#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int creat(char *, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ write(int, char *, int);
void writeRecord(int result) {
  struct stat check;
  char buffer[2] = {'0'};
  int fd;
  int tmpread = 1;
  if (stat("/home/user/game.sav", &check) != 0) {
    fd = creat("/home/user/game.sav", S_IWUSR | S_IRUSR);
    write(fd, "00", 2);
    close(fd);
  }
  fd = open("/home/user/game.sav", O_RDONLY);
  while (tmpread)
    tmpread = read(fd, buffer, 2);
  close(fd);
  if (result == 2)
    buffer[0] = buffer[0] + 1;
  else if (result == 1)
    buffer[1] = buffer[1] + 1;
  else
    return;
  fd = open("/home/user/game.sav", O_WRONLY | O_TRUNC);
  write(fd, buffer, 2);
  close(fd);
  fd = open("/home/user/game.sav", O_RDONLY);
  tmpread = 1;
  while (tmpread)
    tmpread = read(fd, buffer, 2);
  close(fd);
  printf("Punktestand: \n");
  printf("Spieler: %d\n", (buffer[1] - 48));
  printf("Computer: %d\n", (buffer[0] - 48));
}


x86 assembly (clang, -O0):
<writeRecord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0xe93(%rip),%ax
mov    %ax,-0xa(%rbp)
movl   $0x1,-0x14(%rbp)
lea    0xe6c(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
je     11e4 <writeRecord+0x74>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    0x2e11(%rip),%rax
or     (%rax),%esi
lea    0xe40(%rip),%rdi
call   1090 <creat@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
lea    0xe42(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
lea    0xe0c(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     121f <writeRecord+0xaf>
mov    -0x10(%rbp),%edi
lea    -0xa(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
jmp    11fc <writeRecord+0x8c>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x2,-0x4(%rbp)
jne    1240 <writeRecord+0xd0>
movsbl -0xa(%rbp),%eax
add    $0x1,%eax
mov    %al,-0xa(%rbp)
jmp    1263 <writeRecord+0xf3>
cmpl   $0x1,-0x4(%rbp)
jne    1259 <writeRecord+0xe9>
movsbl -0x9(%rbp),%eax
add    $0x1,%eax
mov    %al,-0x9(%rbp)
jmp    125e <writeRecord+0xee>
jmp    131f <writeRecord+0x1af>
jmp    1263 <writeRecord+0xf3>
mov    0x2d4e(%rip),%rax
mov    (%rax),%esi
mov    0x2d85(%rip),%rax
or     (%rax),%esi
lea    0xd84(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
lea    -0xa(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
mov    0x2d3c(%rip),%rax
mov    (%rax),%esi
lea    0xd53(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12df <writeRecord+0x16f>
mov    -0x10(%rbp),%edi
lea    -0xa(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
jmp    12bc <writeRecord+0x14c>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
lea    0xd29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x9(%rbp),%esi
sub    $0x30,%esi
lea    0xd23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0xa(%rbp),%esi
sub    $0x30,%esi
lea    0xd1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeRecord>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r14d
movw   $0x30,0xe(%rsp)
lea    0xe65(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1080 <stat@plt>
test   %rax,%rax
je     11e4 <writeRecord+0x64>
mov    0x2e27(%rip),%rax
mov    0x2e10(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe3d(%rip),%rdi
call   10a0 <creat@plt>
mov    %eax,%ebx
lea    0xe43(%rip),%rsi
mov    %eax,%edi
mov    $0x2,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2df5(%rip),%r15
mov    (%r15),%esi
lea    0xe0b(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebp
lea    0xe(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1070 <read@plt>
test   %eax,%eax
jne    1210 <writeRecord+0x90>
mov    %ebp,%edi
call   1060 <close@plt>
cmp    $0x1,%r14d
je     1241 <writeRecord+0xc1>
cmp    $0x2,%r14d
jne    12f2 <writeRecord+0x172>
addb   $0x1,0xe(%rsp)
jmp    1246 <writeRecord+0xc6>
addb   $0x1,0xf(%rsp)
mov    0x2d6b(%rip),%rax
mov    0x2da4(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xda1(%rip),%r14
mov    %r14,%rdi
call   1090 <open@plt>
mov    %eax,%ebp
lea    0xe(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1090 <open@plt>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1070 <read@plt>
test   %eax,%eax
jne    12a0 <writeRecord+0x120>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0xd71(%rip),%rdi
call   1030 <puts@plt>
movsbl 0xf(%rsp),%esi
add    $0xffffffd0,%esi
lea    0xd42(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movsbl 0xe(%rsp),%esi
add    $0xffffffd0,%esi
lea    0xd39(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@__const.writeRecord.buffer = [2 x i8] c"0\00"
@.str = [20 x i8] c"/home/user/game.sav\00"
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@.str.1 = [3 x i8] c"00\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [15 x i8] c"Punktestand: \0A\00"
@.str.3 = [13 x i8] c"Spieler: %d\0A\00"
@.str.4 = [14 x i8] c"Computer: %d\0A\00"
define void @writeRecord(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.stat
%4 = alloca [2 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = bitcast [2 x i8]* %4 to i8*
store i32 1, i32* %6
%8 = call i64 @stat(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %1
%11 = load i32, i32* @S_IWUSR
%12 = load i32, i32* @S_IRUSR
%13 = or i32 %11, %12
%14 = call i32 @creat(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%17 = load i32, i32* %5
%18 = call i32 @close(i32 %17)
br label %19
19: ; preds = %10, %1
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %20)
store i32 %21, i32* %5
br label %22
22: ; preds = %25, %19
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* %5
%27 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%28 = call i32 @read(i32 %26, i8* %27, i32 2)
store i32 %28, i32* %6
br label %22
29: ; preds = %22
%30 = load i32, i32* %5
%31 = call i32 @close(i32 %30)
%32 = load i32, i32* %2
%33 = icmp eq i32 %32, 2
br i1 %33, label %34, label %41
34: ; preds = %29
%35 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = add nsw i32 %37, 1
%39 = trunc i32 %38 to i8
%40 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8 %39, i8* %40
br label %53
41: ; preds = %29
%42 = load i32, i32* %2
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %51
44: ; preds = %41
%45 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = add nsw i32 %47, 1
%49 = trunc i32 %48 to i8
%50 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 %49, i8* %50
br label %52
51: ; preds = %41
br label %86
52: ; preds = %44
br label %53
53: ; preds = %52, %34
%54 = load i32, i32* @O_WRONLY
%55 = load i32, i32* @O_TRUNC
%56 = or i32 %54, %55
%57 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %56)
store i32 %57, i32* %5
%58 = load i32, i32* %5
%59 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%60 = call i32 @write(i32 %58, i8* %59, i32 2)
%61 = load i32, i32* %5
%62 = call i32 @close(i32 %61)
%63 = load i32, i32* @O_RDONLY
%64 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %63)
store i32 %64, i32* %5
store i32 1, i32* %6
br label %65
65: ; preds = %68, %53
%66 = load i32, i32* %6
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %65
%69 = load i32, i32* %5
%70 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%71 = call i32 @read(i32 %69, i8* %70, i32 2)
store i32 %71, i32* %6
br label %65
72: ; preds = %65
%73 = load i32, i32* %5
%74 = call i32 @close(i32 %73)
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%76 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
%77 = load i8, i8* %76
%78 = sext i8 %77 to i32
%79 = sub nsw i32 %78, 48
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %79)
%81 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = sub nsw i32 %83, 48
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %84)
br label %86
86: ; preds = %72, %51
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [20 x i8] c"/home/user/game.sav\00"
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@.str.1 = [3 x i8] c"00\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [13 x i8] c"Spieler: %d\0A\00"
@.str.4 = [14 x i8] c"Computer: %d\0A\00"
@str = [14 x i8] c"Punktestand: \00"
define void @writeRecord(i32 %0) {
%2 = alloca %struct.stat
%3 = alloca i16
%4 = bitcast i16* %3 to [2 x i8]*
%5 = bitcast %struct.stat* %2 to i8*
%6 = bitcast i16* %3 to i8*
store i16 48, i16* %3
%7 = call i64 @stat(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %1
%10 = load i32, i32* @S_IWUSR
%11 = load i32, i32* @S_IRUSR
%12 = or i32 %11, %10
%13 = call i32 @creat(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @write(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%15 = call i32 @close(i32 %13)
br label %16
16: ; preds = %9, %1
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %16, %19
%20 = call i32 @read(i32 %18, i8* %6, i32 2)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %19
22: ; preds = %19
%23 = call i32 @close(i32 %18)
switch i32 %0, label %55 [
i32 2, label %24
i32 1, label %27
]
24: ; preds = %22
%25 = load i8, i8* %6
%26 = add i8 %25, 1
store i8 %26, i8* %6
br label %31
27: ; preds = %22
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
%29 = load i8, i8* %28
%30 = add i8 %29, 1
store i8 %30, i8* %28
br label %31
31: ; preds = %27, %24
%32 = load i32, i32* @O_WRONLY
%33 = load i32, i32* @O_TRUNC
%34 = or i32 %33, %32
%35 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = call i32 @write(i32 %35, i8* %6, i32 2)
%37 = call i32 @close(i32 %35)
%38 = load i32, i32* @O_RDONLY
%39 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %31, %40
%41 = call i32 @read(i32 %39, i8* %6, i32 2)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %40
43: ; preds = %40
%44 = call i32 @close(i32 %39)
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%46 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = add nsw i32 %48, -48
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %49)
%51 = load i8, i8* %6
%52 = sext i8 %51 to i32
%53 = add nsw i32 %52, -48
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %22, %43
ret void
}