#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(int argc, const char *argv[]) {
  int guess = 1;
  char response;
  printf("Pick an integer from 1 to 100. I will try to guess  ");
  printf("it.\n Respond 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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xf0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x15(%rbp)
movsbl %al,%eax
cmp    $0x79,%eax
je     11e7 <main+0xc7>
movsbl -0x15(%rbp),%eax
cmp    $0x6e,%eax
jne    11b7 <main+0x97>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
lea    0xeee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c5 <main+0xa5>
lea    0xef2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ca <main+0xaa>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11e2 <main+0xc2>
jmp    11ca <main+0xaa>
jmp    1178 <main+0x58>
lea    0xee4(%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   %rbx
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeeb(%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 = [53 x i8] c"Pick an integer from 1 to 100. I will try to guess \00"
@.str.1 = [52 x i8] c"it.\0A Respond 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(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* %6
%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 = %33, %2
%14 = call signext i8 (...) @getchar()
store i8 %14, i8* %7
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 121
br i1 %16, label %17, label %34
17: ; preds = %13
%18 = load i8, i8* %7
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 110
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %23)
br label %27
25: ; preds = %17
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
br label %28
28: ; preds = %32, %27
%29 = call signext i8 (...) @getchar()
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 10
br i1 %31, label %32, label %33
32: ; preds = %28
br label %28
33: ; preds = %28
br label %13
34: ; preds = %13
%35 = 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 = [53 x i8] c"Pick an integer from 1 to 100. I will try to guess \00"
@.str.1 = [52 x i8] c"it.\0A Respond 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(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%6 = 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 %7
7: ; preds = %17, %2
%8 = phi i32 [ 1, %2 ], [ %16, %17 ]
%9 = tail call signext i8 (...) @getchar()
switch i8 %9, label %13 [
i8 121, label %20
i8 110, label %10
]
10: ; preds = %7
%11 = add nsw i32 %8, 1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %11)
br label %15
13: ; preds = %7
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.8, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = phi i32 [ %11, %10 ], [ %8, %13 ]
br label %17
17: ; preds = %17, %15
%18 = tail call signext i8 (...) @getchar()
%19 = icmp eq i8 %18, 10
br i1 %19, label %7, label %17
20: ; preds = %7
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
ret i32 0
}