#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*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read(int, int *, int);
scalar_t__ readdump(int);
int restartgame() {
  register int fd;
  int version;
  if ((fd = open("trek.dump", 0)) < 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
lea    0xea1(%rip),%rdi
xor    %esi,%esi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jl     11ab <restartgame+0x5b>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cltq
cmp    $0x4,%rax
jne    11ab <restartgame+0x5b>
cmpl   $0x2,-0xc(%rbp)
jne    11ab <restartgame+0x5b>
mov    -0x8(%rbp),%edi
call   1060 <readdump@plt>
cmp    $0x0,%rax
je     11cb <restartgame+0x7b>
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    11da <restartgame+0x8a>
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
lea    0xea6(%rip),%rdi
xor    %esi,%esi
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1190 <restartgame+0x40>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    1190 <restartgame+0x40>
cmpl   $0x2,0x4(%rsp)
jne    1190 <restartgame+0x40>
mov    %ebx,%edi
call   1060 <readdump@plt>
test   %rax,%rax
je     11b1 <restartgame+0x61>
lea    0xe73(%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    11a1 <restartgame+0x51>

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

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