#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ file_name(char *);
int /*<<< orphan*/ file_open(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int optind;
int /*<<< orphan*/ perror(char *);
void argvfile(int argc, char *argv[], int p) {
  FILE *f;
  int i;
  for (i = optind; i < argc; i++) {
    f = fopen(argv[i], "r");
    if (!f) {
      perror(argv[i]);
      exit(1);
    }
    if (!p) {
      file_open(f);
    } else {
      file_name(argv[i]);
    }
    fclose(f);
  }
}


x86 assembly (clang, -O0):
<argvfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    120c <argvfile+0xac>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe63(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cc <argvfile+0x6c>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    11e4 <argvfile+0x84>
mov    -0x20(%rbp),%rdi
call   1040 <file_open@plt>
jmp    11f5 <argvfile+0x95>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <file_name@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117e <argvfile+0x1e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argvfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e76(%rip),%rax
movslq (%rax),%rax
cmp    %edi,%eax
jge    11df <argvfile+0x7f>
mov    %edx,%r15d
mov    %edi,%r12d
lea    (%rsi,%rax,8),%r13
sub    %eax,%r12d
xor    %ebx,%ebx
lea    0xe71(%rip),%r14
jmp    11bb <argvfile+0x5b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,8),%rdi
call   1030 <file_name@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
add    $0x1,%rbx
cmp    %ebx,%r12d
je     11df <argvfile+0x7f>
mov    0x0(%r13,%rbx,8),%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ee <argvfile+0x8e>
mov    %rax,%rbp
test   %r15d,%r15d
jne    11a0 <argvfile+0x40>
mov    %rbp,%rdi
call   1040 <file_open@plt>
jmp    11aa <argvfile+0x4a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%r13,%rbx,8),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@optind = global i32 0
@.str = [2 x i8] c"r\00"
define void @argvfile(i32 %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
%9 = load i32, i32* @optind
store i32 %9, i32* %8
br label %10
10: ; preds = %47, %3
%11 = load i32, i32* %8
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %50
14: ; preds = %10
%15 = load i8**, i8*** %5
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = icmp ne i32* %21, null
br i1 %22, label %31, label %23
23: ; preds = %14
%24 = load i8**, i8*** %5
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @perror(i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %14
%32 = load i32, i32* %6
%33 = icmp ne i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32*, i32** %7
%36 = call i32 @file_open(i32* %35)
br label %44
37: ; preds = %31
%38 = load i8**, i8*** %5
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 @file_name(i8* %42)
br label %44
44: ; preds = %37, %34
%45 = load i32*, i32** %7
%46 = call i32 @fclose(i32* %45)
br label %47
47: ; preds = %44
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %10
50: ; preds = %10
ret void
}

LLVM IR (-O2):
@optind = global i32 0
@.str = [2 x i8] c"r\00"
define void @argvfile(i32 %0, i8** nocapture %1, i32 %2) {
%4 = load i32, i32* @optind
%5 = icmp slt i32 %4, %0
br i1 %5, label %6, label %30
6: ; preds = %3
%7 = icmp eq i32 %2, 0
%8 = sext i32 %4 to i64
br label %9
9: ; preds = %6, %25
%10 = phi i64 [ %8, %6 ], [ %27, %25 ]
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = load i8*, i8** %11
%17 = tail call i32 @perror(i8* %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %9
br i1 %7, label %20, label %22
20: ; preds = %19
%21 = tail call i32 @file_open(i32* %13)
br label %25
22: ; preds = %19
%23 = load i8*, i8** %11
%24 = tail call i32 @file_name(i8* %23)
br label %25
25: ; preds = %22, %20
%26 = tail call i32 @fclose(i32* %13)
%27 = add nsw i64 %10, 1
%28 = trunc i64 %27 to i32
%29 = icmp eq i32 %28, %0
br i1 %29, label %30, label %9
30: ; preds = %25, %3
ret void
}