// File: /workspace/github_c_makefile_star2_O1/ajpaulson[P]srogue11/save.c
// Function: restore
bool restore(char const *file,char **envp)
{
  char inf;
  int pid;
	int ret_status;
#ifndef _AIX
	extern char **environ;
#endif
#ifdef __DJGPP__                      /* st_ino w/ DJGPP under WinXP broken */
        _djstat_flags |= _STAT_INODE; /* so turn off computing it for now   */
#endif
	char buf[LINLEN];
	STAT sbuf2;
	int slines, scols;

	if ((inf = open(file, O_RDONLY)) < 0) {
		printf("Cannot read save game %s\n",file);
		return FALSE;
	}

	encread(buf, strlen(version) + 1, inf);

	if (strcmp(buf, version) != 0) {
		printf("Sorry, saved game version is out of date.\n");
		return FALSE;
	}

	fstat(inf, &sbuf2);

	encread(&sbuf.st_ino,sizeof(sbuf.st_ino), inf);
	encread(&sbuf.st_dev,sizeof(sbuf.st_dev), inf);
	encread(&sbuf.st_ctime,sizeof(sbuf.st_ctime), inf);
	encread(&sbuf.st_mtime,sizeof(sbuf.st_mtime), inf);
	encread(&slines,sizeof(slines),inf);
	encread(&scols,sizeof(scols),inf);

	/*
	 * we do not close the file so that we will have a hold of the
	 * inode for as long as possible
	 */

	if (!wizard)
	{
		if(sbuf2.st_ino!=sbuf.st_ino || sbuf2.st_dev!=sbuf.st_dev) {
			printf("Sorry, saved game is not in the same file.\n");
			return FALSE;
		}
	}

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

	initscr();

	if (slines > LINES)
	{
		endwin();
		printf("Sorry, original game was played on a screen with %d lines.\n",slines);
		printf("Current screen only has %d lines. Unable to restore game\n",LINES);
		return(FALSE);
	}

	if (scols > COLS)
	{
		endwin();
		printf("Sorry, original game was played on a screen with %d columns.\n", scols);
		printf("Current screen only has %d columns. Unable to restore game\n",COLS);
		return(FALSE);
	}

	cw = newwin(LINES, COLS, 0, 0);
	mw = newwin(LINES, COLS, 0, 0);
	hw = newwin(LINES, COLS, 0, 0);

	mpos = 0;
	mvwprintw(cw, 0, 0, "%s: %s", file, ctime(&sbuf2.st_mtime));

	/* defeat multiple restarting from the same place */

	if (!wizard)
	{
		if (sbuf2.st_nlink != 1)
		{
                        endwin();
			printf("Cannot restore from a linked file\n");
			return FALSE;
		}
	}

	if (rs_restore_file(inf) == FALSE)
	{
		endwin();
		printf("Cannot restore file\n");
		return(FALSE);
	}

#if defined(__CYGWIN__) || defined(__DJGPP__)
	close(inf);
#endif
	if (!wizard)
	{
#ifndef __DJGPP__
			endwin();
			while((pid = fork()) < 0)
				sleep(1);

			/* set id to unlink file */
			if(pid == 0)
			{
				setuid(playuid);
				setgid(playgid);
				unlink(file);
				exit(0);
			}
			/* wait for unlink to finish */
			else
			{
				while(wait(&ret_status) != pid)
					continue;
				if (ret_status < 0)
				{
					printf("Cannot unlink file\n");
					return FALSE;
				}
			}
#else
		if (unlink(file) < 0)
		{
			printf("Cannot unlink file\n");
			return FALSE;
		}
#endif

	}

	environ = envp;

	strcpy(file_name, file);
	setup();
	restscr(cw);
	srand48(getpid());
	playit();
  return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
xorl %esi, %esi
xorl %eax, %eax
callq 0x6450
movsbl %al, %ebp
testl %ebp, %ebp
js 0x14530
leaq 0x190bf(%rip), %r15     # 0x2d5b0
movq %r15, %rdi
callq 0x6170
leal 0x1(%rax), %esi
leaq 0xa0(%rsp), %r12
movq %r12, %rdi
movl %ebp, %edx
callq 0x15700
movq %r12, %rdi
movq %r15, %rsi
callq 0x6250
testl %eax, %eax
je 0x14548
leaq 0xe21e(%rip), %rdi      # 0x22742
callq 0x60f0
xorl %ebp, %ebp
jmp 0x1466e
leaq 0xe086(%rip), %rdi      # 0x225bd
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x61c0
jmp 0x1466e
leaq 0x10(%rsp), %rsi
movl %ebp, %edi
callq 0x6570
leaq 0x1ee9d(%rip), %rdi     # 0x333f8
movl $0x8, %esi
movl %ebp, %edx
callq 0x15700
leaq 0x1ee82(%rip), %rdi     # 0x333f0
movl $0x8, %esi
movl %ebp, %edx
callq 0x15700
leaq 0x1eed7(%rip), %rdi     # 0x33458
movl $0x8, %esi
movl %ebp, %edx
callq 0x15700
leaq 0x1eeb4(%rip), %rdi     # 0x33448
movl $0x8, %esi
movl %ebp, %edx
callq 0x15700
leaq 0x8(%rsp), %rdi
movl $0x4, %esi
movl %ebp, %edx
callq 0x15700
leaq 0x4(%rsp), %rdi
movl $0x4, %esi
movl %ebp, %edx
callq 0x15700
leaq 0x192d4(%rip), %r13     # 0x2d89d
cmpb $0x0, (%r13)
je 0x1460a
callq 0x61f0
movq 0x159d4(%rip), %r15     # 0x29fb0
movl (%r15), %edi
cmpl %edi, 0x8(%rsp)
jle 0x14632
callq 0x6530
movl 0x8(%rsp), %esi
leaq 0xdfe2(%rip), %rdi      # 0x225d7
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x61c0
movl (%r15), %esi
leaq 0xe00b(%rip), %rdi      # 0x22613
jmp 0x14667
movq 0x18(%rsp), %rax
cmpq 0x1ede2(%rip), %rax     # 0x333f8
jne 0x14626
movq 0x10(%rsp), %rax
cmpq 0x1edcc(%rip), %rax     # 0x333f0
je 0x145d0
leaq 0xe0a1(%rip), %rdi      # 0x226ce
jmp 0x14524
movq 0x1595f(%rip), %r12     # 0x29f98
movl (%r12), %esi
cmpl %esi, 0x4(%rsp)
jle 0x14682
callq 0x6530
movl 0x4(%rsp), %esi
leaq 0xdffa(%rip), %rdi      # 0x2264d
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x61c0
movl (%r12), %esi
leaq 0xe024(%rip), %rdi      # 0x2268b
xorl %eax, %eax
callq 0x61c0
movl %ebp, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x60d0
leaq 0x1c34e(%rip), %rcx     # 0x309e0
movq %rax, (%rcx)
movl (%r15), %edi
movl (%r12), %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x60d0
leaq 0x1c344(%rip), %rcx     # 0x309f0
movq %rax, (%rcx)
movl (%r15), %edi
movl (%r12), %esi
leaq 0x1c323(%rip), %r12     # 0x309e0
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x60d0
leaq 0x1c31b(%rip), %rcx     # 0x309e8
movq %rax, (%rcx)
leaq 0x19199(%rip), %rax     # 0x2d870
movl $0x0, (%rax)
movq (%r12), %r15
leaq 0x68(%rsp), %rdi
xorl %eax, %eax
callq 0x6160
leaq 0xdfd3(%rip), %rcx      # 0x226c7
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rbx, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x6210
cmpb $0x0, (%r13)
jne 0x14728
cmpq $0x1, 0x20(%rsp)
je 0x14728
callq 0x6530
leaq 0xdffd(%rip), %rdi      # 0x22720
jmp 0x14524
movl %ebp, %edi
callq 0x1908b
testl %eax, %eax
je 0x14754
cmpb $0x0, (%r13)
jne 0x14783
callq 0x6530
callq 0x6590
testl %eax, %eax
jns 0x14765
movl $0x1, %edi
callq 0x6560
jmp 0x1473f
callq 0x6530
leaq 0xdfac(%rip), %rdi      # 0x2270c
jmp 0x14524
movl %eax, %ebp
testl %eax, %eax
je 0x147d4
leaq 0xc(%rsp), %r15
movq %r15, %rdi
callq 0x6580
cmpl %ebp, %eax
jne 0x14770
cmpl $0x0, 0xc(%rsp)
js 0x147c8
movq 0x157ee(%rip), %rax     # 0x29f78
movq %r14, (%rax)
leaq 0x1983c(%rip), %rdi     # 0x2dfd0
movq %rbx, %rsi
callq 0x60e0
xorl %eax, %eax
callq 0xc79f
movq (%r12), %rdi
callq 0xbdbb
callq 0x6130
movslq %eax, %rdi
callq 0x63c0
xorl %eax, %eax
callq 0xc859
movb $0x1, %bpl
jmp 0x1466e
leaq 0xdf2a(%rip), %rdi      # 0x226f9
jmp 0x14524
leaq 0x19685(%rip), %rax     # 0x2de60
movl (%rax), %edi
callq 0x6520
leaq 0x1967b(%rip), %rax     # 0x2de64
movl (%rax), %edi
callq 0x6410
movq %rbx, %rdi
callq 0x60a0
xorl %edi, %edi
callq 0x6500
nop