#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 guess_the_number_while(const int ans, const int low, const int high,
                            const int tries) {
  printf("guess the number using a while loop with %d tries\n", tries);
  int i = 0;
  int guess;
  int won = 0;
  while (!won && i < tries) {
    printf("Guess? ");
    scanf(" %d", &guess);
    while (guess < low && guess > high) {
      printf("OUT OF BOUNDS\n");
      printf("Guess? ");
      scanf(" %d", &guess);
    }
    if (guess == ans) {
      won = 1;
    }
    i++;
  }
  if (won == 1) {
    printf("You guessed correctly!\n");
    printf("Took %d tries.\n", i);
  } else {
    printf("WRONG!\n");
  }
}


x86 assembly (clang, -O0):
<guess_the_number_while>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jne    116e <guess_the_number_while+0x4e>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    117e <guess_the_number_while+0x5e>
jmp    121b <guess_the_number_while+0xfb>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea8(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8(%rbp),%ecx
mov    %al,-0x1e(%rbp)
jge    11b9 <guess_the_number_while+0x99>
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
setg   %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    11c9 <guess_the_number_while+0xa9>
jmp    11fa <guess_the_number_while+0xda>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4f(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
jmp    119c <guess_the_number_while+0x7c>
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    120d <guess_the_number_while+0xed>
movl   $0x1,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1153 <guess_the_number_while+0x33>
cmpl   $0x1,-0x1c(%rbp)
jne    1249 <guess_the_number_while+0x129>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1257 <guess_the_number_while+0x137>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guess_the_number_while>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,0x8(%rsp)
lea    0xeb0(%rip),%rdi
mov    %ecx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,0x10(%rsp)
test   %r14d,%r14d
jle    1209 <guess_the_number_while+0xd9>
lea    0xec5(%rip),%r13
lea    0xec6(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xeec(%rip),%r12
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ecx,0x14(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    %ebx,%eax
jge    11d0 <guess_the_number_while+0xa0>
cmp    %ebp,%eax
jle    11d0 <guess_the_number_while+0xa0>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    11a0 <guess_the_number_while+0x70>
nopl   0x0(%rax,%rax,1)
mov    0x14(%rsp),%ecx
add    $0x1,%ecx
cmp    0x8(%rsp),%eax
je     11e3 <guess_the_number_while+0xb3>
cmp    0x10(%rsp),%ecx
jl     1190 <guess_the_number_while+0x60>
cmp    0x8(%rsp),%eax
jne    1209 <guess_the_number_while+0xd9>
lea    0xe66(%rip),%rdi
mov    %ecx,%ebx
call   1030 <puts@plt>
lea    0xe41(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1215 <guess_the_number_while+0xe5>
lea    0xe3f(%rip),%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"guess the number using a while loop with %d tries\0A\00"
@.str.1 = [8 x i8] c"Guess? \00"
@.str.2 = [4 x i8] c" %d\00"
@.str.3 = [15 x i8] c"OUT OF BOUNDS\0A\00"
@.str.4 = [24 x i8] c"You guessed correctly!\0A\00"
@.str.5 = [16 x i8] c"Took %d tries.\0A\00"
@.str.6 = [8 x i8] c"WRONG!\0A\00"
define void @guess_the_number_while(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 0, i32* %9
store i32 0, i32* %11
br label %14
14: ; preds = %45, %4
%15 = load i32, i32* %11
%16 = icmp ne i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = load i32, i32* %9
%19 = load i32, i32* %8
%20 = icmp slt i32 %18, %19
br label %21
21: ; preds = %17, %14
%22 = phi i1 [ false, %14 ], [ %20, %17 ]
br i1 %22, label %23, label %48
23: ; preds = %21
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %10)
br label %26
26: ; preds = %36, %23
%27 = load i32, i32* %10
%28 = load i32, i32* %6
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* %10
%32 = load i32, i32* %7
%33 = icmp sgt i32 %31, %32
br label %34
34: ; preds = %30, %26
%35 = phi i1 [ false, %26 ], [ %33, %30 ]
br i1 %35, label %36, label %40
36: ; preds = %34
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %10)
br label %26
40: ; preds = %34
%41 = load i32, i32* %10
%42 = load i32, i32* %5
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %45
44: ; preds = %40
store i32 1, i32* %11
br label %45
45: ; preds = %44, %40
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %14
48: ; preds = %21
%49 = load i32, i32* %11
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %55
51: ; preds = %48
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%53 = load i32, i32* %9
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %53)
br label %57
55: ; preds = %48
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %57
57: ; preds = %55, %51
ret void
}

LLVM IR (-O2):
@.str = [51 x i8] c"guess the number using a while loop with %d tries\0A\00"
@.str.1 = [8 x i8] c"Guess? \00"
@.str.2 = [4 x i8] c" %d\00"
@.str.5 = [16 x i8] c"Took %d tries.\0A\00"
@str = [7 x i8] c"WRONG!\00"
@str.7 = [23 x i8] c"You guessed correctly!\00"
@str.8 = [14 x i8] c"OUT OF BOUNDS\00"
define void @guess_the_number_while(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %3)
%7 = bitcast i32* %5 to i8*
%8 = icmp sgt i32 %3, 0
br i1 %8, label %9, label %36
9: ; preds = %4, %25
%10 = phi i32 [ %28, %25 ], [ 0, %4 ]
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, %1
%15 = icmp sgt i32 %13, %2
%16 = and i1 %14, %15
br i1 %16, label %17, label %25
17: ; preds = %9, %17
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.8, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, %1
%23 = icmp sgt i32 %21, %2
%24 = and i1 %22, %23
br i1 %24, label %17, label %25
25: ; preds = %17, %9
%26 = phi i32 [ %13, %9 ], [ %21, %17 ]
%27 = icmp eq i32 %26, %0
%28 = add nuw nsw i32 %10, 1
%29 = xor i1 %27, true
%30 = icmp slt i32 %28, %3
%31 = select i1 %29, i1 %30, i1 false
br i1 %31, label %9, label %32
32: ; preds = %25
br i1 %27, label %33, label %36
33: ; preds = %32
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %28)
br label %38
36: ; preds = %4, %32
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
ret void
}