#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
void print_arg_files(int arg_count, char **arg_files) {
  int fno;
  int fd;
  char test_file_line[1024];
  if (arg_count > 2) {
    for (fno = 2; fno < arg_count; ++fno) {
      printf("\tTesting opening file %s\n", arg_files[fno]);
      fd = open(arg_files[fno], O_RDONLY);
      if (fd == -1) {
        perror(arg_files[fno]);
      } else {
        memset(test_file_line, 0, 1024);
        while (read(fd, test_file_line, 1023) > 0) {
          printf("\t\t%s", test_file_line);
          memset(test_file_line, 0, 1024);
        }
      }
    }
    printf("\n\n");
  }
}


x86 assembly (clang, -O0):
<print_arg_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jle    125a <print_arg_files+0x10a>
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    124c <print_arg_files+0xfc>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11d6 <print_arg_files+0x86>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <perror@plt>
jmp    1239 <print_arg_files+0xe9>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x3ff,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jle    1234 <print_arg_files+0xe4>
lea    -0x420(%rbp),%rsi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
jmp    11e9 <print_arg_files+0x99>
jmp    1239 <print_arg_files+0xe9>
jmp    123e <print_arg_files+0xee>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1173 <print_arg_files+0x23>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_arg_files>:
cmp    $0x3,%edi
jl     122f <print_arg_files+0xcf>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r15
mov    %edi,%r13d
mov    $0x2,%r14d
mov    %rsp,%rbx
lea    0xe8a(%rip),%r12
jmp    11a9 <print_arg_files+0x49>
mov    (%r15,%r14,8),%rdi
call   1080 <perror@plt>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    %r13,%r14
je     1212 <print_arg_files+0xb2>
mov    (%r15,%r14,8),%rsi
lea    0xe4c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%r14,8),%rdi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1192 <print_arg_files+0x32>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1060 <read@plt>
test   %rax,%rax
jle    11a0 <print_arg_files+0x40>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e0 <print_arg_files+0x80>
lea    0xdff(%rip),%rdi
call   1030 <puts@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"\09Testing opening file %s\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"\09\09%s\00"
@.str.2 = [3 x i8] c"\0A\0A\00"
define void @print_arg_files(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1024 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 2
br i1 %9, label %10, label %58
10: ; preds = %2
store i32 2, i32* %5
br label %11
11: ; preds = %53, %10
%12 = load i32, i32* %5
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %56
15: ; preds = %11
%16 = load i8**, i8*** %4
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i8**, i8*** %4
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* %26, i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %38
31: ; preds = %15
%32 = load i8**, i8*** %4
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 @perror(i8* %36)
br label %52
38: ; preds = %15
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%40 = call i32 @memset(i8* %39, i32 0, i32 1024)
br label %41
41: ; preds = %46, %38
%42 = load i32, i32* %6
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%44 = call i64 @read(i32 %42, i8* %43, i32 1023)
%45 = icmp sgt i64 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %41
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %47)
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%50 = call i32 @memset(i8* %49, i32 0, i32 1024)
br label %41
51: ; preds = %41
br label %52
52: ; preds = %51, %31
br label %53
53: ; preds = %52
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %11
56: ; preds = %11
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %58
58: ; preds = %56, %2
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"\09Testing opening file %s\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"\09\09%s\00"
@str = [2 x i8] c"\0A\00"
define void @print_arg_files(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 2
br i1 %5, label %6, label %34
6: ; preds = %2
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %29
%9 = phi i64 [ 2, %6 ], [ %30, %29 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %10
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %8
%18 = load i8*, i8** %10
%19 = call i32 @perror(i8* %18)
br label %29
20: ; preds = %8
%21 = call i32 @memset(i8* %4, i32 0, i32 1024)
%22 = call i64 @read(i32 %15, i8* %4, i32 1023)
%23 = icmp sgt i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %20, %24
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%26 = call i32 @memset(i8* %4, i32 0, i32 1024)
%27 = call i64 @read(i32 %15, i8* %4, i32 1023)
%28 = icmp sgt i64 %27, 0
br i1 %28, label %24, label %29
29: ; preds = %24, %20, %17
%30 = add nuw nsw i64 %9, 1
%31 = icmp eq i64 %30, %7
br i1 %31, label %32, label %8
32: ; preds = %29
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %32, %2
ret void
}