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

/* Variables and functions */
int fread(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int update_from_input_server(struct state *st) {
  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 = 1;
      break;
    }
  }
  return finished;
}


x86 assembly (clang, -O0):
<update_from_input_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0xd(%rbp),%rdi
mov    0x2eba(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    116c <update_from_input_server+0x5c>
movsbl -0xd(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
or     $0x20,%eax
sub    $0x71,%eax
je     1160 <update_from_input_server+0x50>
jmp    1167 <update_from_input_server+0x57>
movl   $0x1,-0x14(%rbp)
jmp    1123 <update_from_input_server+0x13>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_from_input_server>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ec8(%rip),%r15
mov    (%r15),%ecx
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
xor    %ebx,%ebx
cmp    $0x1,%eax
jne    117e <update_from_input_server+0x6e>
xor    %ebx,%ebx
lea    0xf(%rsp),%r14
jmp    116a <update_from_input_server+0x5a>
nopw   0x0(%rax,%rax,1)
mov    (%r15),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    117e <update_from_input_server+0x6e>
movsbl 0xf(%rsp),%eax
or     $0x20,%eax
cmp    $0x71,%eax
jne    1150 <update_from_input_server+0x40>
mov    $0x1,%ebx
jmp    1150 <update_from_input_server+0x40>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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