// File: /workspace/github_c_makefile_star2_O3/ajpaulson[P]srogue11/main.c
// Function: main
int main(int argc,char const* argv[],char **envp)
{
	char *env;
	struct linked_list *item;
	struct object *obj;
	struct passwd *pw;
	struct passwd *getpwuid();
	char alldone, wpt;
	char *getpass(), *xcrypt(), *strrchr();
	int lowtime;
	time_t now;
        char *roguehome();
	char *homedir = roguehome();

#ifdef __DJGPP__
	_fmode = O_BINARY;
#endif

	if (homedir == NULL)
        	homedir = "";

	playuid = getuid();

	if (setuid(playuid) < 0) {
		printf("Cannot change to effective uid: %d\n", playuid);
		exit(1);
	}
	playgid = getgid();

	/* check for print-score option */

	strcpy(scorefile, homedir);

	if (*scorefile)
		strcat(scorefile,"/");
	strcat(scorefile, "srogue.scr");

	if(argc >= 2 && strcmp(argv[1], "-s") == 0)
	{
		showtop(0);
		exit(0);
	}

	if (argc >= 2 && author() && strcmp(argv[1],"-a") == 0)
	{
		wizard = TRUE;
		argv++;
		argc--;
	}

	/* Check to see if he is a wizard */

	if (argc >= 2 && strcmp(argv[1],"-w") == 0)
	{
		if (strcmp(PASSWD, xcrypt(getpass(wizstr),"mT")) == 0)
		{
			wizard = TRUE;
			argv++;
			argc--;
		}
	}
	time(&now);
	lowtime = (int) now;

	/* get home and options from environment */

	if ((env = getenv("HOME")) != NULL)
		strcpy(home, env);
	else if ((pw = getpwuid(playuid)) != NULL)
		strcpy(home, pw->pw_dir);
	else
		home[0] = '\0';

        if (strcmp(home,"/") == 0)
		home[0] = '\0';

        if ((strlen(home) > 0) && (home[strlen(home)-1] != '/'))
		strcat(home, "/");

	strcpy(file_name, home);
	strcat(file_name, "srogue.sav");

	if ((env = getenv("ROGUEOPTS")) != NULL)
		parse_opts(env);

	if (env == NULL || whoami[0] == '\0')
	{
		if((pw = getpwuid(playuid)) == NULL)
		{
			printf("Say, who are you?\n");
			exit(1);
		}
		else
			strucpy(whoami, pw->pw_name, strlen(pw->pw_name));
	}

	if (env == NULL || fruit[0] == '\0')
		strcpy(fruit, "juicy-fruit");

	if (argc == 2)
		if(!restore(argv[1], envp)) /* NOTE: NEVER RETURNS */
			exit(1);

	dnum = (wizard && getenv("SEED") != NULL ?
		atoi(getenv("SEED")) : lowtime + getpid());

	if(wizard)
		printf("Hello %s, welcome to dungeon #%d\n", whoami, dnum);
	else
		printf("Hello %s, One moment while I open the door to the dungeon...\n", whoami);

	fflush(stdout);
	seed = dnum;
	srand48(seed);			/* init rnd number gen */

	signal(SIGINT, byebye);		/* just in case */
	signal(SIGQUIT ,byebye);

	init_everything();

#ifdef __INTERIX
        setenv("TERM","interix");
#endif

	initscr();			/* Start up cursor package */

	if (strcmp(termname(),"dumb") == 0)
	{
		endwin();
		printf("ERROR in terminal parameters.\n");
		printf("Check TERM in environment.\n");
		byebye(1);
	}

	if (LINES < 24 || COLS < 80) {
		endwin();
		printf("ERROR: screen size too small\n");
		byebye(1);
	}

	if ((whoami[0] == '\0') || (*whoami == '\0') || (strcmp(whoami,"dosuser")==0))
	{
		echo();
		mvaddstr(23,2,"Rogue's Name? ");
		wgetnstr(stdscr,whoami,MAXSTR);
		noecho();
	}

	if ((whoami[0] == '\0') || (*whoami == '\0'))
		strcpy(whoami,"Rodney");
	
	setup();

	/* Set up windows */

	cw = newwin(0, 0, 0, 0);
	mw = newwin(0, 0, 0, 0);
	hw = newwin(0, 0, 0, 0);
	waswizard = wizard;

	/* Draw current level */

	new_level(NORMLEV);

	/* Start up daemons and fuses */

	srdaemon(status, TRUE, BEFORE);
	srdaemon(doctor, TRUE, BEFORE);
	srdaemon(stomach, TRUE, BEFORE);
	srdaemon(runners, TRUE, AFTER);
	fuse(swander, TRUE, WANDERTIME);

	/* Give the rogue his weaponry */

	do {
		wpt = pick_one(w_magic);
		switch (wpt)
		{
			case MACE:	case SWORD:	case TWOSWORD:
			case SPEAR:	case TRIDENT:	case SPETUM:
			case BARDICHE:	case PIKE:	case BASWORD:
			case HALBERD:
				alldone = TRUE;
			otherwise:
				alldone = FALSE;
		}
	} while(!alldone);

	item = new_thing(FALSE, WEAPON, wpt);
	obj = OBJPTR(item);
	obj->o_hplus = rnd(3);
	obj->o_dplus = rnd(3);
	obj->o_flags = ISKNOW;
	add_pack(item, TRUE);
	cur_weapon = obj;

	/* Now a bow */

	item = new_thing(FALSE, WEAPON, BOW);
	obj = OBJPTR(item);
	obj->o_hplus = rnd(3);
	obj->o_dplus = rnd(3);
	obj->o_flags = ISKNOW;
	add_pack(item, TRUE);

	/* Now some arrows */

	item = new_thing(FALSE, WEAPON, ARROW);
	obj = OBJPTR(item);
	obj->o_count = 25 + rnd(15);
	obj->o_hplus = rnd(2);
	obj->o_dplus = rnd(2);
	obj->o_flags = ISKNOW;
	add_pack(item, TRUE);

	/* And his suit of armor */

	wpt = pick_one(a_magic);
	item = new_thing(FALSE, ARMOR, wpt);
	obj = OBJPTR(item);
	obj->o_flags = ISKNOW;
	obj->o_ac = armors[wpt].a_class - rnd(4);
	cur_armor = obj;
	add_pack(item, TRUE);
	
	/* Give him some food */

	item = new_thing(FALSE, FOOD, 0);
	add_pack(item, TRUE);

	playit();
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movl %edi, %ebp
callq 0xc863
movq %rax, %r15
callq 0x6190
leaq 0x21fca(%rip), %r13     # 0x2de60
movl %eax, (%r13)
movl %eax, %edi
callq 0x6520
testl %eax, %eax
jns 0xbebc
movl (%r13), %esi
leaq 0x14d02(%rip), %rdi     # 0x20bb2
xorl %eax, %eax
callq 0x61c0
jmp 0xc170
testq %r15, %r15
leaq 0x17ac3(%rip), %r12     # 0x23989
cmovneq %r15, %r12
callq 0x6300
leaq 0x21f8e(%rip), %rcx     # 0x2de64
movl %eax, (%rcx)
leaq 0x22141(%rip), %r15     # 0x2e020
movq %r15, %rdi
movq %r12, %rsi
callq 0x60e0
cmpb $0x0, (%r15)
je 0xbeff
movq %r15, %rdi
callq 0x6170
movw $0x2f, (%r15,%rax)
movq %r15, %rdi
callq 0x6170
movabsq $0x732e6575676f7273, %r12 # imm = 0x732E6575676F7273
movq %r12, (%r15,%rax)
movl $0x726373, 0x7(%r15,%rax) # imm = 0x726373
cmpl $0x2, %ebp
jl 0xbfe7
movq 0x8(%r14), %rax
movb (%rax), %cl
cmpb $0x2d, %cl
jne 0xbf4c
cmpb $0x73, 0x1(%rax)
jne 0xbf4c
cmpb $0x0, 0x2(%rax)
jne 0xbf4c
xorl %edi, %edi
callq 0x13574
xorl %edi, %edi
callq 0x6500
movl (%r13), %edx
cmpl $0x64, %edx
je 0xbf59
testl %edx, %edx
jne 0xbf8c
cmpb $0x2d, %cl
jne 0xbfe7
cmpb $0x61, 0x1(%rax)
jne 0xbf91
cmpb $0x0, 0x2(%rax)
jne 0xbf91
leaq 0x8(%r14), %rdx
leaq 0x21924(%rip), %rax     # 0x2d89d
movb $0x1, (%rax)
decl %ebp
cmpl $0x2, %ebp
jb 0xbfdf
movq 0x10(%r14), %rax
movb (%rax), %cl
movq %rdx, %r14
cmpb $0x2d, %cl
jne 0xbfe7
cmpb $0x77, 0x1(%rax)
jne 0xbfe7
cmpb $0x0, 0x2(%rax)
jne 0xbfe7
leaq 0x1e3bc(%rip), %rdi     # 0x2a360
callq 0x6440
leaq 0x14c3f(%rip), %rsi     # 0x20bef
movq %rax, %rdi
xorl %eax, %eax
callq 0x1d7ac
leaq 0x14c20(%rip), %rdi     # 0x20be1
movq %rax, %rsi
callq 0x6250
testl %eax, %eax
jne 0xbfe7
addq $0x8, %r14
leaq 0x218c5(%rip), %rax     # 0x2d89d
movb $0x1, (%rax)
decl %ebp
jmp 0xbfe7
movq %rdx, %r14
movl $0x1, %ebp
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x62e0
movl (%r15), %eax
movl %eax, 0xc(%rsp)
leaq 0x14cd8(%rip), %rdi     # 0x20cda
callq 0x6040
testq %rax, %rax
jne 0xc01e
movl (%r13), %edi
callq 0x6150
testq %rax, %rax
je 0xc03d
movq 0x20(%rax), %rax
leaq 0x2204b(%rip), %r15     # 0x2e070
movq %r15, %rdi
movq %rax, %rsi
callq 0x60e0
cmpb $0x2f, (%r15)
jne 0xc047
cmpb $0x0, 0x1(%r15)
jne 0xc047
leaq 0x2202c(%rip), %rax     # 0x2e070
movb $0x0, (%rax)
leaq 0x22022(%rip), %r15     # 0x2e070
movq %r15, %rdi
callq 0x6170
testq %rax, %rax
je 0xc072
cmpb $0x2f, -0x1(%rax,%r15)
je 0xc072
movq %r15, %rdi
callq 0x6170
movw $0x2f, (%r15,%rax)
leaq 0x21f57(%rip), %r15     # 0x2dfd0
leaq 0x21ff0(%rip), %rsi     # 0x2e070
movq %r15, %rdi
callq 0x60e0
movq %r15, %rdi
callq 0x6170
movq %r12, (%r15,%rax)
movl $0x766173, 0x7(%r15,%rax) # imm = 0x766173
leaq 0x14b59(%rip), %rdi     # 0x20bfd
callq 0x6040
movq %rax, %r15
testq %rax, %rax
je 0xc0c5
movq %r15, %rdi
callq 0x1003f
leaq 0x21e20(%rip), %rax     # 0x2dee0
cmpb $0x0, (%rax)
jne 0xc105
movl (%r13), %edi
callq 0x6150
testq %rax, %rax
jne 0xc0e4
leaq 0x14cb1(%rip), %rdi     # 0x20d8b
callq 0x60f0
jmp 0xc170
movq (%rax), %r12
movq %r12, %rdi
callq 0x6170
leaq 0x21dea(%rip), %rdi     # 0x2dee0
movq %r12, %rsi
movl %eax, %edx
callq 0xfff0
testq %r15, %r15
je 0xc111
leaq 0x21e24(%rip), %rax     # 0x2df30
cmpb $0x0, (%rax)
jne 0xc12c
leaq 0x21e18(%rip), %rax     # 0x2df30
movabsq $0x72662d796369756a, %rcx # imm = 0x72662D796369756A
movq %rcx, (%rax)
movl $0x746975, 0x8(%rax)    # imm = 0x746975
cmpl $0x2, %ebp
jne 0xc141
movq 0x8(%r14), %rdi
movq %rbx, %rsi
callq 0x1436a
testb %al, %al
je 0xc170
leaq 0x21755(%rip), %r14     # 0x2d89d
movb (%r14), %bpl
cmpb $0x1, %bpl
jne 0xc162
leaq 0x14abb(%rip), %rdi     # 0x20c13
callq 0x6040
testq %rax, %rax
jne 0xc17a
callq 0x6130
addl 0xc(%rsp), %eax
movb (%r14), %bpl
jmp 0xc182
movl $0x1, %edi
callq 0x6500
movq %rax, %rdi
callq 0x64b0
leaq 0x21ce7(%rip), %rbx     # 0x2de70
movl %eax, (%rbx)
testb $0x1, %bpl
je 0xc1aa
leaq 0x14a80(%rip), %rdi     # 0x20c18
leaq 0x21d41(%rip), %rsi     # 0x2dee0
movl %eax, %edx
xorl %eax, %eax
callq 0x61c0
jmp 0xc1bf
leaq 0x14a89(%rip), %rdi     # 0x20c3a
leaq 0x21d28(%rip), %rsi     # 0x2dee0
xorl %eax, %eax
callq 0x61c0
movq 0x1dd3a(%rip), %rax     # 0x29f00
movq (%rax), %rdi
callq 0x6350
movslq (%rbx), %rdi
leaq 0x21c94(%rip), %rax     # 0x2de6c
movl %edi, (%rax)
callq 0x63c0
leaq 0x476(%rip), %rbx       # 0xc65c
movl $0x2, %edi
movq %rbx, %rsi
callq 0x6280
movl $0x3, %edi
movq %rbx, %rsi
callq 0x6280
xorl %eax, %eax
callq 0xb5ff
callq 0x61f0
callq 0x63b0
leaq 0x14a60(%rip), %rsi     # 0x20c78
movq %rax, %rdi
callq 0x6250
testl %eax, %eax
jne 0xc241
callq 0x6530
leaq 0x14b05(%rip), %rdi     # 0x20d35
callq 0x60f0
leaq 0x14b17(%rip), %rdi     # 0x20d53
jmp 0xc5f0
movq 0x1dd68(%rip), %rax     # 0x29fb0
cmpl $0x18, (%rax)
jl 0xc5e4
movq 0x1dd40(%rip), %rax     # 0x29f98
cmpl $0x4f, (%rax)
jle 0xc5e4
leaq 0x21c78(%rip), %rbx     # 0x2dee0
cmpb $0x0, (%rbx)
je 0xc284
leaq 0x21c6c(%rip), %rdi     # 0x2dee0
leaq 0x14a02(%rip), %rsi     # 0x20c7d
callq 0x6250
testl %eax, %eax
jne 0xc2e2
callq 0x6390
movq 0x1dca0(%rip), %r15     # 0x29f30
movq (%r15), %rdi
movl $0x17, %esi
movl $0x2, %edx
callq 0x6490
cmpl $-0x1, %eax
je 0xc2bb
movq (%r15), %rdi
leaq 0x149d4(%rip), %rsi     # 0x20c85
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6550
movq (%r15), %rdi
movq %rbx, %rsi
movl $0x18, %edx
callq 0x63e0
callq 0x6180
cmpb $0x0, (%rbx)
jne 0xc2e2
movl $0x79656e, 0x3(%rbx)    # imm = 0x79656E
movl $0x6e646f52, (%rbx)     # imm = 0x6E646F52
callq 0xc6e6
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x60d0
leaq 0x246e5(%rip), %rcx     # 0x309e0
movq %rax, (%rcx)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x60d0
leaq 0x246de(%rip), %rcx     # 0x309f0
movq %rax, (%rcx)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x60d0
leaq 0x246bf(%rip), %rcx     # 0x309e8
movq %rax, (%rcx)
movb (%r14), %al
leaq 0x2156a(%rip), %rcx     # 0x2d8a0
movb %al, (%rcx)
xorl %edi, %edi
callq 0xf534
leaq -0x9d9(%rip), %rdi      # 0xb96d
movl $0x1, %esi
movl $0x1, %edx
callq 0x8b11
leaq -0x3670(%rip), %rdi     # 0x8cec
movl $0x1, %esi
movl $0x1, %edx
callq 0x8b11
leaq -0x3469(%rip), %rdi     # 0x8f09
movl $0x1, %esi
movl $0x1, %edx
callq 0x8b11
leaq -0x5aa4(%rip), %rdi     # 0x68e4
movl $0x1, %esi
movl $0x2, %edx
callq 0x8b11
leaq -0x35ba(%rip), %rdi     # 0x8de4
movl $0x1, %esi
movl $0x46, %edx
callq 0x8ba7
leaq 0x1fbdc(%rip), %rbx     # 0x2bf90
movl $0x3f843, %ebp          # imm = 0x3F843
movq %rbx, %rdi
callq 0x1b9ad
movsbl %al, %edx
cmpl $0x11, %edx
ja 0xc3b9
btl %edx, %ebp
jae 0xc3b9
xorl %edi, %edi
movl $0x29, %esi
callq 0x1b640
movq %rax, %rbx
movq 0x10(%rax), %r12
callq 0x6380
movq %rax, %rcx
movabsq $0x5555555555555556, %r14 # imm = 0x5555555555555556
imulq %r14
movq %rdx, %rax
shrq $0x3f, %rax
addl %edx, %eax
leal (%rax,%rax,2), %eax
subl %eax, %ecx
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
andl %ebp, %ecx
movl %ecx, 0x2c(%r12)
callq 0x6380
movq %rax, %rcx
imulq %r14
movq %rdx, %rax
shrq $0x3f, %rax
addl %edx, %eax
leal (%rax,%rax,2), %eax
subl %eax, %ecx
andl %ebp, %ecx
movl %ecx, 0x30(%r12)
movl $0x2, %r15d
movl %r15d, 0x38(%r12)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x10180
leaq 0x21401(%rip), %rax     # 0x2d850
movq %r12, (%rax)
xorl %edi, %edi
movl $0x29, %esi
movl $0x2, %edx
callq 0x1b640
movq %rax, %rbx
movq 0x10(%rax), %r12
callq 0x6380
movq %rax, %rcx
imulq %r14
movq %rdx, %rax
shrq $0x3f, %rax
addl %edx, %eax
leal (%rax,%rax,2), %eax
subl %eax, %ecx
andl %ebp, %ecx
movl %ecx, 0x2c(%r12)
callq 0x6380
movq %rax, %rcx
imulq %r14
movq %rdx, %rax
shrq $0x3f, %rax
addl %edx, %eax
leal (%rax,%rax,2), %eax
subl %eax, %ecx
andl %ebp, %ecx
movl %ecx, 0x30(%r12)
movl %r15d, 0x38(%r12)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x10180
xorl %edi, %edi
movl $0x29, %esi
movl $0x3, %edx
callq 0x1b640
movq %rax, %rbx
movq 0x10(%rax), %r14
callq 0x6380
movq %rax, %rcx
movabsq $-0x7777777777777777, %rdx # imm = 0x8888888888888889
imulq %rdx
addq %rcx, %rdx
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x3, %rdx
addl %eax, %edx
leal (%rdx,%rdx,4), %eax
leal (%rax,%rax,2), %eax
subl %eax, %ecx
andl %ebp, %ecx
addl $0x19, %ecx
movl %ecx, 0x24(%r14)
callq 0x6380
movq %rax, %rcx
shrq $0x3f, %rcx
addl %eax, %ecx
movl $0x7ffffffe, %r12d      # imm = 0x7FFFFFFE
andl %r12d, %ecx
subl %ecx, %eax
andl %ebp, %eax
movl %eax, 0x2c(%r14)
callq 0x6380
movq %rax, %rcx
shrq $0x3f, %rcx
addl %eax, %ecx
andl %r12d, %ecx
subl %ecx, %eax
andl %ebp, %eax
movl %eax, 0x30(%r14)
movl %r15d, 0x38(%r14)
movq %rbx, %rdi
movl $0x1, %esi
callq 0x10180
leaq 0x1f906(%rip), %rdi     # 0x2be60
callq 0x1b9ad
movl %eax, %ebx
movsbl %bl, %edx
xorl %edi, %edi
movl $0x5d, %esi
callq 0x1b640
movq %rax, %r14
movq 0x10(%rax), %r12
movl %r15d, 0x38(%r12)
movsbq %bl, %rax
leaq (%rax,%rax,2), %rax
leaq 0x1f985(%rip), %rcx     # 0x2bf10
movl (%rcx,%rax,4), %ebx
callq 0x6380
leal 0x3(%rax), %ecx
testq %rax, %rax
cmovnsl %eax, %ecx
andl $0x7ffffffc, %ecx       # imm = 0x7FFFFFFC
subl %ecx, %eax
andl %ebp, %eax
subl %eax, %ebx
movl %ebx, 0x34(%r12)
leaq 0x212a4(%rip), %rax     # 0x2d858
movq %r12, (%rax)
movq %r14, %rdi
movl $0x1, %esi
callq 0x10180
xorl %edi, %edi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x1b640
movq %rax, %rdi
movl $0x1, %esi
callq 0x10180
callq 0xc7a0
callq 0x6530
leaq 0x1477e(%rip), %rdi     # 0x20d6e
callq 0x60f0
movl $0x1, %edi
callq 0xc65c