#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ ioctl_chr(int, int /*<<< orphan*/);
int /*<<< orphan*/ read_chr();
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ write_chr(char *);
int main(int argc, char *argv[]) {
  if ((argc == 3) && (strcmp(argv[1], "write") == 0)) {
    write_chr(argv[2]);
  } else if ((argc == 2) && (strcmp(argv[1], "read") == 0)) {
    read_chr();
  } else if ((argc == 3) && (strcmp(argv[1], "ioctl") == 0)) {
    if (strcmp(argv[2], "clear") == 0)
      ioctl_chr(0x909090, 0);
  } else {
    fprintf(stderr, "Usage: %s write 'some_strings'\nUsage: %s read\n", argv[0],
            argv[0]);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    11a0 <main+0x50>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe81(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11a0 <main+0x50>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <write_chr@plt>
jmp    1264 <main+0x114>
cmpl   $0x2,-0x8(%rbp)
jne    11d4 <main+0x84>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11d4 <main+0x84>
mov    $0x0,%al
call   1070 <read_chr@plt>
jmp    125f <main+0x10f>
cmpl   $0x3,-0x8(%rbp)
jne    122b <main+0xdb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    122b <main+0xdb>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe06(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1226 <main+0xd6>
mov    $0x909090,%edi
xor    %esi,%esi
call   1030 <ioctl_chr@plt>
jmp    125a <main+0x10a>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xdce(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <main+0x11b>
jmp    125f <main+0x10f>
jmp    1264 <main+0x114>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
je     11af <main+0x5f>
cmp    $0x3,%edi
jne    11c4 <main+0x74>
mov    0x8(%rbx),%rdi
lea    0xe97(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11e8 <main+0x98>
mov    0x8(%rbx),%rdi
lea    0xe8d(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11c4 <main+0x74>
mov    0x10(%rbx),%rdi
lea    0xe7e(%rip),%rsi
call   1050 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    11e4 <main+0x94>
xor    %ebx,%ebx
mov    $0x909090,%edi
xor    %esi,%esi
call   1030 <ioctl_chr@plt>
jmp    11e4 <main+0x94>
mov    0x8(%rbx),%rdi
lea    0xe4c(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11f5 <main+0xa5>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rcx
lea    0xe40(%rip),%rsi
mov    %rcx,%rdx
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret
mov    0x10(%rbx),%rdi
call   1040 <write_chr@plt>
xor    %ebx,%ebx
jmp    11e4 <main+0x94>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <read_chr@plt>
jmp    11e4 <main+0x94>

LLVM IR (-O0):
@.str = [6 x i8] c"write\00"
@.str.1 = [5 x i8] c"read\00"
@.str.2 = [6 x i8] c"ioctl\00"
@.str.3 = [6 x i8] c"clear\00"
@stderr = global i32 0
@.str.4 = [47 x i8] c"Usage: %s write 'some_strings'\0AUsage: %s read\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 3
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i32 @write_chr(i8* %17)
br label %59
19: ; preds = %8, %2
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 2
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 (...) @read_chr()
br label %58
30: ; preds = %22, %19
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, 3
br i1 %32, label %33, label %48
33: ; preds = %30
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %48
39: ; preds = %33
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %39
%46 = call i32 @ioctl_chr(i32 9474192, i32 0)
br label %47
47: ; preds = %45, %39
br label %57
48: ; preds = %33, %30
%49 = load i32, i32* @stderr
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 0
%55 = load i8*, i8** %54
%56 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %52, i8* %55)
store i32 -1, i32* %3
br label %60
57: ; preds = %47
br label %58
58: ; preds = %57, %28
br label %59
59: ; preds = %58, %14
store i32 0, i32* %3
br label %60
60: ; preds = %59, %48
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str = [6 x i8] c"write\00"
@.str.1 = [5 x i8] c"read\00"
@.str.2 = [6 x i8] c"ioctl\00"
@.str.3 = [6 x i8] c"clear\00"
@stderr = global i32 0
@.str.4 = [47 x i8] c"Usage: %s write 'some_strings'\0AUsage: %s read\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %30 [
i32 3, label %3
i32 2, label %12
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %3
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @write_chr(i8* %10)
br label %34
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %12
%18 = tail call i32 (...) @read_chr()
br label %34
19: ; preds = %3
%20 = load i8*, i8** %4
%21 = tail call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %19
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = tail call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %23
%29 = tail call i32 @ioctl_chr(i32 9474192, i32 0)
br label %34
30: ; preds = %2, %12, %19
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %1
%33 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %32, i8* %32)
br label %34
34: ; preds = %8, %28, %23, %17, %30
%35 = phi i32 [ -1, %30 ], [ 0, %17 ], [ 0, %23 ], [ 0, %28 ], [ 0, %8 ]
ret i32 %35
}