// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x6450
movb %al, -0x19(%rbp)
movsbl %al, %eax
cmpl $0x0, %eax
jge 0x1a246
movq -0x10(%rbp), %rsi
leaq 0x129d6(%rip), %rdi     # 0x2cc0c
movb $0x0, %al
callq 0x61b0
movb $0x0, -0x1(%rbp)
jmp 0x1a627
leaq -0x80(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq 0x1c418(%rip), %rdi     # 0x36670
callq 0x6160
movq -0x120(%rbp), %rdi
addq $0x1, %rax
movl %eax, %esi
movsbl -0x19(%rbp), %edx
callq 0x1bc90
leaq -0x80(%rbp), %rdi
leaq 0x1c3f2(%rip), %rsi     # 0x36670
callq 0x6250
cmpl $0x0, %eax
je 0x1a29f
leaq 0x12997(%rip), %rdi     # 0x2cc26
movb $0x0, %al
callq 0x61b0
movb $0x0, -0x1(%rbp)
jmp 0x1a627
movsbl -0x19(%rbp), %edi
leaq -0x110(%rbp), %rsi
callq 0x6580
movsbl -0x19(%rbp), %edx
leaq 0x225a6(%rip), %rdi     # 0x3c860
addq $0x8, %rdi
movl $0x8, %esi
callq 0x1bc90
movsbl -0x19(%rbp), %edx
leaq 0x2258d(%rip), %rdi     # 0x3c860
movl $0x8, %esi
callq 0x1bc90
movsbl -0x19(%rbp), %edx
leaq 0x22578(%rip), %rdi     # 0x3c860
addq $0x68, %rdi
movl $0x8, %esi
callq 0x1bc90
movsbl -0x19(%rbp), %edx
leaq 0x2255f(%rip), %rdi     # 0x3c860
addq $0x58, %rdi
movl $0x8, %esi
callq 0x1bc90
movsbl -0x19(%rbp), %edx
leaq -0x114(%rbp), %rdi
movl $0x4, %esi
callq 0x1bc90
movsbl -0x19(%rbp), %edx
leaq -0x118(%rbp), %rdi
movl $0x4, %esi
callq 0x1bc90
leaq 0x1c9cd(%rip), %rax     # 0x36d0d
testb $0x1, (%rax)
jne 0x1a37e
movq -0x108(%rbp), %rax
cmpq 0x22515(%rip), %rax     # 0x3c868
jne 0x1a365
movq -0x110(%rbp), %rax
cmpq 0x224fd(%rip), %rax     # 0x3c860
je 0x1a37c
leaq 0x128e5(%rip), %rdi     # 0x2cc51
movb $0x0, %al
callq 0x61b0
movb $0x0, -0x1(%rbp)
jmp 0x1a627
jmp 0x1a37e
callq 0x61e0
movl -0x114(%rbp), %eax
movq 0x18c50(%rip), %rcx     # 0x32fe0
cmpl (%rcx), %eax
jle 0x1a3cd
callq 0x6530
movl -0x114(%rbp), %esi
leaq 0x128d7(%rip), %rdi     # 0x2cc7d
movb $0x0, %al
callq 0x61b0
movq 0x18c2c(%rip), %rax     # 0x32fe0
movl (%rax), %esi
leaq 0x128fc(%rip), %rdi     # 0x2ccb9
movb $0x0, %al
callq 0x61b0
movb $0x0, -0x1(%rbp)
jmp 0x1a627
movl -0x118(%rbp), %eax
movq 0x18bfe(%rip), %rcx     # 0x32fd8
cmpl (%rcx), %eax
jle 0x1a417
callq 0x6530
movl -0x118(%rbp), %esi
leaq 0x12903(%rip), %rdi     # 0x2ccf3
movb $0x0, %al
callq 0x61b0
movq 0x18bda(%rip), %rax     # 0x32fd8
movl (%rax), %esi
leaq 0x1292a(%rip), %rdi     # 0x2cd31
movb $0x0, %al
callq 0x61b0
movb $0x0, -0x1(%rbp)
jmp 0x1a627
movq 0x18bc2(%rip), %rax     # 0x32fe0
movl (%rax), %edi
movq 0x18bb1(%rip), %rax     # 0x32fd8
movl (%rax), %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x60c0
movq %rax, %rcx
leaq 0x1fa14(%rip), %rax     # 0x39e50
movq %rcx, (%rax)
movq 0x18b9a(%rip), %rax     # 0x32fe0
movl (%rax), %edi
movq 0x18b89(%rip), %rax     # 0x32fd8
movl (%rax), %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x60c0
movq %rax, %rcx
leaq 0x1f9fc(%rip), %rax     # 0x39e60
movq %rcx, (%rax)
movq 0x18b72(%rip), %rax     # 0x32fe0
movl (%rax), %edi
movq 0x18b61(%rip), %rax     # 0x32fd8
movl (%rax), %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x60c0
movq %rax, %rcx
leaq 0x1f9cc(%rip), %rax     # 0x39e58
movq %rcx, (%rax)
leaq 0x1c84a(%rip), %rax     # 0x36ce0
movl $0x0, (%rax)
leaq 0x1f9ad(%rip), %rax     # 0x39e50
movq (%rax), %rax
movq %rax, -0x130(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x110(%rbp), %rdi
addq $0x58, %rdi
movb $0x0, %al
callq 0x6150
movq -0x130(%rbp), %rdi
movq -0x128(%rbp), %r8
movq %rax, %r9
xorl %edx, %edx
leaq 0x12889(%rip), %rcx     # 0x2cd6d
movl %edx, %esi
movb $0x0, %al
callq 0x6200
leaq 0x1c819(%rip), %rax     # 0x36d0d
testb $0x1, (%rax)
jne 0x1a521
cmpq $0x1, -0x100(%rbp)
je 0x1a51f
callq 0x6530
leaq 0x12865(%rip), %rdi     # 0x2cd74
movb $0x0, %al
callq 0x61b0
movb $0x0, -0x1(%rbp)
jmp 0x1a627
jmp 0x1a521
movsbl -0x19(%rbp), %edi
callq 0x20ca0
cmpl $0x0, %eax
jne 0x1a54b
callq 0x6530
leaq 0x1285c(%rip), %rdi     # 0x2cd97
movb $0x0, %al
callq 0x61b0
movb $0x0, -0x1(%rbp)
jmp 0x1a627
leaq 0x1c7bb(%rip), %rax     # 0x36d0d
testb $0x1, (%rax)
jne 0x1a5db
callq 0x6530
callq 0x65a0
movl %eax, -0x20(%rbp)
cmpl $0x0, %eax
jge 0x1a579
movl $0x1, %edi
callq 0x6570
jmp 0x1a560
cmpl $0x0, -0x20(%rbp)
jne 0x1a5ab
leaq 0x1cd4a(%rip), %rax     # 0x372d0
movl (%rax), %edi
callq 0x6520
leaq 0x1cd40(%rip), %rax     # 0x372d4
movl (%rax), %edi
callq 0x6410
movq -0x10(%rbp), %rdi
callq 0x6090
xorl %edi, %edi
callq 0x6500
jmp 0x1a5ad
leaq -0x24(%rbp), %rdi
callq 0x6590
cmpl -0x20(%rbp), %eax
je 0x1a5bd
jmp 0x1a5ad
cmpl $0x0, -0x24(%rbp)
jge 0x1a5d7
leaq 0x127e2(%rip), %rdi     # 0x2cdac
movb $0x0, %al
callq 0x61b0
movb $0x0, -0x1(%rbp)
jmp 0x1a627
jmp 0x1a5d9
jmp 0x1a5db
movq -0x18(%rbp), %rcx
movq 0x189ea(%rip), %rax     # 0x32fd0
movq %rcx, (%rax)
movq -0x10(%rbp), %rsi
leaq 0x1ce4c(%rip), %rdi     # 0x37440
callq 0x60d0
movb $0x0, %al
callq 0xefc0
leaq 0x1f849(%rip), %rax     # 0x39e50
movq (%rax), %rdi
callq 0xe2d0
callq 0x6120
movslq %eax, %rdi
callq 0x63d0
movb $0x0, %al
callq 0xf0a0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop