#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 dialog_quit_confirm(struct state *, struct ui *);
int fread(char *, int, int, int /*<<< orphan*/);
int singleplayer_process_input(struct state *, struct ui *, int);
int /*<<< orphan*/ stdin;
int update_from_input(struct state *st, struct ui *ui) {
  int c;
  char buf[1];
  int finished = 0;
  while (fread(buf, 1, 1, stdin) == 1) {
    c = buf[0];
    switch (c) {
    case 'q':
    case 'Q':
      finished = dialog_quit_confirm(st, ui);
      break;
    default:
      finished = singleplayer_process_input(st, ui, c);
    }
  }
  return finished;
}


x86 assembly (clang, -O0):
<update_from_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x15(%rbp),%rdi
mov    0x2e96(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    11b1 <update_from_input+0x81>
movsbl -0x15(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
or     $0x20,%eax
sub    $0x71,%eax
je     1184 <update_from_input+0x54>
jmp    1199 <update_from_input+0x69>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <dialog_quit_confirm@plt>
mov    %eax,-0x1c(%rbp)
jmp    11ac <update_from_input+0x7c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <singleplayer_process_input@plt>
mov    %eax,-0x1c(%rbp)
jmp    1147 <update_from_input+0x17>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_from_input>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e9f(%rip),%r12
mov    (%r12),%ecx
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
jne    11ae <update_from_input+0x7e>
lea    0xf(%rsp),%r15
jmp    1192 <update_from_input+0x62>
nop
call   1030 <singleplayer_process_input@plt>
mov    %eax,%ebp
mov    (%r12),%ecx
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    11ae <update_from_input+0x7e>
movsbl 0xf(%rsp),%edx
mov    %edx,%eax
or     $0x20,%eax
mov    %rbx,%rdi
mov    %r14,%rsi
cmp    $0x71,%eax
jne    1170 <update_from_input+0x40>
call   1050 <dialog_quit_confirm@plt>
jmp    1175 <update_from_input+0x45>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.state = type { i32 }
%struct.ui = type { i32 }
@stdin = global i32 0
define i32 @update_from_input(%struct.state* %0, %struct.ui* %1) {
%3 = alloca %struct.state*
%4 = alloca %struct.ui*
%5 = alloca i32
%6 = alloca [1 x i8]
%7 = alloca i32
store %struct.state* %0, %struct.state** %3
store %struct.ui* %1, %struct.ui** %4
store i32 0, i32* %7
br label %8
8: ; preds = %27, %2
%9 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32 @fread(i8* %9, i32 1, i32 1, i32 %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %28
13: ; preds = %8
%14 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
store i32 %16, i32* %5
%17 = load i32, i32* %5
switch i32 %17, label %22 [
i32 113, label %18
i32 81, label %18
]
18: ; preds = %13, %13
%19 = load %struct.state*, %struct.state** %3
%20 = load %struct.ui*, %struct.ui** %4
%21 = call i32 @dialog_quit_confirm(%struct.state* %19, %struct.ui* %20)
store i32 %21, i32* %7
br label %27
22: ; preds = %13
%23 = load %struct.state*, %struct.state** %3
%24 = load %struct.ui*, %struct.ui** %4
%25 = load i32, i32* %5
%26 = call i32 @singleplayer_process_input(%struct.state* %23, %struct.ui* %24, i32 %25)
store i32 %26, i32* %7
br label %27
27: ; preds = %22, %18
br label %8
28: ; preds = %8
%29 = load i32, i32* %7
ret i32 %29
}

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