#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*/ fatal_error(char *, char *);
int /*<<< orphan*/ open_close_input_fd(char *);
int /*<<< orphan*/ open_close_input_stdio(char *);
int /*<<< orphan*/ open_close_output_fd(char *);
int /*<<< orphan*/ open_close_output_stdio(char *);
int /*<<< orphan*/ setup();
char toupper(char);
int main(int argc, char *argv[]) {
  if (argc < 3)
    fatal_error("Usage: %s {R|W} <path>\n", argv[0]);
  setup();
  if (toupper(argv[1][0]) == 'R') {
    open_close_input_fd(argv[2]);
    open_close_input_stdio(argv[2]);
  } else {
    open_close_output_fd(argv[2]);
    open_close_output_stdio(argv[2]);
  }
  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)
jge    11a3 <main+0x33>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
call   1050 <fatal_error@plt>
mov    $0x0,%al
call   1090 <setup@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x52,%eax
jne    11e5 <main+0x75>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <open_close_input_fd@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <open_close_input_stdio@plt>
jmp    11ff <main+0x8f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <open_close_output_fd@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <open_close_output_stdio@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     1188 <main+0x18>
mov    (%rbx),%rsi
lea    0xe7d(%rip),%rdi
call   1050 <fatal_error@plt>
xor    %eax,%eax
call   1090 <setup@plt>
mov    0x8(%rbx),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
mov    0x10(%rbx),%rdi
cmp    $0x52,%al
jne    11b3 <main+0x43>
call   1030 <open_close_input_fd@plt>
mov    0x10(%rbx),%rdi
call   1080 <open_close_input_stdio@plt>
jmp    11c1 <main+0x51>
call   1060 <open_close_output_fd@plt>
mov    0x10(%rbx),%rdi
call   1070 <open_close_output_stdio@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Usage: %s {R|W} <path>\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 %13
8: ; preds = %2
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32 @fatal_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %8, %2
%14 = call i32 (...) @setup()
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = call signext i8 @toupper(i8 signext %19)
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 82
br i1 %22, label %23, label %32
23: ; preds = %13
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @open_close_input_fd(i8* %26)
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @open_close_input_stdio(i8* %30)
br label %41
32: ; preds = %13
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @open_close_output_fd(i8* %35)
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32 @open_close_output_stdio(i8* %39)
br label %41
41: ; preds = %32, %23
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Usage: %s {R|W} <path>\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @fatal_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %7
7: ; preds = %4, %2
%8 = tail call i32 (...) @setup()
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = tail call signext i8 @toupper(i8 signext %11)
%13 = icmp eq i8 %12, 82
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
br i1 %13, label %16, label %20
16: ; preds = %7
%17 = tail call i32 @open_close_input_fd(i8* %15)
%18 = load i8*, i8** %14
%19 = tail call i32 @open_close_input_stdio(i8* %18)
br label %24
20: ; preds = %7
%21 = tail call i32 @open_close_output_fd(i8* %15)
%22 = load i8*, i8** %14
%23 = tail call i32 @open_close_output_stdio(i8* %22)
br label %24
24: ; preds = %20, %16
ret i32 0
}