#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
void gen_parse_args(int argc, char **argv, char **fileName) {
  int i;
  FILE *test;
  for (i = 1; i < argc; ++i) {
    test = fopen(argv[i], "r");
    if (test != NULL) {
      *fileName = argv[i];
      fclose(test);
    }
  }
}


x86 assembly (clang, -O0):
<gen_parse_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119c <gen_parse_args+0x7c>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xea7(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1189 <gen_parse_args+0x69>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
jmp    118e <gen_parse_args+0x6e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113a <gen_parse_args+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_parse_args>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x2,%edi
jl     117d <gen_parse_args+0x5d>
mov    %rdx,%r14
mov    %rsi,%r13
mov    %edi,%r12d
mov    $0x1,%ebx
lea    0xebd(%rip),%r15
jmp    1159 <gen_parse_args+0x39>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    %rbx,%r12
je     117d <gen_parse_args+0x5d>
mov    0x0(%r13,%rbx,8),%rdi
mov    %r15,%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1150 <gen_parse_args+0x30>
mov    0x0(%r13,%rbx,8),%rcx
mov    %rcx,(%r14)
mov    %rax,%rdi
call   1030 <fclose@plt>
jmp    1150 <gen_parse_args+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define void @gen_parse_args(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
store i32 1, i32* %7
br label %9
9: ; preds = %32, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %35
13: ; preds = %9
%14 = load i8**, i8*** %5
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %8
%20 = load i32*, i32** %8
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %31
22: ; preds = %13
%23 = load i8**, i8*** %5
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %6
store i8* %27, i8** %28
%29 = load i32*, i32** %8
%30 = call i32 @fclose(i32* %29)
br label %31
31: ; preds = %22, %13
br label %32
32: ; preds = %31
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %9
35: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define void @gen_parse_args(i32 %0, i8** nocapture %1, i8** nocapture writeonly %2) {
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %19
5: ; preds = %3
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %16
%8 = phi i64 [ 1, %5 ], [ %17, %16 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %8
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = load i8*, i8** %9
store i8* %14, i8** %2
%15 = tail call i32 @fclose(i32* %11)
br label %16
16: ; preds = %7, %13
%17 = add nuw nsw i64 %8, 1
%18 = icmp eq i64 %17, %6
br i1 %18, label %19, label %7
19: ; preds = %16, %3
ret void
}