#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*/ __llvm_profile_set_file_object(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ *fopen(char const *, char *);
int main(int argc, const char *argv[]) {
  if (argc < 2)
    return 1;
  FILE *F = fopen(argv[1], "r+b");
  if (!F) {
    F = fopen(argv[1], "w+b");
  }
  __llvm_profile_set_file_object(F, 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    114c <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    119c <main+0x7c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xea5(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1187 <main+0x67>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe86(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1030 <__llvm_profile_set_file_object@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x1,%eax
cmp    $0x2,%edi
jl     1163 <main+0x43>
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xec7(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
jne    1153 <main+0x33>
mov    0x8(%rbx),%rdi
lea    0xeb6(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%rdi
mov    $0x1,%esi
call   1030 <__llvm_profile_set_file_object@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"r+b\00"
@.str.1 = [4 x i8] c"w+b\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
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 %9, label %10
9: ; preds = %2
store i32 1, i32* %3
br label %25
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %22, label %17
17: ; preds = %10
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
br label %22
22: ; preds = %17, %10
%23 = load i32*, i32** %6
%24 = call i32 @__llvm_profile_set_file_object(i32* %23, i32 1)
store i32 0, i32* %3
br label %25
25: ; preds = %22, %9
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [4 x i8] c"r+b\00"
@.str.1 = [4 x i8] c"w+b\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i8*, i8** %5
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %9, %4
%13 = phi i32* [ %7, %4 ], [ %11, %9 ]
%14 = tail call i32 @__llvm_profile_set_file_object(i32* %13, i32 1)
br label %15
15: ; preds = %2, %12
%16 = phi i32 [ 0, %12 ], [ 1, %2 ]
ret i32 %16
}