#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 read(int, char *, int);
int /*<<< orphan*/ uiPrintf(char const *);
int cliConfirm(const char *msg) {
  char ch, buf[2];
  uiPrintf(msg);
  uiPrintf(" (y or n)");
  for (;;) {
    if (read(1, buf, 1) != (-1)) {
      ch = *buf;
      if (ch == 'y' || ch == 'Y') {
        uiPrintf("\n");
        return 1;
      } else if (ch == 'n' || ch == 'N') {
        uiPrintf("\n");
        return 0;
      } else if (ch == '\b')
        uiPrintf(" \b");
      else
        uiPrintf("\b \b");
    } else {
      uiPrintf("read error!\n");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<cliConfirm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <uiPrintf@plt>
lea    0xec4(%rip),%rdi
call   1040 <uiPrintf@plt>
lea    -0x13(%rbp),%rsi
mov    $0x1,%edx
mov    %edx,%edi
call   1030 <read@plt>
cmp    $0xffffffff,%eax
je     11fd <cliConfirm+0xdd>
mov    -0x13(%rbp),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x79,%eax
je     117a <cliConfirm+0x5a>
movsbl -0x11(%rbp),%eax
cmp    $0x59,%eax
jne    1192 <cliConfirm+0x72>
lea    0xe98(%rip),%rdi
call   1040 <uiPrintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121a <cliConfirm+0xfa>
movsbl -0x11(%rbp),%eax
cmp    $0x6e,%eax
je     11ac <cliConfirm+0x8c>
movsbl -0x11(%rbp),%eax
cmp    $0x4e,%eax
jne    11c4 <cliConfirm+0xa4>
lea    0xe66(%rip),%rdi
call   1040 <uiPrintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121a <cliConfirm+0xfa>
movsbl -0x11(%rbp),%eax
cmp    $0x8,%eax
jne    11e2 <cliConfirm+0xc2>
lea    0xe33(%rip),%rdi
call   1040 <uiPrintf@plt>
jmp    11ee <cliConfirm+0xce>
lea    0xe21(%rip),%rdi
call   1040 <uiPrintf@plt>
jmp    11f3 <cliConfirm+0xd3>
jmp    11f8 <cliConfirm+0xd8>
jmp    120e <cliConfirm+0xee>
lea    0xe0a(%rip),%rdi
call   1040 <uiPrintf@plt>
jmp    1213 <cliConfirm+0xf3>
jmp    1141 <cliConfirm+0x21>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cliConfirm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
call   1040 <uiPrintf@plt>
lea    0xec9(%rip),%rdi
call   1040 <uiPrintf@plt>
lea    0x6(%rsp),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <read@plt>
xor    %r14d,%r14d
lea    0xeb4(%rip),%r15
cmp    $0xffffffff,%eax
je     11bc <cliConfirm+0x9c>
lea    0xeb3(%rip),%r12
lea    0xe9e(%rip),%rbx
lea    0xe96(%rip),%r13
lea    0x6(%rsp),%rbp
jmp    119c <cliConfirm+0x7c>
nopl   0x0(%rax,%rax,1)
call   1040 <uiPrintf@plt>
mov    $0x1,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0xffffffff,%eax
je     11bc <cliConfirm+0x9c>
movzbl 0x6(%rsp),%eax
mov    %eax,%ecx
and    $0xdf,%cl
cmp    $0x4e,%cl
je     11c7 <cliConfirm+0xa7>
cmp    $0x59,%cl
je     11c1 <cliConfirm+0xa1>
mov    %rbx,%rdi
cmp    $0x8,%al
je     1180 <cliConfirm+0x60>
mov    %r13,%rdi
jmp    1180 <cliConfirm+0x60>
mov    %r15,%r12
jmp    11c7 <cliConfirm+0xa7>
mov    $0x1,%r14d
mov    %r12,%rdi
call   1040 <uiPrintf@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c" (y or n)\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [3 x i8] c" \08\00"
@.str.3 = [4 x i8] c"\08 \08\00"
@.str.4 = [13 x i8] c"read error!\0A\00"
define i32 @cliConfirm(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca [2 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @uiPrintf(i8* %6)
%8 = call i32 @uiPrintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %48, %1
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%11 = call i32 @read(i32 1, i8* %10, i32 1)
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %46
13: ; preds = %9
%14 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%15 = load i8, i8* %14
store i8 %15, i8* %4
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 121
br i1 %18, label %23, label %19
19: ; preds = %13
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 89
br i1 %22, label %23, label %25
23: ; preds = %19, %13
%24 = call i32 @uiPrintf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %50
25: ; preds = %19
%26 = load i8, i8* %4
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 110
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = load i8, i8* %4
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 78
br i1 %32, label %33, label %35
33: ; preds = %29, %25
%34 = call i32 @uiPrintf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %50
35: ; preds = %29
%36 = load i8, i8* %4
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 8
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @uiPrintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %43
41: ; preds = %35
%42 = call i32 @uiPrintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %39
br label %44
44: ; preds = %43
br label %45
45: ; preds = %44
br label %48
46: ; preds = %9
%47 = call i32 @uiPrintf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %49
48: ; preds = %45
br label %9
49: ; preds = %46
store i32 0, i32* %2
br label %50
50: ; preds = %49, %33, %23
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
@.str = [10 x i8] c" (y or n)\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [3 x i8] c" \08\00"
@.str.3 = [4 x i8] c"\08 \08\00"
@.str.4 = [13 x i8] c"read error!\0A\00"
define i32 @cliConfirm(i8* %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @uiPrintf(i8* %0)
%5 = tail call i32 @uiPrintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @read(i32 1, i8* %3, i32 1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %18, label %8
8: ; preds = %1, %11
%9 = load i8, i8* %3
%10 = and i8 %9, -33
switch i8 %10, label %11 [
i8 89, label %18
i8 78, label %17
]
11: ; preds = %8
%12 = icmp eq i8 %9, 8
%13 = select i1 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0)
%14 = tail call i32 @uiPrintf(i8* %13)
%15 = call i32 @read(i32 1, i8* %3, i32 1)
%16 = icmp eq i32 %15, -1
br i1 %16, label %18, label %8
17: ; preds = %8
br label %18
18: ; preds = %11, %8, %17, %1
%19 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), %1 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %17 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), %11 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %8 ]
%20 = phi i32 [ 0, %1 ], [ 0, %17 ], [ 0, %11 ], [ 1, %8 ]
%21 = tail call i32 @uiPrintf(i8* %19)
ret i32 %20
}