#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_for(const int ans, const int low, const int high,
                          const int tries) {
  printf("guess the number using a for loop with %d tries\n", tries);
  int i;
  int guess;
  int won = 0;
  for (i = 0; i < tries; i++) {
    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;
      break;
    }
  }
  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_for>:
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,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1206 <guess_the_number_for+0xe6>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jge    119a <guess_the_number_for+0x7a>
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
setg   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11aa <guess_the_number_for+0x8a>
jmp    11db <guess_the_number_for+0xbb>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6c(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
jmp    117d <guess_the_number_for+0x5d>
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11f3 <guess_the_number_for+0xd3>
movl   $0x1,-0x1c(%rbp)
jmp    1206 <guess_the_number_for+0xe6>
jmp    11f8 <guess_the_number_for+0xd8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1153 <guess_the_number_for+0x33>
cmpl   $0x1,-0x1c(%rbp)
jne    1234 <guess_the_number_for+0x114>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1242 <guess_the_number_for+0x122>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guess_the_number_for>:
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,0x14(%rsp)
lea    0xeb0(%rip),%rdi
mov    %ecx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,0x10(%rsp)
test   %r14d,%r14d
jle    11d3 <guess_the_number_for+0xa3>
lea    0xec7(%rip),%r13
lea    0xec8(%rip),%r15
lea    0xc(%rsp),%r14
lea    0xeee(%rip),%r12
xor    %eax,%eax
nop
mov    %eax,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    %ebx,%eax
jge    11c0 <guess_the_number_for+0x90>
cmp    %ebp,%eax
jle    11c0 <guess_the_number_for+0x90>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    1190 <guess_the_number_for+0x60>
nopl   0x0(%rax,%rax,1)
cmp    0x14(%rsp),%eax
je     11e1 <guess_the_number_for+0xb1>
mov    0x8(%rsp),%eax
add    $0x1,%eax
cmp    0x10(%rsp),%eax
jne    1180 <guess_the_number_for+0x50>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
jmp    11ff <guess_the_number_for+0xcf>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe49(%rip),%rdi
mov    0x8(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"guess the number using a for 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_for(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 ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 0, i32* %11
store i32 0, i32* %9
br label %14
14: ; preds = %41, %4
%15 = load i32, i32* %9
%16 = load i32, i32* %8
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %44
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* 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* %10)
br label %21
21: ; preds = %31, %18
%22 = load i32, i32* %10
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32, i32* %10
%27 = load i32, i32* %7
%28 = icmp sgt i32 %26, %27
br label %29
29: ; preds = %25, %21
%30 = phi i1 [ false, %21 ], [ %28, %25 ]
br i1 %30, label %31, label %35
31: ; preds = %29
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %10)
br label %21
35: ; preds = %29
%36 = load i32, i32* %10
%37 = load i32, i32* %5
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 1, i32* %11
br label %44
40: ; preds = %35
br label %41
41: ; preds = %40
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %14
44: ; preds = %39, %14
%45 = load i32, i32* %11
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%49 = load i32, i32* %9
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %49)
br label %53
51: ; preds = %44
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %53
53: ; preds = %51, %47
ret void
}

LLVM IR (-O2):
@.str = [49 x i8] c"guess the number using a for 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_for(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 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 %34
9: ; preds = %4, %28
%10 = phi i32 [ %29, %28 ], [ 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
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = add nuw nsw i32 %10, 1
%30 = icmp eq i32 %29, %3
br i1 %30, label %34, label %9
31: ; preds = %25
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %10)
br label %36
34: ; preds = %28, %4
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
ret void
}