#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 EOF;
int getchar();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ scanf(char *, int *);
int raten(int gedachtezahl) {
  int ratemal = 0;
  int anzahl = 0;
  do {
    anzahl++;
    printf("Versuch %3d: Deine Zahl? ", anzahl);
    while (scanf("%3d", &ratemal) <= 0) {
      printf("Fehler bei der Eingabe. Bitte versuche es noch einmal: ");
      int c = getchar();
      while (c != '\n' && c != EOF)
        c = getchar();
    }
    if (gedachtezahl > ratemal) {
      printf("Die gedachte Zahl ist groesser.\n");
    } else if (gedachtezahl < ratemal) {
      printf("Die gedachte Zahl ist kleiner.\n");
    } else if (gedachtezahl == ratemal) {
      printf("Super! Erraten mit %d Versuchen.\n", anzahl);
    }
  } while (!(gedachtezahl == ratemal));
  return anzahl;
}


x86 assembly (clang, -O0):
<raten>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x0,%rax
jg     11da <raten+0xaa>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0xa,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     11b6 <raten+0x86>
mov    -0x10(%rbp),%eax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11c6 <raten+0x96>
jmp    11d5 <raten+0xa5>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
jmp    1195 <raten+0x65>
jmp    1163 <raten+0x33>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    11f9 <raten+0xc9>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123f <raten+0x10f>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1218 <raten+0xe8>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123a <raten+0x10a>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1235 <raten+0x105>
mov    -0xc(%rbp),%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123a <raten+0x10a>
jmp    123f <raten+0x10f>
jmp    1244 <raten+0x114>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
sete   %al
xor    $0xff,%al
test   $0x1,%al
jne    1149 <raten+0x19>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<raten>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
movl   $0x0,0x4(%rsp)
lea    0xebd(%rip),%rbx
lea    0x4(%rsp),%rbp
lea    0xeb5(%rip),%r12
mov    0x2e78(%rip),%r14
xor    %r13d,%r13d
jmp    1197 <raten+0x57>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xf10(%rip),%rdi
call   1030 <puts@plt>
cmp    %r15d,0x4(%rsp)
je     122c <raten+0xec>
add    $0x1,%r13d
lea    0xe5e(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <scanf@plt>
test   %rax,%rax
jg     11f0 <raten+0xb0>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
je     11b0 <raten+0x70>
cmp    (%r14),%eax
jne    11d0 <raten+0x90>
jmp    11b0 <raten+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x4(%rsp),%eax
cmp    %r15d,%eax
jl     1180 <raten+0x40>
jle    1210 <raten+0xd0>
lea    0xe76(%rip),%rdi
jmp    1187 <raten+0x47>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
jne    118c <raten+0x4c>
lea    0xe39(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    118c <raten+0x4c>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Versuch %3d: Deine Zahl? \00"
@.str.1 = [4 x i8] c"%3d\00"
@.str.2 = [56 x i8] c"Fehler bei der Eingabe. Bitte versuche es noch einmal: \00"
@EOF = global i32 0
@.str.3 = [33 x i8] c"Die gedachte Zahl ist groesser.\0A\00"
@.str.4 = [32 x i8] c"Die gedachte Zahl ist kleiner.\0A\00"
@.str.5 = [34 x i8] c"Super! Erraten mit %d Versuchen.\0A\00"
define i32 @raten(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %51, %1
%7 = load i32, i32* %4
%8 = add nsw i32 %7, 1
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %28, %6
%12 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%13 = icmp sle i64 %12, 0
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 (...) @getchar()
store i32 %16, i32* %5
br label %17
17: ; preds = %26, %14
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 10
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* %5
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %21, %22
br label %24
24: ; preds = %20, %17
%25 = phi i1 [ false, %17 ], [ %23, %20 ]
br i1 %25, label %26, label %28
26: ; preds = %24
%27 = call i32 (...) @getchar()
store i32 %27, i32* %5
br label %17
28: ; preds = %24
br label %11
29: ; preds = %11
%30 = load i32, i32* %2
%31 = load i32, i32* %3
%32 = icmp sgt i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %50
35: ; preds = %29
%36 = load i32, i32* %2
%37 = load i32, i32* %3
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %49
41: ; preds = %35
%42 = load i32, i32* %2
%43 = load i32, i32* %3
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* %4
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %45, %41
br label %49
49: ; preds = %48, %39
br label %50
50: ; preds = %49, %33
br label %51
51: ; preds = %50
%52 = load i32, i32* %2
%53 = load i32, i32* %3
%54 = icmp eq i32 %52, %53
%55 = xor i1 %54, true
br i1 %55, label %6, label %56
56: ; preds = %51
%57 = load i32, i32* %4
ret i32 %57
}

LLVM IR (-O2):
@.str = [26 x i8] c"Versuch %3d: Deine Zahl? \00"
@.str.1 = [4 x i8] c"%3d\00"
@.str.2 = [56 x i8] c"Fehler bei der Eingabe. Bitte versuche es noch einmal: \00"
@EOF = global i32 0
@.str.5 = [34 x i8] c"Super! Erraten mit %d Versuchen.\0A\00"
@str = [31 x i8] c"Die gedachte Zahl ist kleiner.\00"
@str.6 = [32 x i8] c"Die gedachte Zahl ist groesser.\00"
define i32 @raten(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %4
4: ; preds = %39, %1
%5 = phi i32 [ 0, %1 ], [ %6, %39 ]
%6 = add nuw nsw i32 %5, 1
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = icmp slt i64 %8, 1
br i1 %9, label %13, label %26
10: ; preds = %20, %13
%11 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%12 = icmp slt i64 %11, 1
br i1 %12, label %13, label %26
13: ; preds = %4, %10
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (...) @getchar()
%16 = icmp ne i32 %15, 10
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %15, %17
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %20, label %10
20: ; preds = %13, %20
%21 = call i32 (...) @getchar()
%22 = icmp ne i32 %21, 10
%23 = load i32, i32* @EOF
%24 = icmp ne i32 %21, %23
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %20, label %10
26: ; preds = %10, %4
%27 = load i32, i32* %2
%28 = icmp slt i32 %27, %0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.6, i64 0, i64 0))
br label %39
31: ; preds = %26
%32 = icmp sgt i32 %27, %0
br i1 %32, label %33, label %35
33: ; preds = %31
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %39
35: ; preds = %31
%36 = icmp eq i32 %27, %0
br i1 %36, label %37, label %39
37: ; preds = %35
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %6)
br label %39
39: ; preds = %29, %35, %37, %33
%40 = load i32, i32* %2
%41 = icmp eq i32 %40, %0
br i1 %41, label %42, label %4
42: ; preds = %39
ret i32 %6
}