#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(void) {
  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");
    if (fd >= 0)
      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     11dc <restartgame+0x8c>
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jl     11d0 <restartgame+0x80>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    11eb <restartgame+0x9b>
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   %rbx
sub    $0x10,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11b3 <restartgame+0x63>
mov    %eax,%ebx
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    1199 <restartgame+0x49>
cmpl   $0x2,0xc(%rsp)
jne    1199 <restartgame+0x49>
mov    %ebx,%edi
call   1060 <readdump@plt>
test   %rax,%rax
je     11c6 <restartgame+0x76>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0x1,%eax
jmp    11cf <restartgame+0x7f>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    11cf <restartgame+0x7f>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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 %27
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 = icmp sge i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* %2
%25 = call i32 @close(i32 %24)
br label %26
26: ; preds = %23, %19
store i32 1, i32* %1
br label %30
27: ; preds = %15
%28 = load i32, i32* %2
%29 = call i32 @close(i32 %28)
store i32 0, i32* %1
br label %30
30: ; preds = %27, %26
%31 = load i32, i32* %1
ret i32 %31
}

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 %17, label %12
12: ; preds = %6
%13 = tail call i64 @readdump(i32 %4)
%14 = icmp eq i64 %13, 0
br i1 %14, label %20, label %17
15: ; preds = %0
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %22
17: ; preds = %12, %6
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 @close(i32 %4)
br label %22
20: ; preds = %12
%21 = tail call i32 @close(i32 %4)
br label %22
22: ; preds = %15, %17, %20
%23 = phi i32 [ 0, %20 ], [ 1, %17 ], [ 1, %15 ]
ret i32 %23
}