#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int guess = -1;
  int secret = 7;
  int count_of_guesses = 0;
  printf("Try to pick a number from 1 to 10 \n");
  while (guess != secret) {
    count_of_guesses++;
    printf("Enter a guess \n");
    scanf("%i", &guess);
    printf("\nYou entered %i \n", guess);
  }
  printf("You got it after %i tries \n", count_of_guesses);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movl   $0x7,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     119b <main+0x7b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1152 <main+0x32>
mov    -0x10(%rbp),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xee5(%rip),%rdi
call   1030 <puts@plt>
lea    0xefc(%rip),%r14
lea    0xea1(%rip),%r15
lea    0xc(%rsp),%r12
lea    0xe98(%rip),%r13
xor    %ebx,%ebx
nopl   (%rax)
add    $0x1,%ebx
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x7,0xc(%rsp)
jne    1170 <main+0x40>
lea    0xe73(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Try to pick a number from 1 to 10 \0A\00"
@.str.1 = [16 x i8] c"Enter a guess \0A\00"
@.str.2 = [3 x i8] c"%i\00"
@.str.3 = [18 x i8] c"\0AYou entered %i \0A\00"
@.str.4 = [28 x i8] c"You got it after %i tries \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %2
store i32 7, i32* %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %10, %0
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 1
store i32 %12, i32* %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%15 = load i32, i32* %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %15)
br label %6
17: ; preds = %6
%18 = load i32, i32* %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %18)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%i\00"
@.str.3 = [18 x i8] c"\0AYou entered %i \0A\00"
@.str.4 = [28 x i8] c"You got it after %i tries \0A\00"
@str = [35 x i8] c"Try to pick a number from 1 to 10 \00"
@str.5 = [15 x i8] c"Enter a guess \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ %6, %4 ], [ 0, %0 ]
%6 = add nuw nsw i32 %5, 1
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.5, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %1
%12 = icmp eq i32 %11, 7
br i1 %12, label %13, label %4
13: ; preds = %4
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %6)
ret i32 0
}