#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*/ perror(char *);
FILE *next_file(int *argcp, char ***argvp) {
  FILE *ret = 0;
  if (*argcp <= 0)
    return 0;
  while (*argcp && !ret) {
    ret = fopen((*argvp)[0], "r");
    if (!ret)
      perror((*argvp)[0]);
    (*argvp)++;
    (*argcp)--;
  }
  return ret;
}


x86 assembly (clang, -O0):
<next_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jg     1152 <next_file+0x32>
movq   $0x0,-0x8(%rbp)
jmp    11e0 <next_file+0xc0>
jmp    1157 <next_file+0x37>
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmpl   $0x0,(%rcx)
mov    %al,-0x21(%rbp)
je     1176 <next_file+0x56>
cmpq   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1186 <next_file+0x66>
jmp    11d8 <next_file+0xb8>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rdi
lea    0xe69(%rip),%rsi
call   1030 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ba <next_file+0x9a>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rdi
call   1040 <perror@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x8,%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
jmp    1157 <next_file+0x37>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmpl   $0x0,(%rdi)
jle    1181 <next_file+0x61>
mov    %rsi,%r12
mov    %rdi,%r14
mov    (%rsi),%rax
lea    0xec3(%rip),%r15
nopl   (%rax)
mov    (%rax),%rdi
mov    %r15,%rsi
call   1030 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1173 <next_file+0x53>
mov    (%r12),%rax
add    $0x8,%rax
mov    %rax,(%r12)
mov    (%r14),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%r14)
test   %rbx,%rbx
jne    1183 <next_file+0x63>
test   %ecx,%ecx
jne    1140 <next_file+0x20>
jmp    1183 <next_file+0x63>
mov    (%r12),%rax
mov    (%rax),%rdi
call   1040 <perror@plt>
jmp    1153 <next_file+0x33>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32* @next_file(i32* nocapture %0, i8*** nocapture %1) {
%3 = load i32, i32* %0
%4 = icmp slt i32 %3, 1
br i1 %4, label %23, label %5
5: ; preds = %2
%6 = load i8**, i8*** %1
br label %7
7: ; preds = %5, %16
%8 = phi i8** [ %6, %5 ], [ %18, %16 ]
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i8**, i8*** %1
%14 = load i8*, i8** %13
%15 = tail call i32 @perror(i8* %14)
br label %16
16: ; preds = %12, %7
%17 = load i8**, i8*** %1
%18 = getelementptr inbounds i8*, i8** %17, i64 1
store i8** %18, i8*** %1
%19 = load i32, i32* %0
%20 = add nsw i32 %19, -1
store i32 %20, i32* %0
%21 = icmp ne i32 %20, 0
%22 = and i1 %11, %21
br i1 %22, label %7, label %23
23: ; preds = %16, %2
%24 = phi i32* [ null, %2 ], [ %10, %16 ]
ret i32* %24
}