#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*/ addToHoF(int, int);
int checkHoF(int);
int /*<<< orphan*/ printHoF();
int /*<<< orphan*/ printf(char *);
int rand();
int raten(int);
int /*<<< orphan*/ readHoF(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int);
long time(int /*<<< orphan*/ *);
int /*<<< orphan*/ writeHoF(char *);
int /*<<< orphan*/ writeToLog(char *, int, int);
int main(void) {
  int a, r, platz, nocheinmal = 0;
  if (!readHoF("hof.txt")) {
    printf("Fehler. Datei hof.txt konnte nicht eingelesen werden.\n");
  }
  do {
    int stime;
    long ltime;
    ltime = time(NULL);
    stime = (unsigned)ltime / 2;
    srand(stime);
    printf("Der Computer denkt sich eine Zahl zwischen 1 und 100.\n");
    r = (rand() % 100 + 1);
    a = raten(r);
    printHoF();
    platz = checkHoF(a);
    if (platz > -1) {
      addToHoF(platz, a);
      printHoF();
    }
    printf("Nocheinmal? (1 fuer ja, 0 fuer nein) ");
    scanf("%d", &nocheinmal);
    if (!writeToLog("log.txt", r, a)) {
      printf(
          "Fehler. Datei Log-Datei log.txt konnte nicht geschrieben werden.\n");
      return -2;
    }
  } while (nocheinmal != 0);
  if (!writeHoF("hof.txt")) {
    printf("Fehler. \"Hall of fame\" konnte nicht in hof.txt geschrieben "
           "werden.\n");
    return -4;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe23(%rip),%rdi
call   10b0 <readHoF@plt>
cmp    $0x0,%eax
jne    11f7 <main+0x37>
lea    0xe16(%rip),%rdi
call   1050 <printf@plt>
jmp    11fc <main+0x3c>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shr    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1080 <srand@plt>
lea    0xe1d(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   10e0 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <raten@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1060 <printHoF@plt>
mov    -0x8(%rbp),%edi
call   1090 <checkHoF@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jle    1275 <main+0xb5>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1070 <addToHoF@plt>
mov    $0x0,%al
call   1060 <printHoF@plt>
lea    0xdfa(%rip),%rdi
call   1050 <printf@plt>
lea    0xe14(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   10c0 <scanf@plt>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe01(%rip),%rdi
call   10d0 <writeToLog@plt>
cmp    $0x0,%eax
jne    12c4 <main+0x104>
lea    0xdf4(%rip),%rdi
call   1050 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1307 <main+0x147>
jmp    12c9 <main+0x109>
cmpl   $0x0,-0x14(%rbp)
jne    11fc <main+0x3c>
lea    0xd26(%rip),%rdi
call   1040 <writeHoF@plt>
cmp    $0x0,%eax
jne    1300 <main+0x140>
lea    0xdfa(%rip),%rdi
call   1050 <printf@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1307 <main+0x147>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
lea    0xe16(%rip),%rdi
call   10c0 <readHoF@plt>
test   %eax,%eax
jne    11ff <main+0x2f>
lea    0xe3f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe02(%rip),%r12
lea    0xe21(%rip),%r13
lea    0x4(%rsp),%rbx
lea    0xe18(%rip),%rbp
nopl   0x0(%rax)
xor    %edi,%edi
call   10b0 <time@plt>
shr    %eax
mov    %eax,%edi
call   1090 <srand@plt>
lea    0xe38(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10f0 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%r14d
add    $0x1,%r14d
mov    %r14d,%edi
call   1030 <raten@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1070 <printHoF@plt>
mov    %r15d,%edi
call   10a0 <checkHoF@plt>
test   %eax,%eax
js     1295 <main+0xc5>
mov    %eax,%edi
mov    %r15d,%esi
call   1080 <addToHoF@plt>
xor    %eax,%eax
call   1070 <printHoF@plt>
mov    %r12,%rdi
call   1060 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   10d0 <scanf@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %r15d,%edx
call   10e0 <writeToLog@plt>
test   %eax,%eax
je     12e5 <main+0x115>
cmpl   $0x0,0x4(%rsp)
jne    1220 <main+0x50>
lea    0xd34(%rip),%rdi
call   1050 <writeHoF@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    12f6 <main+0x126>
mov    $0xfffffffc,%ebx
lea    0xe03(%rip),%rdi
jmp    12f1 <main+0x121>
mov    $0xfffffffe,%ebx
lea    0xdb4(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"hof.txt\00"
@.str.1 = [55 x i8] c"Fehler. Datei hof.txt konnte nicht eingelesen werden.\0A\00"
@.str.2 = [55 x i8] c"Der Computer denkt sich eine Zahl zwischen 1 und 100.\0A\00"
@.str.3 = [38 x i8] c"Nocheinmal? (1 fuer ja, 0 fuer nein) \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [8 x i8] c"log.txt\00"
@.str.6 = [66 x i8] c"Fehler. Datei Log-Datei log.txt konnte nicht geschrieben werden.\0A\00"
@.str.7 = [68 x i8] c"Fehler. \22Hall of fame\22 konnte nicht in hof.txt geschrieben werden.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %5
%8 = call i32 @readHoF(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
br label %13
13: ; preds = %46, %12
%14 = call i64 @time(i32* null)
store i64 %14, i64* %7
%15 = load i64, i64* %7
%16 = trunc i64 %15 to i32
%17 = udiv i32 %16, 2
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = call i32 @srand(i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 (...) @rand()
%22 = srem i32 %21, 100
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = call i32 @raten(i32 %24)
store i32 %25, i32* %2
%26 = call i32 (...) @printHoF()
%27 = load i32, i32* %2
%28 = call i32 @checkHoF(i32 %27)
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = icmp sgt i32 %29, -1
br i1 %30, label %31, label %36
31: ; preds = %13
%32 = load i32, i32* %4
%33 = load i32, i32* %2
%34 = call i32 @addToHoF(i32 %32, i32 %33)
%35 = call i32 (...) @printHoF()
br label %36
36: ; preds = %31, %13
%37 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %5)
%39 = load i32, i32* %3
%40 = load i32, i32* %2
%41 = call i32 @writeToLog(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %39, i32 %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %36
%44 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.6, i64 0, i64 0))
store i32 -2, i32* %1
br label %55
45: ; preds = %36
br label %46
46: ; preds = %45
%47 = load i32, i32* %5
%48 = icmp ne i32 %47, 0
br i1 %48, label %13, label %49
49: ; preds = %46
%50 = call i32 @writeHoF(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%51 = icmp ne i32 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %49
%53 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.7, i64 0, i64 0))
store i32 -4, i32* %1
br label %55
54: ; preds = %49
store i32 0, i32* %1
br label %55
55: ; preds = %54, %52, %43
%56 = load i32, i32* %1
ret i32 %56
}

LLVM IR (-O2):
@.str = [8 x i8] c"hof.txt\00"
@.str.3 = [38 x i8] c"Nocheinmal? (1 fuer ja, 0 fuer nein) \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [8 x i8] c"log.txt\00"
@str = [54 x i8] c"Fehler. Datei hof.txt konnte nicht eingelesen werden.\00"
@str.8 = [54 x i8] c"Der Computer denkt sich eine Zahl zwischen 1 und 100.\00"
@str.9 = [65 x i8] c"Fehler. Datei Log-Datei log.txt konnte nicht geschrieben werden.\00"
@str.10 = [67 x i8] c"Fehler. \22Hall of fame\22 konnte nicht in hof.txt geschrieben werden.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 @readHoF(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
br label %8
8: ; preds = %7, %29
%9 = call i64 @time(i32* null)
%10 = trunc i64 %9 to i32
%11 = lshr i32 %10, 1
%12 = call i32 @srand(i32 %11)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.8, i64 0, i64 0))
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 100
%16 = add nsw i32 %15, 1
%17 = call i32 @raten(i32 %16)
%18 = call i32 (...) @printHoF()
%19 = call i32 @checkHoF(i32 %17)
%20 = icmp sgt i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %8
%22 = call i32 @addToHoF(i32 %19, i32 %17)
%23 = call i32 (...) @printHoF()
br label %24
24: ; preds = %21, %8
%25 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%27 = call i32 @writeToLog(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %16, i32 %17)
%28 = icmp eq i32 %27, 0
br i1 %28, label %35, label %29
29: ; preds = %24
%30 = load i32, i32* %1
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %8
32: ; preds = %29
%33 = call i32 @writeHoF(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %24, %32
%36 = phi i8* [ getelementptr inbounds ([67 x i8], [67 x i8]* @str.10, i64 0, i64 0), %32 ], [ getelementptr inbounds ([65 x i8], [65 x i8]* @str.9, i64 0, i64 0), %24 ]
%37 = phi i32 [ -4, %32 ], [ -2, %24 ]
%38 = call i32 @puts(i8* dereferenceable(1) %36)
br label %39
39: ; preds = %35, %32
%40 = phi i32 [ 0, %32 ], [ %37, %35 ]
ret i32 %40
}