// File: /workspace/github_c_makefile_star2_O2/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 0xc1af
movq %rax, %r15
callq 0x6190
leaq 0x22542(%rip), %r13     # 0x2de50
movl %eax, (%r13)
movl %eax, %edi
callq 0x6500
testl %eax, %eax
jns 0xb934
movl (%r13), %esi
leaq 0x1328a(%rip), %rdi     # 0x1ebb2
xorl %eax, %eax
callq 0x61c0
jmp 0xbbf2
testq %r15, %r15
leaq 0x1604b(%rip), %r12     # 0x21989
cmovneq %r15, %r12
callq 0x62f0
leaq 0x22506(%rip), %rcx     # 0x2de54
movl %eax, (%rcx)
leaq 0x226b9(%rip), %r15     # 0x2e010
movq %r15, %rdi
movq %r12, %rsi
callq 0x60e0
cmpb $0x0, (%r15)
je 0xb977
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 0xba5e
movq 0x8(%r14), %rax
movb (%rax), %cl
cmpb $0x2d, %cl
jne 0xb9c4
cmpb $0x73, 0x1(%rax)
jne 0xb9c4
cmpb $0x0, 0x2(%rax)
jne 0xb9c4
xorl %edi, %edi
callq 0x12887
xorl %edi, %edi
callq 0x64e0
movl (%r13), %edx
cmpl $0x64, %edx
je 0xb9d1
testl %edx, %edx
jne 0xba0a
cmpb $0x2d, %cl
jne 0xba5e
cmpb $0x61, 0x1(%rax)
jne 0xba12
cmpb $0x0, 0x2(%rax)
jne 0xba12
leaq 0x8(%r14), %rdx
leaq 0x21e9c(%rip), %rax     # 0x2d88d
movb $0x1, (%rax)
decl %ebp
cmpl $0x2, %ebp
jb 0xbf89
movq 0x10(%r14), %rax
movb (%rax), %cl
movq %rdx, %r14
jmp 0xba0d
movq %r14, %rdx
cmpb $0x2d, %cl
jne 0xba61
cmpb $0x77, 0x1(%rax)
jne 0xba5e
cmpb $0x0, 0x2(%rax)
jne 0xba5e
leaq 0x1e92b(%rip), %rdi     # 0x2a350
callq 0x6420
leaq 0x131be(%rip), %rsi     # 0x1ebef
movq %rax, %rdi
xorl %eax, %eax
callq 0x1bbb4
leaq 0x1319f(%rip), %rdi     # 0x1ebe1
movq %rax, %rsi
callq 0x6240
testl %eax, %eax
jne 0xba5e
addq $0x8, %r14
leaq 0x21e34(%rip), %rax     # 0x2d88d
movb $0x1, (%rax)
decl %ebp
movq %r14, %rdx
movq %rbx, 0x8(%rsp)
movq %rdx, %rbx
movq %r12, %r15
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x62d0
movl (%r14), %r12d
leaq 0x13257(%rip), %rdi     # 0x1ecda
callq 0x6040
testq %rax, %rax
jne 0xba9f
movl (%r13), %edi
callq 0x6150
testq %rax, %rax
je 0xbabe
movq 0x20(%rax), %rax
leaq 0x225ba(%rip), %r14     # 0x2e060
movq %r14, %rdi
movq %rax, %rsi
callq 0x60e0
cmpb $0x2f, (%r14)
jne 0xbac8
cmpb $0x0, 0x1(%r14)
jne 0xbac8
leaq 0x2259b(%rip), %rax     # 0x2e060
movb $0x0, (%rax)
leaq 0x22591(%rip), %r14     # 0x2e060
movq %r14, %rdi
callq 0x6170
testq %rax, %rax
je 0xbaf3
cmpb $0x2f, -0x1(%rax,%r14)
je 0xbaf3
movq %r14, %rdi
callq 0x6170
movw $0x2f, (%r14,%rax)
leaq 0x224c6(%rip), %r14     # 0x2dfc0
leaq 0x2255f(%rip), %rsi     # 0x2e060
movq %r14, %rdi
callq 0x60e0
movq %r14, %rdi
callq 0x6170
movq %r15, (%r14,%rax)
movl $0x766173, 0x7(%r14,%rax) # imm = 0x766173
leaq 0x130d8(%rip), %rdi     # 0x1ebfd
callq 0x6040
movq %rax, %r14
testq %rax, %rax
je 0xbb46
movq %r14, %rdi
callq 0xf66c
leaq 0x2238f(%rip), %rax     # 0x2ded0
cmpb $0x0, (%rax)
jne 0xbb86
movl (%r13), %edi
callq 0x6150
testq %rax, %rax
jne 0xbb65
leaq 0x13230(%rip), %rdi     # 0x1ed8b
callq 0x60f0
jmp 0xbbf2
movq (%rax), %r15
movq %r15, %rdi
callq 0x6170
leaq 0x22359(%rip), %rdi     # 0x2ded0
movq %r15, %rsi
movl %eax, %edx
callq 0xf61f
testq %r14, %r14
je 0xbb92
leaq 0x22393(%rip), %rax     # 0x2df20
cmpb $0x0, (%rax)
jne 0xbbad
leaq 0x22387(%rip), %rax     # 0x2df20
movabsq $0x72662d796369756a, %rcx # imm = 0x72662D796369756A
movq %rcx, (%rax)
movl $0x746975, 0x8(%rax)    # imm = 0x746975
cmpl $0x2, %ebp
jne 0xbbc4
movq 0x8(%rbx), %rdi
movq 0x8(%rsp), %rsi
callq 0x13543
testb %al, %al
je 0xbbf2
leaq 0x21cc2(%rip), %r14     # 0x2d88d
movb (%r14), %bpl
cmpb $0x1, %bpl
jne 0xbbe5
leaq 0x13038(%rip), %rdi     # 0x1ec13
callq 0x6040
testq %rax, %rax
jne 0xbbfa
callq 0x6130
addl %r12d, %eax
movb (%r14), %bpl
jmp 0xbc02
pushq $0x1
popq %rdi
callq 0x64e0
movq %rax, %rdi
callq 0x6490
leaq 0x22257(%rip), %rbx     # 0x2de60
movl %eax, (%rbx)
testb $0x1, %bpl
je 0xbc2a
leaq 0x13000(%rip), %rdi     # 0x1ec18
leaq 0x222b1(%rip), %rsi     # 0x2ded0
movl %eax, %edx
xorl %eax, %eax
callq 0x61c0
jmp 0xbc3f
leaq 0x13009(%rip), %rdi     # 0x1ec3a
leaq 0x22298(%rip), %rsi     # 0x2ded0
xorl %eax, %eax
callq 0x61c0
movq 0x1e2ba(%rip), %rax     # 0x29f00
movq (%rax), %rdi
callq 0x6340
movslq (%rbx), %rdi
leaq 0x22204(%rip), %rax     # 0x2de5c
movl %edi, (%rax)
callq 0x63b0
leaq 0x386(%rip), %rbx       # 0xbfec
pushq $0x2
popq %rdi
movq %rbx, %rsi
callq 0x6270
pushq $0x3
popq %rdi
movq %rbx, %rsi
callq 0x6270
xorl %eax, %eax
callq 0xb156
callq 0x61f0
callq 0x63a0
leaq 0x12fe4(%rip), %rsi     # 0x1ec78
movq %rax, %rdi
callq 0x6240
testl %eax, %eax
jne 0xbcbd
callq 0x6510
leaq 0x13089(%rip), %rdi     # 0x1ed35
callq 0x60f0
leaq 0x1309b(%rip), %rdi     # 0x1ed53
jmp 0xbf7c
movq 0x1e2fc(%rip), %rax     # 0x29fc0
cmpl $0x18, (%rax)
jl 0xbf70
movq 0x1e2cc(%rip), %rax     # 0x29fa0
cmpl $0x4f, (%rax)
jle 0xbf70
leaq 0x221ec(%rip), %rbx     # 0x2ded0
cmpb $0x0, (%rbx)
je 0xbd00
leaq 0x221e0(%rip), %rdi     # 0x2ded0
leaq 0x12f86(%rip), %rsi     # 0x1ec7d
callq 0x6240
testl %eax, %eax
jne 0xbd56
callq 0x6380
movq 0x1e22c(%rip), %r15     # 0x29f38
movq (%r15), %rdi
pushq $0x17
popq %rsi
pushq $0x2
popq %rdx
callq 0x6470
cmpl $-0x1, %eax
je 0xbd31
movq (%r15), %rdi
leaq 0x12f5c(%rip), %rsi     # 0x1ec85
pushq $-0x1
popq %rdx
callq 0x6530
movq (%r15), %rdi
pushq $0x18
popq %rdx
movq %rbx, %rsi
callq 0x63d0
callq 0x6180
cmpb $0x0, (%rbx)
jne 0xbd56
movl $0x79656e, 0x3(%rbx)    # imm = 0x79656E
movl $0x6e646f52, (%rbx)     # imm = 0x6E646F52
callq 0xc04d
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x60d0
leaq 0x24c61(%rip), %rcx     # 0x309d0
movq %rax, (%rcx)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x60d0
leaq 0x24c5a(%rip), %rcx     # 0x309e0
movq %rax, (%rcx)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x60d0
leaq 0x24c3b(%rip), %rcx     # 0x309d8
movq %rax, (%rcx)
movb (%r14), %al
leaq 0x21ae6(%rip), %rcx     # 0x2d890
movb %al, (%rcx)
xorl %edi, %edi
callq 0xeb48
leaq -0x952(%rip), %rdi      # 0xb468
pushq $0x1
popq %rbp
movl %ebp, %esi
movl %ebp, %edx
callq 0x89b6
leaq -0x324d(%rip), %rdi     # 0x8b80
movl %ebp, %esi
movl %ebp, %edx
callq 0x89b6
leaq -0x305d(%rip), %rdi     # 0x8d80
movl %ebp, %esi
movl %ebp, %edx
callq 0x89b6
leaq -0x5599(%rip), %rdi     # 0x6854
pushq $0x2
popq %rbx
movl %ebp, %esi
movl %ebx, %edx
callq 0x89b6
leaq -0x3193(%rip), %rdi     # 0x8c6d
pushq $0x46
popq %rdx
movl %ebp, %esi
callq 0x8a46
leaq 0x2016f(%rip), %r14     # 0x2bf80
movl $0x3f843, %ebp          # imm = 0x3F843
movq %r14, %rdi
callq 0x19f2a
movsbl %al, %edx
cmpl $0x11, %edx
ja 0xbe16
btl %edx, %ebp
jae 0xbe16
pushq $0x29
popq %r14
xorl %edi, %edi
movl %r14d, %esi
callq 0x19c8f
movq %rax, %r12
movq 0x10(%rax), %r13
pushq $0x3
popq %r15
movl %r15d, %edi
callq 0xc004
movl %eax, 0x2c(%r13)
movl %r15d, %edi
callq 0xc004
movl %eax, 0x30(%r13)
movl %ebx, 0x38(%r13)
pushq $0x1
popq %rbp
movq %r12, %rdi
movl %ebp, %esi
callq 0xf7ac
leaq 0x219cc(%rip), %rax     # 0x2d840
movq %r13, (%rax)
xorl %edi, %edi
movl %r14d, %esi
movl %ebx, %edx
callq 0x19c8f
movq %rax, %r12
movq 0x10(%rax), %r13
movl %r15d, %edi
callq 0xc004
movl %eax, 0x2c(%r13)
movl %r15d, %edi
callq 0xc004
movl %eax, 0x30(%r13)
movl %ebx, 0x38(%r13)
movq %r12, %rdi
movl %ebp, %esi
callq 0xf7ac
xorl %edi, %edi
movl %r14d, %esi
movl %r15d, %edx
callq 0x19c8f
movq %rax, %r14
movq 0x10(%rax), %r15
pushq $0xf
popq %rdi
callq 0xc004
addl $0x19, %eax
movl %eax, 0x24(%r15)
movl %ebx, %edi
callq 0xc004
movl %eax, 0x2c(%r15)
movl %ebx, %edi
callq 0xc004
movl %eax, 0x30(%r15)
movl %ebx, 0x38(%r15)
movq %r14, %rdi
movl %ebp, %esi
callq 0xf7ac
leaq 0x1ff52(%rip), %rdi     # 0x2be50
callq 0x19f2a
movl %eax, %r14d
movsbl %r14b, %edx
pushq $0x5d
popq %rsi
xorl %edi, %edi
callq 0x19c8f
movq %rax, %r15
movq 0x10(%rax), %r12
movl %ebx, 0x38(%r12)
movsbq %r14b, %rax
imulq $0xc, %rax, %rax
leaq 0x1ffd1(%rip), %rcx     # 0x2bf00
movl (%rcx,%rax), %ebx
pushq $0x4
popq %rdi
callq 0xc004
subl %eax, %ebx
movl %ebx, 0x34(%r12)
leaq 0x21900(%rip), %rax     # 0x2d848
movq %r12, (%rax)
movq %r15, %rdi
movl %ebp, %esi
callq 0xf7ac
pushq $0x3a
popq %rsi
xorl %edi, %edi
xorl %edx, %edx
callq 0x19c8f
movq %rax, %rdi
movl %ebp, %esi
callq 0xf7ac
callq 0xc0ef
callq 0x6510
leaq 0x12df2(%rip), %rdi     # 0x1ed6e
callq 0x60f0
pushq $0x1
popq %rdi
callq 0xbfec
pushq $0x1
popq %rbp
jmp 0xba61