#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 */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int a = 1, b = 100;
  char response;
  printf("Pick a integer from 1 to 100. I will try to guess ");
  printf("it.\nRespond with a y if my guess is right and with");
  printf(" an l if it is lower and with a h if it is higher.\n");
  printf("Uh...is your number %d?\n", (a + b) / 2);
  while ((response = getchar()) != 'y') {
    switch (response) {
    case 'l':
      a = (a + b) / 2;
      printf("Well, then, is it %d?\n", (a + b) / 2);
      break;
    case 'h':
      b = (a + b) / 2;
      printf("Well, then, is it %d?\n", (a + b) / 2);
      break;
    default:
      printf("Sorry, I understand only y, h, or l.\n");
    }
    while (getchar() != '\n')
      continue;
  }
  printf("I knew I could do it!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x64,-0xc(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xf1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0xd(%rbp)
movsbl %al,%eax
cmp    $0x79,%eax
je     1259 <main+0x139>
movsbl -0xd(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x68,%eax
je     11f5 <main+0xd5>
jmp    11b0 <main+0x90>
mov    -0x14(%rbp),%eax
sub    $0x6c,%eax
jne    1229 <main+0x109>
jmp    11c1 <main+0xa1>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1237 <main+0x117>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1237 <main+0x117>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123c <main+0x11c>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1254 <main+0x134>
jmp    123c <main+0x11c>
jmp    1185 <main+0x65>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf3a(%rip),%rdi
call   1030 <puts@plt>
lea    0xefe(%rip),%rdi
mov    $0x32,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0x79,%al
je     123a <main+0x10a>
mov    $0x64,%r12d
mov    $0x1,%r13d
lea    0xee9(%rip),%r15
lea    0xf42(%rip),%r14
nopl   (%rax)
movsbl %al,%eax
cmp    $0x68,%eax
je     11e0 <main+0xb0>
cmp    $0x6c,%eax
jne    1210 <main+0xe0>
add    %r12d,%r13d
mov    %r13d,%ebx
shr    $0x1f,%ebx
add    %r13d,%ebx
sar    %ebx
lea    (%rbx,%r12,1),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%r13d
jmp    1220 <main+0xf0>
nopw   0x0(%rax,%rax,1)
add    %r13d,%r12d
mov    %r12d,%ebx
shr    $0x1f,%ebx
add    %r12d,%ebx
sar    %ebx
lea    (%rbx,%r13,1),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%r12d
jmp    1220 <main+0xf0>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    1220 <main+0xf0>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0x79,%al
jne    11a0 <main+0x70>
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [51 x i8] c"Pick a integer from 1 to 100. I will try to guess \00"
@.str.1 = [51 x i8] c"it.\0ARespond with a y if my guess is right and with\00"
@.str.2 = [52 x i8] c" an l if it is lower and with a h if it is higher.\0A\00"
@.str.3 = [25 x i8] c"Uh...is your number %d?\0A\00"
@.str.4 = [23 x i8] c"Well, then, is it %d?\0A\00"
@.str.5 = [38 x i8] c"Sorry, I understand only y, h, or l.\0A\00"
@.str.6 = [23 x i8] c"I knew I could do it!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
store i32 1, i32* %2
store i32 100, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = add nsw i32 %8, %9
%11 = sdiv i32 %10, 2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %48, %0
%14 = call signext i8 (...) @getchar()
store i8 %14, i8* %4
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 121
br i1 %16, label %17, label %49
17: ; preds = %13
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
switch i32 %19, label %40 [
i32 108, label %20
i32 104, label %30
]
20: ; preds = %17
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = add nsw i32 %21, %22
%24 = sdiv i32 %23, 2
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = add nsw i32 %25, %26
%28 = sdiv i32 %27, 2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %28)
br label %42
30: ; preds = %17
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = add nsw i32 %31, %32
%34 = sdiv i32 %33, 2
store i32 %34, i32* %3
%35 = load i32, i32* %2
%36 = load i32, i32* %3
%37 = add nsw i32 %35, %36
%38 = sdiv i32 %37, 2
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %38)
br label %42
40: ; preds = %17
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
br label %42
42: ; preds = %40, %30, %20
br label %43
43: ; preds = %47, %42
%44 = call signext i8 (...) @getchar()
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 10
br i1 %46, label %47, label %48
47: ; preds = %43
br label %43
48: ; preds = %43
br label %13
49: ; preds = %13
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [51 x i8] c"Pick a integer from 1 to 100. I will try to guess \00"
@.str.1 = [51 x i8] c"it.\0ARespond with a y if my guess is right and with\00"
@.str.3 = [25 x i8] c"Uh...is your number %d?\0A\00"
@.str.4 = [23 x i8] c"Well, then, is it %d?\0A\00"
@str = [51 x i8] c" an l if it is lower and with a h if it is higher.\00"
@str.7 = [22 x i8] c"I knew I could do it!\00"
@str.8 = [37 x i8] c"Sorry, I understand only y, h, or l.\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 50)
%5 = tail call signext i8 (...) @getchar()
%6 = icmp eq i8 %5, 121
br i1 %6, label %35, label %10
7: ; preds = %32
%8 = tail call signext i8 (...) @getchar()
%9 = icmp eq i8 %8, 121
br i1 %9, label %35, label %10
10: ; preds = %0, %7
%11 = phi i8 [ %8, %7 ], [ %5, %0 ]
%12 = phi i32 [ %31, %7 ], [ 1, %0 ]
%13 = phi i32 [ %30, %7 ], [ 100, %0 ]
%14 = sext i8 %11 to i32
switch i32 %14, label %27 [
i32 108, label %15
i32 104, label %21
]
15: ; preds = %10
%16 = add nsw i32 %12, %13
%17 = sdiv i32 %16, 2
%18 = add nsw i32 %17, %13
%19 = sdiv i32 %18, 2
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %19)
br label %29
21: ; preds = %10
%22 = add nsw i32 %12, %13
%23 = sdiv i32 %22, 2
%24 = add nsw i32 %23, %12
%25 = sdiv i32 %24, 2
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %25)
br label %29
27: ; preds = %10
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.8, i64 0, i64 0))
br label %29
29: ; preds = %27, %21, %15
%30 = phi i32 [ %13, %27 ], [ %23, %21 ], [ %13, %15 ]
%31 = phi i32 [ %12, %27 ], [ %12, %21 ], [ %17, %15 ]
br label %32
32: ; preds = %32, %29
%33 = tail call signext i8 (...) @getchar()
%34 = icmp eq i8 %33, 10
br i1 %34, label %7, label %32
35: ; preds = %7, %0
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
ret i32 0
}