#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 ui {
  int dummy;
};
struct state {
  int dummy;
};

/* Variables and functions */
int fread(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ output_dialog_quit_off(struct state *, struct ui *);
int /*<<< orphan*/ output_dialog_quit_on(struct state *, struct ui *);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ stdin;
int dialog_quit_confirm(struct state *st, struct ui *ui) {
  output_dialog_quit_on(st, ui);
  int done = 0;
  int finished = 0;
  char buf[1];
  while (!done) {
    if (fread(buf, 1, 1, stdin) == 1) {
      char c = buf[0];
      switch (c) {
      case 'y':
      case 'Y':
      case 'q':
      case 'Q':
        finished = 1;
        done = 1;
        break;
      case 'n':
      case 'N':
      case '\033':
        finished = 0;
        done = 1;
        break;
      default:
        break;
      }
    } else
      pause();
  }
  output_dialog_quit_off(st, ui);
  return finished;
}


x86 assembly (clang, -O0):
<dialog_quit_confirm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <output_dialog_quit_on@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1181 <dialog_quit_confirm+0x41>
jmp    1260 <dialog_quit_confirm+0x120>
lea    -0x19(%rbp),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1254 <dialog_quit_confirm+0x114>
mov    -0x19(%rbp),%al
mov    %al,-0x1a(%rbp)
movsbl -0x1a(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x1b,%eax
je     1237 <dialog_quit_confirm+0xf7>
jmp    11be <dialog_quit_confirm+0x7e>
mov    -0x20(%rbp),%eax
sub    $0x4e,%eax
je     1237 <dialog_quit_confirm+0xf7>
jmp    11cf <dialog_quit_confirm+0x8f>
mov    -0x20(%rbp),%eax
sub    $0x51,%eax
je     1224 <dialog_quit_confirm+0xe4>
jmp    11e0 <dialog_quit_confirm+0xa0>
mov    -0x20(%rbp),%eax
sub    $0x59,%eax
je     1224 <dialog_quit_confirm+0xe4>
jmp    11f1 <dialog_quit_confirm+0xb1>
mov    -0x20(%rbp),%eax
sub    $0x6e,%eax
je     1237 <dialog_quit_confirm+0xf7>
jmp    1202 <dialog_quit_confirm+0xc2>
mov    -0x20(%rbp),%eax
sub    $0x71,%eax
je     1224 <dialog_quit_confirm+0xe4>
jmp    1213 <dialog_quit_confirm+0xd3>
mov    -0x20(%rbp),%eax
sub    $0x79,%eax
jne    124a <dialog_quit_confirm+0x10a>
jmp    1224 <dialog_quit_confirm+0xe4>
movl   $0x1,-0x18(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    124f <dialog_quit_confirm+0x10f>
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    124f <dialog_quit_confirm+0x10f>
jmp    124f <dialog_quit_confirm+0x10f>
jmp    125b <dialog_quit_confirm+0x11b>
mov    $0x0,%al
call   1050 <pause@plt>
jmp    116b <dialog_quit_confirm+0x2b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <output_dialog_quit_off@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dialog_quit_confirm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1060 <output_dialog_quit_on@plt>
mov    0x2e8b(%rip),%r12
lea    0x7(%rsp),%rbx
movabs $0x80800000808,%r13
movabs $0x100000001,%rbp
jmp    1187 <dialog_quit_confirm+0x47>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <pause@plt>
mov    (%r12),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    1180 <dialog_quit_confirm+0x40>
movsbl 0x7(%rsp),%eax
lea    -0x4e(%rax),%ecx
cmp    $0x2b,%ecx
ja     11bb <dialog_quit_confirm+0x7b>
bt     %rcx,%r13
jb     11c4 <dialog_quit_confirm+0x84>
bt     %rcx,%rbp
jb     11c0 <dialog_quit_confirm+0x80>
cmp    $0x1b,%eax
jne    1187 <dialog_quit_confirm+0x47>
xor    %ebx,%ebx
jmp    11c9 <dialog_quit_confirm+0x89>
mov    $0x1,%ebx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <output_dialog_quit_off@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.state = type { i32 }
%struct.ui = type { i32 }
@stdin = global i32 0
define i32 @dialog_quit_confirm(%struct.state* %0, %struct.ui* %1) {
%3 = alloca %struct.state*
%4 = alloca %struct.ui*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1 x i8]
%8 = alloca i8
store %struct.state* %0, %struct.state** %3
store %struct.ui* %1, %struct.ui** %4
%9 = load %struct.state*, %struct.state** %3
%10 = load %struct.ui*, %struct.ui** %4
%11 = call i32 @output_dialog_quit_on(%struct.state* %9, %struct.ui* %10)
store i32 0, i32* %5
store i32 0, i32* %6
br label %12
12: ; preds = %32, %2
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %33
16: ; preds = %12
%17 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i32 @fread(i8* %17, i32 1, i32 1, i32 %18)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %30
21: ; preds = %16
%22 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%23 = load i8, i8* %22
store i8 %23, i8* %8
%24 = load i8, i8* %8
%25 = sext i8 %24 to i32
switch i32 %25, label %28 [
i32 121, label %26
i32 89, label %26
i32 113, label %26
i32 81, label %26
i32 110, label %27
i32 78, label %27
i32 27, label %27
]
26: ; preds = %21, %21, %21, %21
store i32 1, i32* %6
store i32 1, i32* %5
br label %29
27: ; preds = %21, %21, %21
store i32 0, i32* %6
store i32 1, i32* %5
br label %29
28: ; preds = %21
br label %29
29: ; preds = %28, %27, %26
br label %32
30: ; preds = %16
%31 = call i32 (...) @pause()
br label %32
32: ; preds = %30, %29
br label %12
33: ; preds = %12
%34 = load %struct.state*, %struct.state** %3
%35 = load %struct.ui*, %struct.ui** %4
%36 = call i32 @output_dialog_quit_off(%struct.state* %34, %struct.ui* %35)
%37 = load i32, i32* %6
ret i32 %37
}

LLVM IR (-O2):
%struct.state = type { i32 }
%struct.ui = type { i32 }
@stdin = global i32 0
define i32 @dialog_quit_confirm(%struct.state* %0, %struct.ui* %1) {
%3 = alloca [1 x i8]
%4 = tail call i32 @output_dialog_quit_on(%struct.state* %0, %struct.ui* %1)
%5 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
br label %6
6: ; preds = %13, %2
%7 = load i32, i32* @stdin
%8 = call i32 @fread(i8* %5, i32 1, i32 1, i32 %7)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i8, i8* %5
%12 = sext i8 %11 to i32
switch i32 %12, label %13 [
i32 121, label %16
i32 89, label %16
i32 113, label %16
i32 81, label %16
i32 110, label %17
i32 78, label %17
i32 27, label %17
]
13: ; preds = %10, %14
br label %6
14: ; preds = %6
%15 = call i32 (...) @pause()
br label %13
16: ; preds = %10, %10, %10, %10
br label %17
17: ; preds = %10, %10, %10, %16
%18 = phi i32 [ 1, %16 ], [ 0, %10 ], [ 0, %10 ], [ 0, %10 ]
%19 = call i32 @output_dialog_quit_off(%struct.state* %0, %struct.ui* %1)
ret i32 %18
}