#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 EOF;
int fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ qsim_bin_out(int);
size_t qsim_in_block(char *);
int /*<<< orphan*/ qsim_out(int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ write(int, char *, size_t);
int main(int argc, char **argv) {
  int c;
  if (!strcmp(argv[0], "/sbin/qsim_out")) {
    while ((c = fgetc(stdin)) != EOF)
      qsim_out(c);
  } else if (!strcmp(argv[0], "/sbin/qsim_bin_out")) {
    while ((c = fgetc(stdin)) != EOF)
      qsim_bin_out(c);
  } else if (!strcmp(argv[0], "/sbin/qsim_in")) {
    size_t s;
    char buf[1024];
    while ((s = qsim_in_block(buf)) != 0)
      write(1, buf, s);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe79(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11cc <main+0x6c>
jmp    119a <main+0x3a>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e2e(%rip),%rcx
cmp    (%rcx),%eax
je     11c7 <main+0x67>
mov    -0x14(%rbp),%edi
call   1080 <qsim_out@plt>
jmp    119a <main+0x3a>
jmp    1283 <main+0x123>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe35(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    121f <main+0xbf>
jmp    11ed <main+0x8d>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2ddb(%rip),%rcx
cmp    (%rcx),%eax
je     121a <main+0xba>
mov    -0x14(%rbp),%edi
call   1070 <qsim_bin_out@plt>
jmp    11ed <main+0x8d>
jmp    127e <main+0x11e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xdf5(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1279 <main+0x119>
jmp    1240 <main+0xe0>
lea    -0x420(%rbp),%rdi
call   1040 <qsim_in_block@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1274 <main+0x114>
lea    -0x420(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    1240 <main+0xe0>
jmp    1279 <main+0x119>
jmp    127e <main+0x11e>
jmp    1283 <main+0x123>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    (%rsi),%rbx
lea    0xe8c(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11ea <main+0x8a>
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1225 <main+0xc5>
lea    0xe84(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11dd <main+0x7d>
mov    %rsp,%rdi
call   1040 <qsim_in_block@plt>
test   %rax,%rax
je     11dd <main+0x7d>
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rbx,%rdi
call   1040 <qsim_in_block@plt>
test   %rax,%rax
jne    11c0 <main+0x60>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2df7(%rip),%r14
mov    (%r14),%edi
call   1050 <fgetc@plt>
mov    0x2de0(%rip),%rbx
cmp    (%rbx),%eax
je     11dd <main+0x7d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%edi
call   1080 <qsim_out@plt>
mov    (%r14),%edi
call   1050 <fgetc@plt>
cmp    (%rbx),%eax
jne    1210 <main+0xb0>
jmp    11dd <main+0x7d>
mov    0x2dbc(%rip),%r14
mov    (%r14),%edi
call   1050 <fgetc@plt>
mov    0x2da5(%rip),%rbx
cmp    (%rbx),%eax
je     11dd <main+0x7d>
nop
mov    %eax,%edi
call   1070 <qsim_bin_out@plt>
mov    (%r14),%edi
call   1050 <fgetc@plt>
cmp    (%rbx),%eax
jne    1240 <main+0xe0>
jmp    11dd <main+0x7d>

LLVM IR (-O0):
@.str = [15 x i8] c"/sbin/qsim_out\00"
@stdin = global i32 0
@EOF = global i32 0
@.str.1 = [19 x i8] c"/sbin/qsim_bin_out\00"
@.str.2 = [14 x i8] c"/sbin/qsim_in\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32 @strcmp(i8* %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %2
br label %15
15: ; preds = %20, %14
%16 = load i32, i32* @stdin
%17 = call i32 @fgetc(i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32, i32* %6
%22 = call i32 @qsim_out(i32 %21)
br label %15
23: ; preds = %15
br label %58
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 @strcmp(i8* %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp ne i32 %28, 0
br i1 %29, label %40, label %30
30: ; preds = %24
br label %31
31: ; preds = %36, %30
%32 = load i32, i32* @stdin
%33 = call i32 @fgetc(i32 %32)
store i32 %33, i32* %6
%34 = load i32, i32* @EOF
%35 = icmp ne i32 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i32, i32* %6
%38 = call i32 @qsim_bin_out(i32 %37)
br label %31
39: ; preds = %31
br label %57
40: ; preds = %24
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = call i32 @strcmp(i8* %43, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%45 = icmp ne i32 %44, 0
br i1 %45, label %56, label %46
46: ; preds = %40
br label %47
47: ; preds = %51, %46
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%49 = call i64 @qsim_in_block(i8* %48)
store i64 %49, i64* %7
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%53 = load i64, i64* %7
%54 = call i32 @write(i32 1, i8* %52, i64 %53)
br label %47
55: ; preds = %47
br label %56
56: ; preds = %55, %40
br label %57
57: ; preds = %56, %39
br label %58
58: ; preds = %57, %23
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"/sbin/qsim_out\00"
@stdin = global i32 0
@EOF = global i32 0
@.str.1 = [19 x i8] c"/sbin/qsim_bin_out\00"
@.str.2 = [14 x i8] c"/sbin/qsim_in\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = load i8*, i8** %1
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %4, i8* dereferenceable(15) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %2
%8 = load i32, i32* @stdin
%9 = tail call i32 @fgetc(i32 %8)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %47, label %12
12: ; preds = %7, %12
%13 = phi i32 [ %16, %12 ], [ %9, %7 ]
%14 = tail call i32 @qsim_out(i32 %13)
%15 = load i32, i32* @stdin
%16 = tail call i32 @fgetc(i32 %15)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %47, label %12
19: ; preds = %2
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %4, i8* dereferenceable(19) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %19
%23 = load i32, i32* @stdin
%24 = tail call i32 @fgetc(i32 %23)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %47, label %27
27: ; preds = %22, %27
%28 = phi i32 [ %31, %27 ], [ %24, %22 ]
%29 = tail call i32 @qsim_bin_out(i32 %28)
%30 = load i32, i32* @stdin
%31 = tail call i32 @fgetc(i32 %30)
%32 = load i32, i32* @EOF
%33 = icmp eq i32 %31, %32
br i1 %33, label %47, label %27
34: ; preds = %19
%35 = tail call i32 @strcmp(i8* dereferenceable(1) %4, i8* dereferenceable(14) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %47
37: ; preds = %34
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%39 = call i64 @qsim_in_block(i8* %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %46, label %41
41: ; preds = %37, %41
%42 = phi i64 [ %44, %41 ], [ %39, %37 ]
%43 = call i32 @write(i32 1, i8* %38, i64 %42)
%44 = call i64 @qsim_in_block(i8* %38)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %41
46: ; preds = %41, %37
br label %47
47: ; preds = %27, %12, %22, %7, %46, %34
ret i32 0
}