#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_dowhile(const int ans, const int low, const int high,
                              const int tries) {
  printf("guess the number using a do-while loop with %d tries\n", tries);
  int i = 0;
  int guess;
  int won = 0;
  do {
    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++;
  } while (!won && i < tries);
  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_dowhile>:
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)
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed6(%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    118e <guess_the_number_dowhile+0x6e>
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
setg   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    119e <guess_the_number_dowhile+0x7e>
jmp    11cf <guess_the_number_dowhile+0xaf>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7d(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
jmp    1171 <guess_the_number_dowhile+0x51>
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11e2 <guess_the_number_dowhile+0xc2>
movl   $0x1,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1e(%rbp)
jne    1206 <guess_the_number_dowhile+0xe6>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
setl   %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    1153 <guess_the_number_dowhile+0x33>
cmpl   $0x1,-0x1c(%rbp)
jne    123f <guess_the_number_dowhile+0x11f>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <guess_the_number_dowhile+0x12d>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guess_the_number_dowhile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,0x8(%rsp)
lea    0xeb3(%rip),%rdi
mov    %ecx,0x10(%rsp)
mov    %ecx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed5(%rip),%r13
lea    0xed6(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xefc(%rip),%r12
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
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    11c0 <guess_the_number_dowhile+0x90>
cmp    %ebp,%eax
jle    11c0 <guess_the_number_dowhile+0x90>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    1190 <guess_the_number_dowhile+0x60>
nopl   0x0(%rax,%rax,1)
mov    0x14(%rsp),%ecx
add    $0x1,%ecx
cmp    0x8(%rsp),%eax
je     11d3 <guess_the_number_dowhile+0xa3>
cmp    0x10(%rsp),%ecx
jl     1180 <guess_the_number_dowhile+0x50>
cmp    0x8(%rsp),%eax
jne    11f9 <guess_the_number_dowhile+0xc9>
lea    0xe79(%rip),%rdi
mov    %ecx,%ebx
call   1030 <puts@plt>
lea    0xe54(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1205 <guess_the_number_dowhile+0xd5>
lea    0xe52(%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 = [54 x i8] c"guess the number using a do-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_dowhile(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 ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 0, i32* %9
store i32 0, i32* %11
br label %14
14: ; preds = %46, %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %10)
br label %17
17: ; preds = %27, %14
%18 = load i32, i32* %10
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* %10
%23 = load i32, i32* %7
%24 = icmp sgt i32 %22, %23
br label %25
25: ; preds = %21, %17
%26 = phi i1 [ false, %17 ], [ %24, %21 ]
br i1 %26, label %27, label %31
27: ; preds = %25
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %10)
br label %17
31: ; preds = %25
%32 = load i32, i32* %10
%33 = load i32, i32* %5
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 1, i32* %11
br label %36
36: ; preds = %35, %31
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %39
39: ; preds = %36
%40 = load i32, i32* %11
%41 = icmp ne i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %39
%43 = load i32, i32* %9
%44 = load i32, i32* %8
%45 = icmp slt i32 %43, %44
br label %46
46: ; preds = %42, %39
%47 = phi i1 [ false, %39 ], [ %45, %42 ]
br i1 %47, label %14, label %48
48: ; preds = %46
%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 = [54 x i8] c"guess the number using a do-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_dowhile(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %3)
%7 = bitcast i32* %5 to i8*
br label %8
8: ; preds = %24, %4
%9 = phi i32 [ 0, %4 ], [ %27, %24 ]
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, %1
%14 = icmp sgt i32 %12, %2
%15 = and i1 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %8, %16
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.8, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, %1
%22 = icmp sgt i32 %20, %2
%23 = and i1 %21, %22
br i1 %23, label %16, label %24
24: ; preds = %16, %8
%25 = phi i32 [ %12, %8 ], [ %20, %16 ]
%26 = icmp eq i32 %25, %0
%27 = add nuw nsw i32 %9, 1
%28 = xor i1 %26, true
%29 = icmp slt i32 %27, %3
%30 = select i1 %28, i1 %29, i1 false
br i1 %30, label %8, label %31
31: ; preds = %24
br i1 %26, label %32, label %35
32: ; preds = %31
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %27)
br label %37
35: ; preds = %31
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
ret void
}