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

#include "nimbase.h"
#undef linux
#undef near
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* p, NI op);
typedef N_NIMCALL_PTR(void*, TY_WSm2xU5ARYv9aAR4l0z9c9auQ) (void* p);
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* p);
N_LIB_EXPORT N_CDECL(NimStringDesc*, nimrtl_setLengthStr)(NimStringDesc* s, NI newLen);
N_NIMCALL(void, handleShortOption_7aIl9cJUX5tPqtQBG33k9aMg)(OptParser_fe5bDDfRbVwQIuUOouExnA* p);
N_NIMCALL(NimStringDesc*, addChar)(NimStringDesc* s, NIM_CHAR c);
N_NIMCALL(NI, parseWord_JAw9bP8tjPXKSullchoBwUA)(NimStringDesc* s, NI i, NimStringDesc** w, TY_nmiMWKVIe46vacnhAFrQvw_Set delim);
N_LIB_EXPORT N_CDECL(NimStringDesc*, npocmdLineRest)(OptParser_fe5bDDfRbVwQIuUOouExnA* p);
N_LIB_EXPORT N_CDECL(NimStringDesc*, nsuStrip)(NimStringDesc* s, NIM_BOOL leading, NIM_BOOL trailing, TY_nmiMWKVIe46vacnhAFrQvw_Set chars);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI start, NI last);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI first, NI last);
static NIM_CONST TY_nmiMWKVIe46vacnhAFrQvw_Set TM_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 TM_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 TM_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* s, NI i, NimStringDesc** w, TY_nmiMWKVIe46vacnhAFrQvw_Set delim) {
	NI result;
	result = (NI)0;
	result = i;
	{
		if (!((NU8)(s->data[result]) == (NU8)(34))) goto LA3_;
		result += ((NI) 1);
		{
			while (1) {
				if (!!((((NU8)(s->data[result])) == ((NU8)(0)) || ((NU8)(s->data[result])) == ((NU8)(34))))) goto LA6;
				(*w) = addChar((*w), s->data[result]);
				result += ((NI) 1);
			} LA6: ;
		}
		{
			if (!((NU8)(s->data[result]) == (NU8)(34))) goto LA9_;
			result += ((NI) 1);
		}
		LA9_: ;
	}
	goto LA1_;
	LA3_: ;
	{
		{
			while (1) {
				if (!!(((delim[(NU)(((NU8)(s->data[result])))>>3] &(1U<<((NU)(((NU8)(s->data[result])))&7U)))!=0))) goto LA13;
				(*w) = addChar((*w), s->data[result]);
				result += ((NI) 1);
			} LA13: ;
		}
	}
	LA1_: ;
	return result;
}

N_NIMCALL(void, handleShortOption_7aIl9cJUX5tPqtQBG33k9aMg)(OptParser_fe5bDDfRbVwQIuUOouExnA* p) {
	NI i;
	i = (*p).pos;
	(*p).kind = ((CmdLineKind_XkdXq9atxjiuhkFFh0XYrSA) 3);
	(*p).key = addChar((*p).key, (*p).cmd->data[i]);
	i += ((NI) 1);
	(*p).inShortState = NIM_TRUE;
	{
		while (1) {
			if (!(((NU8)((*p).cmd->data[i])) == ((NU8)(9)) || ((NU8)((*p).cmd->data[i])) == ((NU8)(32)))) goto LA2;
			i += ((NI) 1);
			(*p).inShortState = NIM_FALSE;
		} LA2: ;
	}
	{
		if (!(((NU8)((*p).cmd->data[i])) == ((NU8)(58)) || ((NU8)((*p).cmd->data[i])) == ((NU8)(61)))) goto LA5_;
		i += ((NI) 1);
		(*p).inShortState = NIM_FALSE;
		{
			while (1) {
				if (!(((NU8)((*p).cmd->data[i])) == ((NU8)(9)) || ((NU8)((*p).cmd->data[i])) == ((NU8)(32)))) goto LA8;
				i += ((NI) 1);
			} LA8: ;
		}
		i = parseWord_JAw9bP8tjPXKSullchoBwUA((*p).cmd, i, (&(*p).val), TM_GYgvYKeHVTEls0AcywABHQ_2);
	}
	LA5_: ;
	{
		if (!((NU8)((*p).cmd->data[i]) == (NU8)(0))) goto LA11_;
		(*p).inShortState = NIM_FALSE;
	}
	LA11_: ;
	(*p).pos = i;
}

N_LIB_EXPORT N_CDECL(void, nponext)(OptParser_fe5bDDfRbVwQIuUOouExnA* p) {
	NI i;
{	i = (*p).pos;
	{
		while (1) {
			if (!(((NU8)((*p).cmd->data[i])) == ((NU8)(9)) || ((NU8)((*p).cmd->data[i])) == ((NU8)(32)))) goto LA2;
			i += ((NI) 1);
		} LA2: ;
	}
	(*p).pos = i;
	(*p).key = nimrtl_setLengthStr((*p).key, ((NI) 0));
	(*p).val = nimrtl_setLengthStr((*p).val, ((NI) 0));
	{
		if (!(*p).inShortState) goto LA5_;
		handleShortOption_7aIl9cJUX5tPqtQBG33k9aMg(p);
		goto BeforeRet_;
	}
	LA5_: ;
	switch (((NU8)((*p).cmd->data[i]))) {
	case 0:
	{
		(*p).kind = ((CmdLineKind_XkdXq9atxjiuhkFFh0XYrSA) 0);
	}
	break;
	case 45:
	{
		i += ((NI) 1);
		{
			if (!((NU8)((*p).cmd->data[i]) == (NU8)(45))) goto LA11_;
			(*p).kind = ((CmdLineKind_XkdXq9atxjiuhkFFh0XYrSA) 2);
			i += ((NI) 1);
			i = parseWord_JAw9bP8tjPXKSullchoBwUA((*p).cmd, i, (&(*p).key), TM_GYgvYKeHVTEls0AcywABHQ_3);
			{
				while (1) {
					if (!(((NU8)((*p).cmd->data[i])) == ((NU8)(9)) || ((NU8)((*p).cmd->data[i])) == ((NU8)(32)))) goto LA14;
					i += ((NI) 1);
				} LA14: ;
			}
			{
				if (!(((NU8)((*p).cmd->data[i])) == ((NU8)(58)) || ((NU8)((*p).cmd->data[i])) == ((NU8)(61)))) goto LA17_;
				i += ((NI) 1);
				{
					while (1) {
						if (!(((NU8)((*p).cmd->data[i])) == ((NU8)(9)) || ((NU8)((*p).cmd->data[i])) == ((NU8)(32)))) goto LA20;
						i += ((NI) 1);
					} LA20: ;
				}
				(*p).pos = parseWord_JAw9bP8tjPXKSullchoBwUA((*p).cmd, i, (&(*p).val), TM_GYgvYKeHVTEls0AcywABHQ_2);
			}
			goto LA15_;
			LA17_: ;
			{
				(*p).pos = i;
			}
			LA15_: ;
		}
		goto LA9_;
		LA11_: ;
		{
			(*p).pos = i;
			handleShortOption_7aIl9cJUX5tPqtQBG33k9aMg(p);
		}
		LA9_: ;
	}
	break;
	default:
	{
		(*p).kind = ((CmdLineKind_XkdXq9atxjiuhkFFh0XYrSA) 1);
		(*p).pos = parseWord_JAw9bP8tjPXKSullchoBwUA((*p).cmd, i, (&(*p).key), TM_GYgvYKeHVTEls0AcywABHQ_2);
	}
	break;
	}
	}BeforeRet_: ;
}

N_LIB_EXPORT N_CDECL(NimStringDesc*, npocmdLineRest)(OptParser_fe5bDDfRbVwQIuUOouExnA* p) {
	NimStringDesc* result;
	NimStringDesc* T1_;
	result = (NimStringDesc*)0;
	T1_ = (NimStringDesc*)0;
	T1_ = copyStrLast((*p).cmd, (*p).pos, (NI)(((*p).cmd ? (*p).cmd->Sup.len : 0) - ((NI) 1)));
	result = nsuStrip(T1_, NIM_TRUE, NIM_TRUE, TM_GYgvYKeHVTEls0AcywABHQ_4);
	return result;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_parseoptInit000)(void) {
}

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

