/* Generated by Nim Compiler v0.16.0 */
/*   (c) 2017 Andreas Rumpf */
/* The generated code is subject to the original license. */
/* Compiled for: Linux, amd64, gcc */
/* Command for C compiler:
   gcc -c  -w -O3 -fno-strict-aliasing -fPIC  -I/build/nim/src/Nim-0.16.0/lib -o lib/nimcache/stdlib_parseopt.o lib/nimcache/stdlib_parseopt.c */
#define NIM_INTBITS 64

#include "nimbase.h"
#undef linux
typedef struct Optparser_fe5bDDfRbVwQIuUOouExnA Optparser_fe5bDDfRbVwQIuUOouExnA;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef NU8 Tnimkind_jIBKr1ejBgsfM33Kxw4j7A;
typedef NU8 Tnimtypeflag_v8QUszD1sWlSIWZz7mC4bQ_Set;
typedef N_NIMCALL_PTR(void, TY_ojoeKfW4VYIm36I9cpDTQIg) (void* p0, NI op0);
typedef N_NIMCALL_PTR(void*, TY_WSm2xU5ARYv9aAR4l0z9c9auQ) (void* p0);
struct  TNimType  {
NI size;
Tnimkind_jIBKr1ejBgsfM33Kxw4j7A kind;
Tnimtypeflag_v8QUszD1sWlSIWZz7mC4bQ_Set flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY_ojoeKfW4VYIm36I9cpDTQIg marker;
TY_WSm2xU5ARYv9aAR4l0z9c9auQ deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef NU8 Cmdlinekind_XkdXq9atxjiuhkFFh0XYrSA;
struct  Optparser_fe5bDDfRbVwQIuUOouExnA  {
  TNimObject Sup;
NimStringDesc* cmd;
NI pos;
NIM_BOOL inshortstate;
Cmdlinekind_XkdXq9atxjiuhkFFh0XYrSA kind;
NimStringDesc* key;
NimStringDesc* val;
};
typedef NU8 TY_nmiMWKVIe46vacnhAFrQvw_Set[32];
typedef NU8 Tnimnodekind_unfNsxrcATrufDZmpBq4HQ;
struct  TNimNode  {
Tnimnodekind_unfNsxrcATrufDZmpBq4HQ kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
N_LIB_EXPORT N_CDECL(void, nponext)(Optparser_fe5bDDfRbVwQIuUOouExnA* p0);
N_LIB_EXPORT N_CDECL(NimStringDesc*, nimrtl_setLengthStr)(NimStringDesc* s0, NI newlen0);
N_NIMCALL(void, handleshortoption_7aIl9cJUX5tPqtQBG33k9aMg)(Optparser_fe5bDDfRbVwQIuUOouExnA* p0);
N_NIMCALL(NimStringDesc*, addChar)(NimStringDesc* s0, NIM_CHAR c0);
N_NIMCALL(NI, parseword_JAw9bP8tjPXKSullchoBwUA)(NimStringDesc* s0, NI i0, NimStringDesc** w0, TY_nmiMWKVIe46vacnhAFrQvw_Set delim0);
N_LIB_EXPORT N_CDECL(NimStringDesc*, npocmdLineRest)(Optparser_fe5bDDfRbVwQIuUOouExnA* p0);
N_LIB_EXPORT N_CDECL(NimStringDesc*, nsuStrip)(NimStringDesc* s0, NIM_BOOL leading0, NIM_BOOL trailing0, TY_nmiMWKVIe46vacnhAFrQvw_Set chars0);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s0, NI start_WPWyPKk58Cr5a6XFFviMjg, NI last0);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s0, NI first0, NI last0);
static NIM_CONST TY_nmiMWKVIe46vacnhAFrQvw_Set T_GYgvYKeHVTEls0AcywABHQ_2 = {
0x01, 0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
;
static NIM_CONST TY_nmiMWKVIe46vacnhAFrQvw_Set T_GYgvYKeHVTEls0AcywABHQ_3 = {
0x01, 0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x24,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
;
static NIM_CONST TY_nmiMWKVIe46vacnhAFrQvw_Set T_GYgvYKeHVTEls0AcywABHQ_4 = {
0x00, 0x3E, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
;

N_NIMCALL(NI, parseword_JAw9bP8tjPXKSullchoBwUA)(NimStringDesc* s0, NI i0, NimStringDesc** w0, TY_nmiMWKVIe46vacnhAFrQvw_Set delim0) {
	NI result0;
	result0 = (NI)0;
	result0 = i0;
	{
		if (!((NU8)(s0->data[result0]) == (NU8)(34))) goto LA3;
		result0 += ((NI) 1);
		{
			while (1) {
				if (!!((((NU8)(s0->data[result0])) == ((NU8)(0)) || ((NU8)(s0->data[result0])) == ((NU8)(34))))) goto LA6;
				(*w0) = addChar((*w0), s0->data[result0]);
				result0 += ((NI) 1);
			} LA6: ;
		}
		{
			if (!((NU8)(s0->data[result0]) == (NU8)(34))) goto LA9;
			result0 += ((NI) 1);
		}
		LA9: ;
	}
	goto LA1;
	LA3: ;
	{
		{
			while (1) {
				if (!!(((delim0[(NU)(((NU8)(s0->data[result0])))>>3] &(1U<<((NU)(((NU8)(s0->data[result0])))&7U)))!=0))) goto LA13;
				(*w0) = addChar((*w0), s0->data[result0]);
				result0 += ((NI) 1);
			} LA13: ;
		}
	}
	LA1: ;
	return result0;
}

N_NIMCALL(void, handleshortoption_7aIl9cJUX5tPqtQBG33k9aMg)(Optparser_fe5bDDfRbVwQIuUOouExnA* p0) {
	NI i0;
	i0 = (*p0).pos;
	(*p0).kind = ((Cmdlinekind_XkdXq9atxjiuhkFFh0XYrSA) 3);
	(*p0).key = addChar((*p0).key, (*p0).cmd->data[i0]);
	i0 += ((NI) 1);
	(*p0).inshortstate = NIM_TRUE;
	{
		while (1) {
			if (!(((NU8)((*p0).cmd->data[i0])) == ((NU8)(9)) || ((NU8)((*p0).cmd->data[i0])) == ((NU8)(32)))) goto LA2;
			i0 += ((NI) 1);
			(*p0).inshortstate = NIM_FALSE;
		} LA2: ;
	}
	{
		if (!(((NU8)((*p0).cmd->data[i0])) == ((NU8)(58)) || ((NU8)((*p0).cmd->data[i0])) == ((NU8)(61)))) goto LA5;
		i0 += ((NI) 1);
		(*p0).inshortstate = NIM_FALSE;
		{
			while (1) {
				if (!(((NU8)((*p0).cmd->data[i0])) == ((NU8)(9)) || ((NU8)((*p0).cmd->data[i0])) == ((NU8)(32)))) goto LA8;
				i0 += ((NI) 1);
			} LA8: ;
		}
		i0 = parseword_JAw9bP8tjPXKSullchoBwUA((*p0).cmd, i0, (&(*p0).val), T_GYgvYKeHVTEls0AcywABHQ_2);
	}
	LA5: ;
	{
		if (!((NU8)((*p0).cmd->data[i0]) == (NU8)(0))) goto LA11;
		(*p0).inshortstate = NIM_FALSE;
	}
	LA11: ;
	(*p0).pos = i0;
}

N_LIB_EXPORT N_CDECL(void, nponext)(Optparser_fe5bDDfRbVwQIuUOouExnA* p0) {
	NI i0;
{	i0 = (*p0).pos;
	{
		while (1) {
			if (!(((NU8)((*p0).cmd->data[i0])) == ((NU8)(9)) || ((NU8)((*p0).cmd->data[i0])) == ((NU8)(32)))) goto LA2;
			i0 += ((NI) 1);
		} LA2: ;
	}
	(*p0).pos = i0;
	(*p0).key = nimrtl_setLengthStr((*p0).key, ((NI) 0));
	(*p0).val = nimrtl_setLengthStr((*p0).val, ((NI) 0));
	{
		if (!(*p0).inshortstate) goto LA5;
		handleshortoption_7aIl9cJUX5tPqtQBG33k9aMg(p0);
		goto BeforeRet;
	}
	LA5: ;
	switch (((NU8)((*p0).cmd->data[i0]))) {
	case 0:
	{
		(*p0).kind = ((Cmdlinekind_XkdXq9atxjiuhkFFh0XYrSA) 0);
	}
	break;
	case 45:
	{
		i0 += ((NI) 1);
		{
			if (!((NU8)((*p0).cmd->data[i0]) == (NU8)(45))) goto LA11;
			(*p0).kind = ((Cmdlinekind_XkdXq9atxjiuhkFFh0XYrSA) 2);
			i0 += ((NI) 1);
			i0 = parseword_JAw9bP8tjPXKSullchoBwUA((*p0).cmd, i0, (&(*p0).key), T_GYgvYKeHVTEls0AcywABHQ_3);
			{
				while (1) {
					if (!(((NU8)((*p0).cmd->data[i0])) == ((NU8)(9)) || ((NU8)((*p0).cmd->data[i0])) == ((NU8)(32)))) goto LA14;
					i0 += ((NI) 1);
				} LA14: ;
			}
			{
				if (!(((NU8)((*p0).cmd->data[i0])) == ((NU8)(58)) || ((NU8)((*p0).cmd->data[i0])) == ((NU8)(61)))) goto LA17;
				i0 += ((NI) 1);
				{
					while (1) {
						if (!(((NU8)((*p0).cmd->data[i0])) == ((NU8)(9)) || ((NU8)((*p0).cmd->data[i0])) == ((NU8)(32)))) goto LA20;
						i0 += ((NI) 1);
					} LA20: ;
				}
				(*p0).pos = parseword_JAw9bP8tjPXKSullchoBwUA((*p0).cmd, i0, (&(*p0).val), T_GYgvYKeHVTEls0AcywABHQ_2);
			}
			goto LA15;
			LA17: ;
			{
				(*p0).pos = i0;
			}
			LA15: ;
		}
		goto LA9;
		LA11: ;
		{
			(*p0).pos = i0;
			handleshortoption_7aIl9cJUX5tPqtQBG33k9aMg(p0);
		}
		LA9: ;
	}
	break;
	default:
	{
		(*p0).kind = ((Cmdlinekind_XkdXq9atxjiuhkFFh0XYrSA) 1);
		(*p0).pos = parseword_JAw9bP8tjPXKSullchoBwUA((*p0).cmd, i0, (&(*p0).key), T_GYgvYKeHVTEls0AcywABHQ_2);
	}
	break;
	}
	}BeforeRet: ;
}

N_LIB_EXPORT N_CDECL(NimStringDesc*, npocmdLineRest)(Optparser_fe5bDDfRbVwQIuUOouExnA* p0) {
	NimStringDesc* result0;
	NimStringDesc* LOC1;
	result0 = (NimStringDesc*)0;
	LOC1 = (NimStringDesc*)0;
	LOC1 = copyStrLast((*p0).cmd, (*p0).pos, (NI)(((*p0).cmd ? (*p0).cmd->Sup.len : 0) - ((NI) 1)));
	result0 = nsuStrip(LOC1, NIM_TRUE, NIM_TRUE, T_GYgvYKeHVTEls0AcywABHQ_4);
	return result0;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_parseoptInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, stdlib_parseoptDatInit000)(void) {
}

