#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*/ file_read(char *);
int /*<<< orphan*/ file_write(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  char ioFlag[50];
  if (argc < 2 || argc > 3) {
    usage(argv[0]);
    return 0;
  } else if (argc == 2) {
    strcpy(ioFlag, "-w");
  } else {
    strcpy(ioFlag, argv[2]);
  }
  if (!strcmp(ioFlag, "-w")) {
    printf("Writing new file named %s\n", argv[1]);
    file_write(argv[1]);
  } else if (!strcmp(ioFlag, "-r")) {
    printf("Reading from file named %s\n", argv[1]);
    file_read(argv[1]);
  } else {
    printf("Error: unknown file ioFlag \'%s\'\n", ioFlag);
    usage(argv[0]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     118a <main+0x2a>
cmpl   $0x3,-0x8(%rbp)
jle    11a2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    127d <main+0x11d>
cmpl   $0x2,-0x8(%rbp)
jne    11c1 <main+0x61>
lea    -0x50(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11d2 <main+0x72>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <strcpy@plt>
jmp    11d7 <main+0x77>
lea    -0x50(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1216 <main+0xb6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe04(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <file_write@plt>
jmp    1276 <main+0x116>
lea    -0x50(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1255 <main+0xf5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xde3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <file_read@plt>
jmp    1271 <main+0x111>
lea    -0x50(%rbp),%rsi
lea    0xddd(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
jmp    1276 <main+0x116>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%rbx
lea    -0x4(%rdi),%eax
cmp    $0xfffffffd,%eax
jbe    11ad <main+0x5d>
cmp    $0x2,%edi
jne    116e <main+0x1e>
lea    0xe94(%rip),%rsi
jmp    1172 <main+0x22>
mov    0x10(%rbx),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
mov    $0x772d,%eax
xor    (%rsp),%eax
movzbl 0x2(%rsp),%ecx
or     %ax,%cx
je     11b7 <main+0x67>
mov    $0x722d,%eax
xor    (%rsp),%eax
movzbl 0x2(%rsp),%ecx
or     %ax,%cx
je     11d2 <main+0x82>
lea    0xe98(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
mov    (%rbx),%rdi
call   1050 <usage@plt>
jmp    11eb <main+0x9b>
mov    0x8(%rbx),%rsi
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%rbx),%rdi
call   1070 <file_write@plt>
jmp    11eb <main+0x9b>
mov    0x8(%rbx),%rsi
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%rbx),%rdi
call   1060 <file_read@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-w\00"
@.str.1 = [27 x i8] c"Writing new file named %s\0A\00"
@.str.2 = [3 x i8] c"-r\00"
@.str.3 = [28 x i8] c"Reading from file named %s\0A\00"
@.str.4 = [33 x i8] c"Error: unknown file ioFlag '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [50 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %9, %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @usage(i8* %15)
store i32 0, i32* %3
br label %65
17: ; preds = %9
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %29
23: ; preds = %17
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @strcpy(i8* %24, i8* %27)
br label %29
29: ; preds = %23, %20
br label %30
30: ; preds = %29
%31 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %43, label %34
34: ; preds = %30
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 @file_write(i8* %41)
br label %64
43: ; preds = %30
%44 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%45 = call i32 @strcmp(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%46 = icmp ne i32 %45, 0
br i1 %46, label %56, label %47
47: ; preds = %43
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %50)
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = call i32 @file_read(i8* %54)
br label %63
56: ; preds = %43
%57 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%58 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %57)
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = call i32 @usage(i8* %61)
br label %63
63: ; preds = %56, %47
br label %64
64: ; preds = %63, %34
store i32 0, i32* %3
br label %65
65: ; preds = %64, %12
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@.str = [3 x i8] c"-w\00"
@.str.1 = [27 x i8] c"Writing new file named %s\0A\00"
@.str.2 = [3 x i8] c"-r\00"
@.str.3 = [28 x i8] c"Reading from file named %s\0A\00"
@.str.4 = [33 x i8] c"Error: unknown file ioFlag '%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [50 x i8]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%5 = add i32 %0, -4
%6 = icmp ult i32 %5, -2
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 @usage(i8* %8)
br label %39
10: ; preds = %2
%11 = icmp eq i32 %0, 2
br i1 %11, label %15, label %12
12: ; preds = %10
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
br label %15
15: ; preds = %10, %12
%16 = phi i8* [ %14, %12 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %10 ]
%17 = call i32 @strcpy(i8* %4, i8* %16)
%18 = call i32 @bcmp(i8* dereferenceable(3) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 3)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %21
%25 = call i32 @file_write(i8* %24)
br label %39
26: ; preds = %15
%27 = call i32 @bcmp(i8* dereferenceable(3) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 3)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = getelementptr inbounds i8*, i8** %1, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %30
%34 = call i32 @file_read(i8* %33)
br label %39
35: ; preds = %26
%36 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%37 = load i8*, i8** %1
%38 = call i32 @usage(i8* %37)
br label %39
39: ; preds = %20, %35, %29, %7
ret i32 0
}