#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 */
struct editor {
  int dummy;
};

/* Variables and functions */
char *editor_prompt(struct editor *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char *, char *);
int editor_prompt_bool(struct editor *e, char *prompt) {
  while (1) {
    char *res = editor_prompt(e, prompt, NULL);
    if (res == NULL) {
      continue;
    }
    int v = -1;
    if (strcmp(res, "y") == 0) {
      v = 1;
    } else if (strcmp(res, "n") == 0) {
      v = 0;
    }
    free(res);
    if (v >= 0) {
      return v;
    }
  }
}


x86 assembly (clang, -O0):
<editor_prompt_bool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <editor_prompt@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1165 <editor_prompt_bool+0x35>
jmp    1140 <editor_prompt_bool+0x10>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1192 <editor_prompt_bool+0x62>
movl   $0x1,-0x1c(%rbp)
jmp    11b8 <editor_prompt_bool+0x88>
mov    -0x18(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11b3 <editor_prompt_bool+0x83>
movl   $0x0,-0x1c(%rbp)
jmp    11b8 <editor_prompt_bool+0x88>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x1c(%rbp)
jl     11d4 <editor_prompt_bool+0xa4>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    1140 <editor_prompt_bool+0x10>

x86 assembly (clang, -O2):
<editor_prompt_bool>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
lea    0xeb8(%rip),%r15
lea    0xeb3(%rip),%r12
nop
mov    %r13,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <editor_prompt@plt>
test   %rax,%rax
je     1150 <editor_prompt_bool+0x20>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1194 <editor_prompt_bool+0x64>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %rbp,%rbp
jne    1150 <editor_prompt_bool+0x20>
xor    %eax,%eax
jmp    11a1 <editor_prompt_bool+0x71>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.editor = type { i32 }
@.str = [2 x i8] c"y\00"
@.str.1 = [2 x i8] c"n\00"
define i32 @editor_prompt_bool(%struct.editor* %0, i8* %1) {
%3 = alloca %struct.editor*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store %struct.editor* %0, %struct.editor** %3
store i8* %1, i8** %4
br label %7
7: ; preds = %2, %13, %32
%8 = load %struct.editor*, %struct.editor** %3
%9 = load i8*, i8** %4
%10 = call i8* @editor_prompt(%struct.editor* %8, i8* %9, i32* null)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %7
br label %7
14: ; preds = %7
store i32 -1, i32* %6
%15 = load i8*, i8** %5
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 1, i32* %6
br label %25
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 0, i32* %6
br label %24
24: ; preds = %23, %19
br label %25
25: ; preds = %24, %18
%26 = load i8*, i8** %5
%27 = call i32 @free(i8* %26)
%28 = load i32, i32* %6
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = load i32, i32* %6
ret i32 %31
32: ; preds = %25
br label %7
}

LLVM IR (-O2):
%struct.editor = type { i32 }
@.str = [2 x i8] c"y\00"
@.str.1 = [2 x i8] c"n\00"
define i32 @editor_prompt_bool(%struct.editor* %0, i8* %1) {
br label %3
3: ; preds = %15, %2
%4 = tail call i8* @editor_prompt(%struct.editor* %0, i8* %1, i32* null)
%5 = icmp eq i8* %4, null
br i1 %5, label %15, label %6
6: ; preds = %3
%7 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @free(i8* %4)
br label %16
11: ; preds = %6
%12 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
%14 = tail call i32 @free(i8* %4)
br i1 %13, label %16, label %15
15: ; preds = %11, %3
br label %3
16: ; preds = %11, %9
%17 = phi i32 [ 1, %9 ], [ 0, %11 ]
ret i32 %17
}