// File: /workspace/github_c_makefile_star2_O1/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 0xc91c
movq %rax, %r15
callq 0x6190
leaq 0x21f12(%rip), %r13     # 0x2de60
movl %eax, (%r13)
movl %eax, %edi
callq 0x6520
testl %eax, %eax
jns 0xbf74
movl (%r13), %esi
leaq 0x14c2e(%rip), %rdi     # 0x20b96
xorl %eax, %eax
callq 0x61c0
jmp 0xc225
testq %r15, %r15
leaq 0x17993(%rip), %r12     # 0x23911
cmovneq %r15, %r12
callq 0x6300
leaq 0x21ed6(%rip), %rcx     # 0x2de64
movl %eax, (%rcx)
leaq 0x22089(%rip), %r15     # 0x2e020
movq %r15, %rdi
movq %r12, %rsi
callq 0x60e0
cmpb $0x0, (%r15)
je 0xbfb7
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 0xc030
movq 0x8(%r14), %r15
leaq 0x14be1(%rip), %rsi     # 0x20bc7
movq %r15, %rdi
callq 0x6250
testl %eax, %eax
jne 0xc000
xorl %edi, %edi
callq 0x136ea
xorl %edi, %edi
callq 0x6500
movl (%r13), %eax
cmpl $0x64, %eax
je 0xc00d
testl %eax, %eax
jne 0xc030
leaq 0x14bb6(%rip), %rsi     # 0x20bca
movq %r15, %rdi
callq 0x6250
testl %eax, %eax
jne 0xc030
addq $0x8, %r14
leaq 0x21872(%rip), %rax     # 0x2d89d
movb $0x1, (%rax)
decl %ebp
cmpl $0x2, %ebp
jl 0xc089
movq 0x8(%r14), %rdi
leaq 0x14b8d(%rip), %rsi     # 0x20bcd
callq 0x6250
testl %eax, %eax
jne 0xc089
leaq 0x1e310(%rip), %rdi     # 0x2a360
callq 0x6440
leaq 0x14b82(%rip), %rsi     # 0x20bde
movq %rax, %rdi
xorl %eax, %eax
callq 0x1d898
leaq 0x14b63(%rip), %rdi     # 0x20bd0
movq %rax, %rsi
callq 0x6250
testl %eax, %eax
jne 0xc089
addq $0x8, %r14
leaq 0x21819(%rip), %rax     # 0x2d89d
movb $0x1, (%rax)
decl %ebp
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x62e0
movl (%r15), %eax
movl %eax, 0xc(%rsp)
leaq 0x14c25(%rip), %rdi     # 0x20cc9
callq 0x6040
testq %rax, %rax
jne 0xc0c8
movl (%r13), %edi
callq 0x6150
testq %rax, %rax
jne 0xc0d4
leaq 0x21fad(%rip), %rax     # 0x2e070
movb $0x0, (%rax)
jmp 0xc0e4
leaq 0x21fa1(%rip), %rdi     # 0x2e070
movq %rax, %rsi
jmp 0xc0df
movq 0x20(%rax), %rsi
leaq 0x21f91(%rip), %rdi     # 0x2e070
callq 0x60e0
leaq 0x21f85(%rip), %r15     # 0x2e070
leaq 0x14ac8(%rip), %rsi     # 0x20bba
movq %r15, %rdi
callq 0x6250
testl %eax, %eax
jne 0xc102
movb $0x0, (%r15)
leaq 0x21f67(%rip), %r15     # 0x2e070
movq %r15, %rdi
callq 0x6170
testq %rax, %rax
je 0xc12d
cmpb $0x2f, -0x1(%rax,%r15)
je 0xc12d
movq %r15, %rdi
callq 0x6170
movw $0x2f, (%r15,%rax)
leaq 0x21e9c(%rip), %r15     # 0x2dfd0
leaq 0x21f35(%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 0x14a8d(%rip), %rdi     # 0x20bec
callq 0x6040
movq %rax, %r15
testq %rax, %rax
je 0xc180
movq %r15, %rdi
callq 0x1013f
leaq 0x21d65(%rip), %rax     # 0x2dee0
cmpb $0x0, (%rax)
jne 0xc1bb
movl (%r13), %edi
callq 0x6150
testq %rax, %rax
jne 0xc19f
leaq 0x14be5(%rip), %rdi     # 0x20d7a
callq 0x60f0
jmp 0xc225
movq (%rax), %r12
movq %r12, %rdi
callq 0x6170
leaq 0x21d2f(%rip), %rdi     # 0x2dee0
movq %r12, %rsi
movl %eax, %edx
callq 0x100f0
testq %r15, %r15
je 0xc1cc
leaq 0x21d69(%rip), %rax     # 0x2df30
cmpb $0x0, (%rax)
jne 0xc1e7
leaq 0x21d5d(%rip), %rax     # 0x2df30
movabsq $0x72662d796369756a, %rcx # imm = 0x72662D796369756A
movq %rcx, (%rax)
movl $0x746975, 0x8(%rax)    # imm = 0x746975
cmpl $0x2, %ebp
jne 0xc1fc
movq 0x8(%r14), %rdi
movq %rbx, %rsi
callq 0x144c3
testb %al, %al
je 0xc225
leaq 0x2169a(%rip), %r14     # 0x2d89d
cmpb $0x1, (%r14)
jne 0xc21a
leaq 0x149f2(%rip), %rdi     # 0x20c02
callq 0x6040
testq %rax, %rax
jne 0xc22f
callq 0x6130
addl 0xc(%rsp), %eax
jmp 0xc237
movl $0x1, %edi
callq 0x6500
movq %rax, %rdi
callq 0x64b0
leaq 0x21c32(%rip), %rbx     # 0x2de70
movl %eax, (%rbx)
cmpb $0x1, (%r14)
jne 0xc25f
leaq 0x149ba(%rip), %rdi     # 0x20c07
leaq 0x21c8c(%rip), %rsi     # 0x2dee0
movl %eax, %edx
xorl %eax, %eax
callq 0x61c0
jmp 0xc274
leaq 0x149c3(%rip), %rdi     # 0x20c29
leaq 0x21c73(%rip), %rsi     # 0x2dee0
xorl %eax, %eax
callq 0x61c0
movq 0x1dc85(%rip), %rax     # 0x29f00
movq (%rax), %rdi
callq 0x6350
movslq (%rbx), %rdi
leaq 0x21bdf(%rip), %rax     # 0x2de6c
movl %edi, (%rax)
callq 0x63c0
leaq 0x47a(%rip), %rbx       # 0xc715
movl $0x2, %edi
movq %rbx, %rsi
callq 0x6280
movl $0x3, %edi
movq %rbx, %rsi
callq 0x6280
xorl %eax, %eax
callq 0xb6bf
callq 0x61f0
callq 0x63b0
leaq 0x1499a(%rip), %rsi     # 0x20c67
movq %rax, %rdi
callq 0x6250
testl %eax, %eax
jne 0xc2f6
callq 0x6530
leaq 0x14a3f(%rip), %rdi     # 0x20d24
callq 0x60f0
leaq 0x14a51(%rip), %rdi     # 0x20d42
jmp 0xc6a9
movq 0x1dcb3(%rip), %rax     # 0x29fb0
cmpl $0x18, (%rax)
jl 0xc69d
movq 0x1dc8b(%rip), %rax     # 0x29f98
cmpl $0x4f, (%rax)
jle 0xc69d
leaq 0x21bc3(%rip), %rbx     # 0x2dee0
cmpb $0x0, (%rbx)
je 0xc339
leaq 0x21bb7(%rip), %rdi     # 0x2dee0
leaq 0x1493c(%rip), %rsi     # 0x20c6c
callq 0x6250
testl %eax, %eax
jne 0xc389
callq 0x6390
movq 0x1dbeb(%rip), %r15     # 0x29f30
movq (%r15), %rdi
movl $0x17, %esi
movl $0x2, %edx
callq 0x6490
cmpl $-0x1, %eax
je 0xc370
movq (%r15), %rdi
leaq 0x1490e(%rip), %rsi     # 0x20c74
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6550
movq (%r15), %rdi
leaq 0x21b66(%rip), %rsi     # 0x2dee0
movl $0x18, %edx
callq 0x63e0
callq 0x6180
cmpb $0x0, (%rbx)
jne 0xc39b
movl $0x79656e, 0x3(%rbx)    # imm = 0x79656E
movl $0x6e646f52, (%rbx)     # imm = 0x6E646F52
callq 0xc79f
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x60d0
leaq 0x2462c(%rip), %rcx     # 0x309e0
movq %rax, (%rcx)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x60d0
leaq 0x24625(%rip), %rcx     # 0x309f0
movq %rax, (%rcx)
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x60d0
leaq 0x24606(%rip), %rcx     # 0x309e8
movq %rax, (%rcx)
movb (%r14), %al
leaq 0x214b1(%rip), %rcx     # 0x2d8a0
movb %al, (%rcx)
xorl %edi, %edi
callq 0xf658
leaq -0x9e1(%rip), %rdi      # 0xba1e
movl $0x1, %esi
movl $0x1, %edx
callq 0x8bdd
leaq -0x3669(%rip), %rdi     # 0x8dac
movl $0x1, %esi
movl $0x1, %edx
callq 0x8bdd
leaq -0x3468(%rip), %rdi     # 0x8fc3
movl $0x1, %esi
movl $0x1, %edx
callq 0x8bdd
leaq -0x5b59(%rip), %rdi     # 0x68e8
movl $0x1, %esi
movl $0x2, %edx
callq 0x8bdd
leaq -0x35b9(%rip), %rdi     # 0x8e9e
movl $0x1, %esi
movl $0x46, %edx
callq 0x8c6f
leaq 0x1fb23(%rip), %rbx     # 0x2bf90
movl $0x3f843, %ebp          # imm = 0x3F843
movq %rbx, %rdi
callq 0x1ba82
movsbl %al, %edx
cmpl $0x11, %edx
ja 0xc472
btl %edx, %ebp
jae 0xc472
xorl %edi, %edi
movl $0x29, %esi
callq 0x1b715
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 0x10288
leaq 0x21348(%rip), %rax     # 0x2d850
movq %r12, (%rax)
xorl %edi, %edi
movl $0x29, %esi
movl $0x2, %edx
callq 0x1b715
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 0x10288
xorl %edi, %edi
movl $0x29, %esi
movl $0x3, %edx
callq 0x1b715
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 0x10288
leaq 0x1f84d(%rip), %rdi     # 0x2be60
callq 0x1ba82
movl %eax, %ebx
movsbl %bl, %edx
xorl %edi, %edi
movl $0x5d, %esi
callq 0x1b715
movq %rax, %r14
movq 0x10(%rax), %r12
movl %r15d, 0x38(%r12)
movsbq %bl, %rax
leaq (%rax,%rax,2), %rax
leaq 0x1f8cc(%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 0x211eb(%rip), %rax     # 0x2d858
movq %r12, (%rax)
movq %r14, %rdi
movl $0x1, %esi
callq 0x10288
xorl %edi, %edi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x1b715
movq %rax, %rdi
movl $0x1, %esi
callq 0x10288
callq 0xc859
callq 0x6530
leaq 0x146b4(%rip), %rdi     # 0x20d5d
callq 0x60f0
movl $0x1, %edi
callq 0xc715