#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 f_read(char *);
int f_write(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (argc < 3)
    goto inval;
  if (strcmp(argv[2], "r") == 0)
    return f_read(argv[1]);
  if ((argc > 3) && (strcmp(argv[2], "w") == 0))
    return f_write(argv[1], argv[3]);
inval:
  fprintf(stderr, "Usage: %s <filename> <r|w> [string]\n", argv[0]);
  return -1;
}


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)
jge    1165 <main+0x25>
jmp    11e2 <main+0xa2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe8c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1198 <main+0x58>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <f_read@plt>
mov    %eax,-0x4(%rbp)
jmp    1205 <main+0xc5>
cmpl   $0x3,-0x8(%rbp)
jle    11dd <main+0x9d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe51(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11dd <main+0x9d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1060 <f_write@plt>
mov    %eax,-0x4(%rbp)
jmp    1205 <main+0xc5>
jmp    11e2 <main+0xa2>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0b(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jl     117c <main+0x3c>
mov    %edi,%ebp
mov    0x10(%rbx),%rdi
lea    0xea8(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11a0 <main+0x60>
cmp    $0x4,%ebp
jb     117c <main+0x3c>
mov    0x10(%rbx),%rdi
lea    0xe90(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11af <main+0x6f>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe75(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x8(%rbx),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <f_read@plt>
mov    0x8(%rbx),%rdi
mov    0x18(%rbx),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <f_write@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [37 x i8] c"Usage: %s <filename> <r|w> [string]\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 slt i32 %6, 3
br i1 %7, label %8, label %9
8: ; preds = %2
br label %38
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 2
%12 = load i8*, i8** %11
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %9
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @f_read(i8* %18)
store i32 %19, i32* %3
br label %44
20: ; preds = %9
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, 3
br i1 %22, label %23, label %37
23: ; preds = %20
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %23
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 3
%35 = load i8*, i8** %34
%36 = call i32 @f_write(i8* %32, i8* %35)
store i32 %36, i32* %3
br label %44
37: ; preds = %23, %20
br label %38
38: ; preds = %37, %8
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %42)
store i32 -1, i32* %3
br label %44
44: ; preds = %38, %29, %15
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [37 x i8] c"Usage: %s <filename> <r|w> [string]\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %25, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 2
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @f_read(i8* %11)
br label %29
13: ; preds = %4
%14 = icmp ugt i32 %0, 3
br i1 %14, label %15, label %25
15: ; preds = %13
%16 = load i8*, i8** %5
%17 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
%24 = tail call i32 @f_write(i8* %21, i8* %23)
br label %29
25: ; preds = %13, %15, %2
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %1
%28 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %25, %19, %9
%30 = phi i32 [ -1, %25 ], [ %12, %9 ], [ %24, %19 ]
ret i32 %30
}