#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ rferror(char *);
int /*<<< orphan*/ stdout;
void parse_arg(int argc, char **argv, FILE **infile, FILE **outfile) {
  if (argc < 2) {
    fprintf(stdout, "usage: %s infile [outfile]\n", argv[0]);
    rferror("Wrong number of arguments.");
  }
  if (!(*infile = fopen(argv[1], "rb"))) {
    rferror("Could not open in-file for reading.");
  }
  if (argc > 2) {
    if (!(*outfile = fopen(argv[2], "wb"))) {
      rferror("Could not open out-file for writing.");
    }
  } else {
    *outfile = NULL;
  }
}


x86 assembly (clang, -O0):
<parse_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    1179 <parse_arg+0x49>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe98(%rip),%rsi
call   1030 <fprintf@plt>
lea    0xea8(%rip),%rdi
call   1050 <rferror@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xeaf(%rip),%rsi
call   1040 <fopen@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11aa <parse_arg+0x7a>
lea    0xe95(%rip),%rdi
call   1050 <rferror@plt>
cmpl   $0x2,-0x4(%rbp)
jle    11ea <parse_arg+0xba>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe9b(%rip),%rsi
call   1040 <fopen@plt>
mov    -0x20(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11e5 <parse_arg+0xb5>
lea    0xe81(%rip),%rdi
call   1050 <rferror@plt>
jmp    11f5 <parse_arg+0xc5>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_arg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x1,%edi
jg     116b <parse_arg+0x3b>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xea6(%rip),%rsi
call   1030 <fprintf@plt>
lea    0xeb6(%rip),%rdi
call   1050 <rferror@plt>
mov    0x8(%rbx),%rdi
lea    0xec1(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     11b6 <parse_arg+0x86>
cmp    $0x3,%ebp
jl     11c7 <parse_arg+0x97>
mov    0x10(%rbx),%rdi
lea    0xecb(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,(%r14)
test   %rax,%rax
jne    11ce <parse_arg+0x9e>
lea    0xeba(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <rferror@plt>
lea    0xe7d(%rip),%rdi
call   1050 <rferror@plt>
cmp    $0x3,%ebp
jge    1188 <parse_arg+0x58>
movq   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [28 x i8] c"usage: %s infile [outfile]\0A\00"
@.str.1 = [27 x i8] c"Wrong number of arguments.\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [36 x i8] c"Could not open in-file for reading.\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [37 x i8] c"Could not open out-file for writing.\00"
define void @parse_arg(i32 %0, i8** %1, i32** %2, i32** %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32**
%8 = alloca i32**
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i32** %2, i32*** %7
store i32** %3, i32*** %8
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %4
%12 = load i32, i32* @stdout
%13 = load i8**, i8*** %6
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @rferror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %11, %4
%19 = load i8**, i8*** %6
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32**, i32*** %7
store i32* %22, i32** %23
%24 = icmp ne i32* %22, null
br i1 %24, label %27, label %25
25: ; preds = %18
%26 = call i32 @rferror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %18
%28 = load i32, i32* %5
%29 = icmp sgt i32 %28, 2
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = load i8**, i8*** %6
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%35 = load i32**, i32*** %8
store i32* %34, i32** %35
%36 = icmp ne i32* %34, null
br i1 %36, label %39, label %37
37: ; preds = %30
%38 = call i32 @rferror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %39
39: ; preds = %37, %30
br label %42
40: ; preds = %27
%41 = load i32**, i32*** %8
store i32* null, i32** %41
br label %42
42: ; preds = %40, %39
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [28 x i8] c"usage: %s infile [outfile]\0A\00"
@.str.1 = [27 x i8] c"Wrong number of arguments.\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [36 x i8] c"Could not open in-file for reading.\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [37 x i8] c"Could not open out-file for writing.\00"
define void @parse_arg(i32 %0, i8** nocapture %1, i32** nocapture writeonly %2, i32** nocapture writeonly %3) {
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %11
6: ; preds = %4
%7 = load i32, i32* @stdout
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @rferror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %6, %4
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %2
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @rferror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = icmp sgt i32 %0, 2
br i1 %19, label %20, label %27
20: ; preds = %18
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %23, i32** %3
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = tail call i32 @rferror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %28
27: ; preds = %18
store i32* null, i32** %3
br label %28
28: ; preds = %20, %25, %27
ret void
}