#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 rand();
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(void) {
  printf("Enter a number for the program to guess: ");
  int num;
  scanf(" %d", &num);
  srand((unsigned)time(NULL));
  int low = 1;
  int high = 100;
  for (;;) {
    int guess;
    do {
      guess = (rand() % 99) + 1;
    } while (guess < low || guess > high);
    printf("The program guessed: %d\n", guess);
    if (guess == num) {
      break;
    }
    printf("Response:\n");
    printf("h = Too high\n");
    printf("l = Too low\n");
    char c;
    scanf(" %c", &c);
    switch (c) {
    case 'h':
      high = guess;
      break;
    case 'l':
      low = guess;
    }
  }
  printf("The program guessed your number!");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb6(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x1,-0xc(%rbp)
movl   $0x64,-0x10(%rbp)
jmp    11a2 <main+0x52>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x63,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
mov    $0x1,%al
cmp    -0xc(%rbp),%ecx
mov    %al,-0x16(%rbp)
jl     11d4 <main+0x84>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
setg   %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
test   $0x1,%al
jne    11a2 <main+0x52>
mov    -0x14(%rbp),%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    1201 <main+0xb1>
jmp    127f <main+0x12f>
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x1d(%rbp)
call   1030 <printf@plt>
mov    -0x1d(%rbp),%al
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1d(%rbp),%al
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1d(%rbp),%al
lea    0xe33(%rip),%rdi
lea    -0x15(%rbp),%rsi
call   1060 <scanf@plt>
movsbl -0x15(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x68,%eax
je     1269 <main+0x119>
jmp    1258 <main+0x108>
mov    -0x1c(%rbp),%eax
sub    $0x6c,%eax
je     1274 <main+0x124>
jmp    127a <main+0x12a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    127a <main+0x12a>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    119d <main+0x4d>
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeaa(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x64,%r12d
mov    $0x1,%r15d
lea    0xe81(%rip),%r13
lea    0xe93(%rip),%rbx
lea    0x3(%rsp),%rbp
jmp    11d0 <main+0x70>
mov    %r14d,%r15d
mov    %r12d,%r14d
mov    %r14d,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1080 <rand@plt>
movslq %eax,%rcx
imul   $0xffffffffa57eb503,%rcx,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0x6,%eax
add    %edx,%eax
imul   $0x63,%eax,%edx
mov    %ecx,%eax
sub    %edx,%eax
neg    %edx
lea    (%rcx,%rdx,1),%r14d
add    $0x1,%r14d
cmp    %r15d,%r14d
jl     11d0 <main+0x70>
cmp    %r12d,%eax
jge    11d0 <main+0x70>
mov    %r13,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    0x4(%rsp),%r14d
je     126d <main+0x10d>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
lea    0xe43(%rip),%rdi
call   1030 <puts@plt>
lea    0xe44(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
movsbl 0x3(%rsp),%eax
cmp    $0x6c,%eax
je     11bb <main+0x5b>
cmp    $0x68,%eax
je     11c1 <main+0x61>
jmp    11be <main+0x5e>
lea    0xdd7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Enter a number for the program to guess: \00"
@.str.1 = [4 x i8] c" %d\00"
@.str.2 = [25 x i8] c"The program guessed: %d\0A\00"
@.str.3 = [11 x i8] c"Response:\0A\00"
@.str.4 = [14 x i8] c"h = Too high\0A\00"
@.str.5 = [13 x i8] c"l = Too low\0A\00"
@.str.6 = [4 x i8] c" %c\00"
@.str.7 = [33 x i8] c"The program guessed your number!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = call i64 @time(i32* null)
%10 = trunc i64 %9 to i32
%11 = call i32 @srand(i32 %10)
store i32 1, i32* %3
store i32 100, i32* %4
br label %12
12: ; preds = %45, %0
br label %13
13: ; preds = %25, %12
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 99
%16 = add nsw i32 %15, 1
store i32 %16, i32* %5
br label %17
17: ; preds = %13
%18 = load i32, i32* %5
%19 = load i32, i32* %3
%20 = icmp slt i32 %18, %19
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = icmp sgt i32 %22, %23
br label %25
25: ; preds = %21, %17
%26 = phi i1 [ true, %17 ], [ %24, %21 ]
br i1 %26, label %13, label %27
27: ; preds = %25
%28 = load i32, i32* %5
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %5
%31 = load i32, i32* %2
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %27
br label %46
34: ; preds = %27
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%38 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%39 = load i8, i8* %6
%40 = sext i8 %39 to i32
switch i32 %40, label %45 [
i32 104, label %41
i32 108, label %43
]
41: ; preds = %34
%42 = load i32, i32* %5
store i32 %42, i32* %4
br label %45
43: ; preds = %34
%44 = load i32, i32* %5
store i32 %44, i32* %3
br label %45
45: ; preds = %43, %34, %41
br label %12
46: ; preds = %33
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [42 x i8] c"Enter a number for the program to guess: \00"
@.str.1 = [4 x i8] c" %d\00"
@.str.2 = [25 x i8] c"The program guessed: %d\0A\00"
@.str.6 = [4 x i8] c" %c\00"
@.str.7 = [33 x i8] c"The program guessed your number!\00"
@str = [10 x i8] c"Response:\00"
@str.8 = [13 x i8] c"h = Too high\00"
@str.9 = [12 x i8] c"l = Too low\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%4 = bitcast i32* %1 to i8*
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = call i64 @time(i32* null)
%7 = trunc i64 %6 to i32
%8 = call i32 @srand(i32 %7)
br label %9
9: ; preds = %32, %0
%10 = phi i32 [ 1, %0 ], [ %33, %32 ]
%11 = phi i32 [ 100, %0 ], [ %34, %32 ]
br label %12
12: ; preds = %12, %9
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 99
%15 = add nsw i32 %14, 1
%16 = icmp slt i32 %15, %10
%17 = icmp sge i32 %14, %11
%18 = select i1 %16, i1 true, i1 %17
br i1 %18, label %12, label %19
19: ; preds = %12
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%21 = load i32, i32* %1
%22 = icmp eq i32 %15, %21
br i1 %22, label %35, label %23
23: ; preds = %19
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.8, i64 0, i64 0))
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0))
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %2)
%28 = load i8, i8* %2
%29 = sext i8 %28 to i32
switch i32 %29, label %32 [
i32 104, label %30
i32 108, label %31
]
30: ; preds = %23
br label %32
31: ; preds = %23
br label %32
32: ; preds = %30, %23, %31
%33 = phi i32 [ %10, %23 ], [ %15, %31 ], [ %10, %30 ]
%34 = phi i32 [ %11, %23 ], [ %11, %31 ], [ %15, %30 ]
br label %9
35: ; preds = %19
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}