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


x86 assembly (clang, -O0):
<play>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    117b <play+0x5b>
mov    -0xc(%rbp),%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b2 <play+0x92>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119a <play+0x7a>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a8 <play+0x88>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ad <play+0x8d>
jmp    1132 <play+0x12>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<play>:
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    118a <play+0x5a>
lea    0xea1(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
lea    0xea9(%rip),%r13
lea    0xe63(%rip),%r14
lea    0xe6a(%rip),%r15
lea    0x4(%rsp),%r12
jmp    11d5 <play+0xa5>
nopl   0x0(%rax,%rax,1)
call   1030 <puts@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
add    $0x1,%ebp
mov    0x4(%rsp),%eax
cmp    %ebx,%eax
je     1169 <play+0x39>
mov    %r13,%rdi
cmp    %ebx,%eax
jl     11b0 <play+0x80>
lea    0xe47(%rip),%rdi
jmp    11b0 <play+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 i32 @play(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 = %1, %25
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %4
%9 = add nsw i32 %8, 1
store i32 %9, i32* %4
%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)
br label %26
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
26: ; preds = %13
%27 = load i32, i32* %4
ret i32 %27
}

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 i32 @play(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 ], [ %19, %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 i32 %9
11: ; preds = %1, %11
%12 = phi i32 [ %20, %11 ], [ %6, %1 ]
%13 = phi i32 [ %19, %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 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%19 = add nuw nsw i32 %13, 1
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, %0
br i1 %21, label %8, label %11
}