#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 *, char *);
int ask_user(char *msg) {
  char rs;
  printf("%s\n", msg);
  while (rs != 'y' && rs != 'n') {
    rs = getchar();
  }
  if (rs == 'y')
    return 1;
  return 2;
}


x86 assembly (clang, -O0):
<ask_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x79,%ecx
mov    %al,-0x12(%rbp)
je     115b <ask_user+0x3b>
movsbl -0x11(%rbp),%eax
cmp    $0x6e,%eax
setne  %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    116b <ask_user+0x4b>
jmp    117a <ask_user+0x5a>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x11(%rbp)
jmp    113c <ask_user+0x1c>
movsbl -0x11(%rbp),%eax
cmp    $0x79,%eax
jne    1193 <ask_user+0x73>
movl   $0x1,-0x4(%rbp)
jmp    119a <ask_user+0x7a>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ask_user>:
push   %rax
mov    %rdi,%rsi
lea    0xed5(%rip),%rdi
call   1030 <printf@plt>
cmp    $0x6e,%al
je     114f <ask_user+0x2f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x79,%al
je     1156 <ask_user+0x36>
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0x6e,%al
jne    1140 <ask_user+0x20>
mov    $0x2,%eax
pop    %rcx
ret
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define i32 @ask_user(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %7
7: ; preds = %17, %1
%8 = load i8, i8* %4
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 121
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i8, i8* %4
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 110
br label %15
15: ; preds = %11, %7
%16 = phi i1 [ false, %7 ], [ %14, %11 ]
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = call signext i8 (...) @getchar()
store i8 %18, i8* %4
br label %7
19: ; preds = %15
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 121
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 1, i32* %2
br label %25
24: ; preds = %19
store i32 2, i32* %2
br label %25
25: ; preds = %24, %23
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define i32 @ask_user(i8* %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %3
3: ; preds = %5, %1
%4 = phi i8 [ undef, %1 ], [ %6, %5 ]
switch i8 %4, label %5 [
i8 121, label %7
i8 110, label %8
]
5: ; preds = %3
%6 = tail call signext i8 (...) @getchar()
br label %3
7: ; preds = %3
br label %8
8: ; preds = %3, %7
%9 = phi i32 [ 1, %7 ], [ 2, %3 ]
ret i32 %9
}