#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 *);
void read_guesses(int secret_number) {
  int guess, num_guesses = 0;
  for (;;) {
    num_guesses++;
    printf("Enter guess: ");
    scanf("%d", &guess);
    if (guess == secret_number) {
      printf("You won in %d guesses!\n\n", num_guesses);
      return;
    } else if (guess < secret_number)
      printf("Too low; try again.\n");
    else
      printf("Too high; try again.\n");
  }
}


x86 assembly (clang, -O0):
<read_guesses>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebe(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    117c <read_guesses+0x5c>
mov    -0xc(%rbp),%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119b <read_guesses+0x7b>
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a9 <read_guesses+0x89>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ae <read_guesses+0x8e>
jmp    1132 <read_guesses+0x12>

x86 assembly (clang, -O2):
<read_guesses>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xebc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebc(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
mov    $0x1,%ebp
cmp    %ebx,%eax
jne    1188 <read_guesses+0x58>
lea    0xea1(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
lea    0xeab(%rip),%r13
lea    0xe65(%rip),%r14
lea    0xe6c(%rip),%r15
lea    0x4(%rsp),%r12
jmp    11d5 <read_guesses+0xa5>
nopl   0x0(%rax)
call   1030 <puts@plt>
add    $0x1,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    %ebx,%eax
je     1169 <read_guesses+0x39>
mov    %r13,%rdi
cmp    %ebx,%eax
jl     11b0 <read_guesses+0x80>
lea    0xe47(%rip),%rdi
jmp    11b0 <read_guesses+0x80>

LLVM IR (-O0):
@.str = [14 x i8] c"Enter guess: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"You won in %d guesses!\0A\0A\00"
@.str.3 = [21 x i8] c"Too low; try again.\0A\00"
@.str.4 = [22 x i8] c"Too high; try again.\0A\00"
define void @read_guesses(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %5
5: ; preds = %25, %1
%6 = load i32, i32* %4
%7 = add nsw i32 %6, 1
store i32 %7, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %5
%14 = load i32, i32* %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %14)
ret void
16: ; preds = %5
%17 = load i32, i32* %3
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %24
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %24
24: ; preds = %22, %20
br label %25
25: ; preds = %24
br label %5
}

LLVM IR (-O2):
@.str = [14 x i8] c"Enter guess: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"You won in %d guesses!\0A\0A\00"
@str = [21 x i8] c"Too high; try again.\00"
@str.5 = [20 x i8] c"Too low; try again.\00"
define void @read_guesses(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, %0
br i1 %7, label %8, label %11
8: ; preds = %11, %1
%9 = phi i32 [ 1, %1 ], [ %17, %11 ]
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %9)
ret void
11: ; preds = %1, %11
%12 = phi i32 [ %20, %11 ], [ %6, %1 ]
%13 = phi i32 [ %17, %11 ], [ 1, %1 ]
%14 = icmp slt i32 %12, %0
%15 = select i1 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0)
%16 = call i32 @puts(i8* dereferenceable(1) %15)
%17 = add nuw nsw i32 %13, 1
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, %0
br i1 %21, label %8, label %11
}