#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 guess = 1;
  char response;
  printf("Pick an integer from 1 to 100. I will try to guess ");
  printf("it. \nResponse with a y if my guess is right and with");
  printf("\nan n if it is wrong.\n");
  printf("Uh...is your number %d?\n", guess);
  while ((response = getchar()) != 'y') {
    if (response == 'n') {
      printf("Well, then, is it %d?\n", ++guess);
    } else {
      printf("Sorry, I understand only y or n.\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    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xf16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
cmp    $0x79,%eax
je     11e0 <main+0xc0>
movsbl -0x9(%rbp),%eax
cmp    $0x6e,%eax
jne    11b0 <main+0x90>
mov    -0x8(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x8(%rbp)
lea    0xef5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11be <main+0x9e>
lea    0xef9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c3 <main+0xa3>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11db <main+0xbb>
jmp    11c3 <main+0xa3>
jmp    1171 <main+0x51>
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeea(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf41(%rip),%rdi
call   1030 <puts@plt>
lea    0xf05(%rip),%rdi
mov    $0x1,%ebx
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf06(%rip),%r14
lea    0xf42(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0x6e,%al
je     11b0 <main+0x80>
cmp    $0x79,%al
je     11cd <main+0x9d>
mov    %r15,%rdi
call   1030 <puts@plt>
jmp    11c0 <main+0x90>
nopl   0x0(%rax)
add    $0x1,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
nop
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    11c0 <main+0x90>
jmp    1190 <main+0x60>
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [52 x i8] c"Pick an integer from 1 to 100. I will try to guess \00"
@.str.1 = [53 x i8] c"it. \0AResponse with a y if my guess is right and with\00"
@.str.2 = [23 x i8] c"\0Aan n if it is wrong.\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 = [34 x i8] c"Sorry, I understand only y or n.\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 i8
store i32 0, i32* %1
store i32 1, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32, i32* %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %29, %0
%10 = call signext i8 (...) @getchar()
store i8 %10, i8* %3
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 121
br i1 %12, label %13, label %30
13: ; preds = %9
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 110
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %19)
br label %23
21: ; preds = %13
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
br label %24
24: ; preds = %28, %23
%25 = call signext i8 (...) @getchar()
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 10
br i1 %27, label %28, label %29
28: ; preds = %24
br label %24
29: ; preds = %24
br label %9
30: ; preds = %9
%31 = 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 = [52 x i8] c"Pick an integer from 1 to 100. I will try to guess \00"
@.str.1 = [53 x i8] c"it. \0AResponse 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 = [22 x i8] c"\0Aan n if it is wrong.\00"
@str.7 = [22 x i8] c"I knew I could do it!\00"
@str.8 = [33 x i8] c"Sorry, I understand only y or n.\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 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 1)
br label %5
5: ; preds = %15, %0
%6 = phi i32 [ 1, %0 ], [ %14, %15 ]
%7 = tail call signext i8 (...) @getchar()
switch i8 %7, label %11 [
i8 121, label %18
i8 110, label %8
]
8: ; preds = %5
%9 = add nsw i32 %6, 1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %9)
br label %13
11: ; preds = %5
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.8, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
%14 = phi i32 [ %9, %8 ], [ %6, %11 ]
br label %15
15: ; preds = %15, %13
%16 = tail call signext i8 (...) @getchar()
%17 = icmp eq i8 %16, 10
br i1 %17, label %5, label %15
18: ; preds = %5
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
ret i32 0
}