/* Generated by Nim Compiler v1.3.5 */
/*   (c) 2020 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 64

/* section: NIM_merge_HEADERS */

#include "nimbase.h"
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix

/* section: NIM_merge_FRAME_DEFINES */
#define nimfr_(x, y)
#define nimln_(x, y)

/* section: NIM_merge_FORWARD_TYPES */
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;

/* section: NIM_merge_TYPES */
typedef NIM_CHAR tyArray__2cWMSJoP9cqN4yIK0ILkQaQ[64];
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};

/* section: NIM_merge_PROC_HEADERS */
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, setLengthStr)(NimStringDesc* s, NI newLen);

/* section: NIM_merge_VARS */
N_LIB_PRIVATE NIM_CONST tyArray__2cWMSJoP9cqN4yIK0ILkQaQ cb64__Yyfw6lxoVbgtswIxGnGnUQ = {65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
79,
80,
81,
82,
83,
84,
85,
86,
87,
88,
89,
90,
97,
98,
99,
100,
101,
102,
103,
104,
105,
106,
107,
108,
109,
110,
111,
112,
113,
114,
115,
116,
117,
118,
119,
120,
121,
122,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
43,
47}
;
N_LIB_PRIVATE NIM_CONST tyArray__2cWMSJoP9cqN4yIK0ILkQaQ cb64safe__q0GCLBVULDDeEKBBmNHUGw = {65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
79,
80,
81,
82,
83,
84,
85,
86,
87,
88,
89,
90,
97,
98,
99,
100,
101,
102,
103,
104,
105,
106,
107,
108,
109,
110,
111,
112,
113,
114,
115,
116,
117,
118,
119,
120,
121,
122,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
45,
95}
;

/* section: NIM_merge_PROCS */
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, encode__D4bDwZBUb9bAJslbVxAPmbg)(NimStringDesc* s, NIM_BOOL safe) {
	NimStringDesc* result;
	result = (NimStringDesc*)0;
	{
		NIM_CHAR* lookupTable;
		NI inputIndexX60gensym45_;
		NI outputIndexX60gensym45_;
		NI inputEndsX60gensym45_;
		NU32 nX60gensym45_;
		NU32 bX60gensym45_;
		NI paddingX60gensym45_;
		{
			if (!safe) goto LA4_;
			lookupTable = cb64safe__q0GCLBVULDDeEKBBmNHUGw;
		}
		goto LA2_;
		LA4_: ;
		{
			lookupTable = cb64__Yyfw6lxoVbgtswIxGnGnUQ;
		}
		LA2_: ;
		result = setLengthStr(result, ((NI) ((NI)((NI)((NI)((s ? s->Sup.len : 0) * ((NI) 4)) / ((NI) 3)) + ((NI) 6)))));
		inputIndexX60gensym45_ = ((NI) 0);
		outputIndexX60gensym45_ = ((NI) 0);
		inputEndsX60gensym45_ = (NI)((s ? s->Sup.len : 0) - (NI)((s ? s->Sup.len : 0) % ((NI) 3)));
		nX60gensym45_ = (NU32)0;
		bX60gensym45_ = (NU32)0;
		{
			while (1) {
				if (!!((inputIndexX60gensym45_ == inputEndsX60gensym45_))) goto LA8;
				bX60gensym45_ = ((NU32) (((NU8)(s->data[inputIndexX60gensym45_]))));
				nX60gensym45_ = (NU32)((NU64)(bX60gensym45_) << (NU64)(((NI) 16)));
				inputIndexX60gensym45_ += ((NI) 1);
				bX60gensym45_ = ((NU32) (((NU8)(s->data[inputIndexX60gensym45_]))));
				nX60gensym45_ = (NU32)(nX60gensym45_ | (NU32)((NU64)(bX60gensym45_) << (NU64)(((NI) 8))));
				inputIndexX60gensym45_ += ((NI) 1);
				bX60gensym45_ = ((NU32) (((NU8)(s->data[inputIndexX60gensym45_]))));
				nX60gensym45_ = (NU32)(nX60gensym45_ | (NU32)((NU64)(bX60gensym45_) << (NU64)(((NI) 0))));
				inputIndexX60gensym45_ += ((NI) 1);
				result->data[outputIndexX60gensym45_] = lookupTable[((NU32)((NU32)((NU32)(nX60gensym45_) >> (NU64)(((NI) 18))) & ((NU32) 63)))- 0];
				outputIndexX60gensym45_ += ((NI) 1);
				result->data[outputIndexX60gensym45_] = lookupTable[((NU32)((NU32)((NU32)(nX60gensym45_) >> (NU64)(((NI) 12))) & ((NU32) 63)))- 0];
				outputIndexX60gensym45_ += ((NI) 1);
				result->data[outputIndexX60gensym45_] = lookupTable[((NU32)((NU32)((NU32)(nX60gensym45_) >> (NU64)(((NI) 6))) & ((NU32) 63)))- 0];
				outputIndexX60gensym45_ += ((NI) 1);
				result->data[outputIndexX60gensym45_] = lookupTable[((NU32)((NU32)((NU32)(nX60gensym45_) >> (NU64)(((NI) 0))) & ((NU32) 63)))- 0];
				outputIndexX60gensym45_ += ((NI) 1);
			} LA8: ;
		}
		paddingX60gensym45_ = (NI)((s ? s->Sup.len : 0) % ((NI) 3));
		{
			if (!(paddingX60gensym45_ == ((NI) 1))) goto LA11_;
			bX60gensym45_ = ((NU32) (((NU8)(s->data[inputIndexX60gensym45_]))));
			nX60gensym45_ = (NU32)((NU64)(bX60gensym45_) << (NU64)(((NI) 16)));
			inputIndexX60gensym45_ += ((NI) 1);
			result->data[outputIndexX60gensym45_] = lookupTable[((NU32)((NU32)((NU32)(nX60gensym45_) >> (NU64)(((NI) 18))) & ((NU32) 63)))- 0];
			outputIndexX60gensym45_ += ((NI) 1);
			result->data[outputIndexX60gensym45_] = lookupTable[((NU32)((NU32)((NU32)(nX60gensym45_) >> (NU64)(((NI) 12))) & ((NU32) 63)))- 0];
			outputIndexX60gensym45_ += ((NI) 1);
			result->data[outputIndexX60gensym45_] = 61;
			outputIndexX60gensym45_ += ((NI) 1);
			result->data[outputIndexX60gensym45_] = 61;
			outputIndexX60gensym45_ += ((NI) 1);
		}
		goto LA9_;
		LA11_: ;
		{
			if (!(paddingX60gensym45_ == ((NI) 2))) goto LA14_;
			bX60gensym45_ = ((NU32) (((NU8)(s->data[inputIndexX60gensym45_]))));
			nX60gensym45_ = (NU32)((NU64)(bX60gensym45_) << (NU64)(((NI) 16)));
			inputIndexX60gensym45_ += ((NI) 1);
			bX60gensym45_ = ((NU32) (((NU8)(s->data[inputIndexX60gensym45_]))));
			nX60gensym45_ = (NU32)(nX60gensym45_ | (NU32)((NU64)(bX60gensym45_) << (NU64)(((NI) 8))));
			inputIndexX60gensym45_ += ((NI) 1);
			result->data[outputIndexX60gensym45_] = lookupTable[((NU32)((NU32)((NU32)(nX60gensym45_) >> (NU64)(((NI) 18))) & ((NU32) 63)))- 0];
			outputIndexX60gensym45_ += ((NI) 1);
			result->data[outputIndexX60gensym45_] = lookupTable[((NU32)((NU32)((NU32)(nX60gensym45_) >> (NU64)(((NI) 12))) & ((NU32) 63)))- 0];
			outputIndexX60gensym45_ += ((NI) 1);
			result->data[outputIndexX60gensym45_] = lookupTable[((NU32)((NU32)((NU32)(nX60gensym45_) >> (NU64)(((NI) 6))) & ((NU32) 63)))- 0];
			outputIndexX60gensym45_ += ((NI) 1);
			result->data[outputIndexX60gensym45_] = 61;
			outputIndexX60gensym45_ += ((NI) 1);
		}
		goto LA9_;
		LA14_: ;
		LA9_: ;
		result = setLengthStr(result, ((NI) (outputIndexX60gensym45_)));
	}
	return result;
}
