#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read(int, int *, int);
scalar_t__ readdump(int);
int restartgame() {
  int fd;
  int version;
  if ((fd = open("trek.dump", O_RDONLY)) < 0 ||
      read(fd, &version, sizeof version) != sizeof version || version != 2 ||
      readdump(fd)) {
    printf("cannot restart\n");
    close(fd);
    return (1);
  }
  close(fd);
  return (0);
}


x86 assembly (clang, -O0):
<restartgame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jl     11b2 <restartgame+0x62>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cltq
cmp    $0x4,%rax
jne    11b2 <restartgame+0x62>
cmpl   $0x2,-0xc(%rbp)
jne    11b2 <restartgame+0x62>
mov    -0x8(%rbp),%edi
call   1060 <readdump@plt>
cmp    $0x0,%rax
je     11d2 <restartgame+0x82>
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e1 <restartgame+0x91>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<restartgame>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
lea    0xe9d(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1197 <restartgame+0x47>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    1197 <restartgame+0x47>
cmpl   $0x2,0x4(%rsp)
jne    1197 <restartgame+0x47>
mov    %ebx,%edi
call   1060 <readdump@plt>
test   %rax,%rax
je     11b8 <restartgame+0x68>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %ebp,%ebp
jmp    11a8 <restartgame+0x58>

LLVM IR (-O0):
@.str = [10 x i8] c"trek.dump\00"
@O_RDONLY = global i32 0
@.str.1 = [16 x i8] c"cannot restart\0A\00"
define i32 @restartgame() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %0
%8 = load i32, i32* %2
%9 = call i32 @read(i32 %8, i32* %3, i32 4)
%10 = sext i32 %9 to i64
%11 = icmp ne i64 %10, 4
br i1 %11, label %19, label %12
12: ; preds = %7
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 2
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = load i32, i32* %2
%17 = call i64 @readdump(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15, %12, %7, %0
%20 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* %2
%22 = call i32 @close(i32 %21)
store i32 1, i32* %1
br label %26
23: ; preds = %15
%24 = load i32, i32* %2
%25 = call i32 @close(i32 %24)
store i32 0, i32* %1
br label %26
26: ; preds = %23, %19
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [10 x i8] c"trek.dump\00"
@O_RDONLY = global i32 0
@str = [15 x i8] c"cannot restart\00"
define i32 @restartgame() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %0
%7 = call i32 @read(i32 %4, i32* %1, i32 4)
%8 = icmp ne i32 %7, 4
%9 = load i32, i32* %1
%10 = icmp ne i32 %9, 2
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %15, label %12
12: ; preds = %6
%13 = tail call i64 @readdump(i32 %4)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12, %6, %0
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %12, %15
%18 = phi i32 [ 1, %15 ], [ 0, %12 ]
%19 = tail call i32 @close(i32 %4)
ret i32 %18
}