#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*/ errno;
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *, ...);
int /*<<< orphan*/ **malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strcmp(char const *, char *);
char *strerror(int /*<<< orphan*/);
FILE **open_files(int argc, const char *argv[]) {
  FILE **files;
  int i;
  files = malloc(argc * sizeof(FILE *));
  if (!files) {
    fprintf(stderr, "%s: unable to allocate: %s\n", argv[0], strerror(errno));
    return NULL;
  }
  for (i = 1; i < argc; i++) {
    FILE *fh;
    if (!strcmp(argv[i], "-")) {
      fh = stdin;
    } else {
      fh = fopen(argv[i], "rb");
      if (!fh) {
        fprintf(stderr, "%s: %s: unable to open: %s\n", argv[0], argv[i],
                strerror(errno));
        return NULL;
      }
    }
    files[i - 1] = fh;
  }
  return files;
}


x86 assembly (clang, -O0):
<open_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c7 <open_files+0x77>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12c3 <open_files+0x173>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12bb <open_files+0x16b>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe2f(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    120e <open_files+0xbe>
mov    0x2de6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1298 <open_files+0x148>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdfd(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1293 <open_files+0x143>
mov    0x2d9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    %rax,%r8
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12c3 <open_files+0x173>
jmp    1298 <open_files+0x148>
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ce <open_files+0x7e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
lea    0x0(,%r15,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     121f <open_files+0xcf>
mov    %rax,%r13
cmp    $0x2,%r15d
jl     1252 <open_files+0x102>
mov    %r15d,%r12d
mov    $0x1,%ebp
lea    0xe89(%rip),%r15
jmp    11bc <open_files+0x6c>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x2e41(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%r13,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r12
je     1252 <open_files+0x102>
mov    (%r14,%rbp,8),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11a0 <open_files+0x50>
mov    %rbx,%rdi
lea    0xe45(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    11aa <open_files+0x5a>
mov    0x2dee(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%r15
mov    (%r14,%rbp,8),%r14
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe19(%rip),%rsi
xor    %r13d,%r13d
mov    %ebx,%edi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1252 <open_files+0x102>
mov    0x2db2(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%r14
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xdc0(%rip),%rsi
xor    %r13d,%r13d
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"%s: unable to allocate: %s\0A\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [28 x i8] c"%s: %s: unable to open: %s\0A\00"
define i32** @open_files(i32 %0, i8** %1) {
%3 = alloca i32**
%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
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 8
%12 = trunc i64 %11 to i32
%13 = call i32** @malloc(i32 %12)
store i32** %13, i32*** %6
%14 = load i32**, i32*** %6
%15 = icmp ne i32** %14, null
br i1 %15, label %24, label %16
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %22)
store i32** null, i32*** %3
br label %74
24: ; preds = %2
store i32 1, i32* %7
br label %25
25: ; preds = %69, %24
%26 = load i32, i32* %7
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %72
29: ; preds = %25
%30 = load i8**, i8*** %5
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 @strcmp(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp ne i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %29
%38 = load i32*, i32** @stdin
store i32* %38, i32** %8
br label %62
39: ; preds = %29
%40 = load i8**, i8*** %5
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %45, i32** %8
%46 = load i32*, i32** %8
%47 = icmp ne i32* %46, null
br i1 %47, label %61, label %48
48: ; preds = %39
%49 = load i32, i32* @stderr
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = load i8**, i8*** %5
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %52, i8* %57, i8* %59)
store i32** null, i32*** %3
br label %74
61: ; preds = %39
br label %62
62: ; preds = %61, %37
%63 = load i32*, i32** %8
%64 = load i32**, i32*** %6
%65 = load i32, i32* %7
%66 = sub nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32*, i32** %64, i64 %67
store i32* %63, i32** %68
br label %69
69: ; preds = %62
%70 = load i32, i32* %7
%71 = add nsw i32 %70, 1
store i32 %71, i32* %7
br label %25
72: ; preds = %25
%73 = load i32**, i32*** %6
store i32** %73, i32*** %3
br label %74
74: ; preds = %72, %48, %16
%75 = load i32**, i32*** %3
ret i32** %75
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"%s: unable to allocate: %s\0A\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [28 x i8] c"%s: %s: unable to open: %s\0A\00"
define noalias i32** @open_files(i32 %0, i8** nocapture %1) {
%3 = shl i32 %0, 3
%4 = tail call i32** @malloc(i32 %3)
%5 = icmp eq i32** %4, null
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %42
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %14)
br label %42
16: ; preds = %8, %36
%17 = phi i64 [ 1, %8 ], [ %40, %36 ]
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = load i32*, i32** @stdin
br label %36
24: ; preds = %16
%25 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = and i64 %17, 4294967295
%29 = getelementptr inbounds i8*, i8** %1, i64 %28
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %1
%32 = load i8*, i8** %29
%33 = load i32, i32* @errno
%34 = tail call i8* @strerror(i32 %33)
%35 = tail call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %31, i8* %32, i8* %34)
br label %42
36: ; preds = %24, %22
%37 = phi i32* [ %25, %24 ], [ %23, %22 ]
%38 = add nsw i64 %17, -1
%39 = getelementptr inbounds i32*, i32** %4, i64 %38
store i32* %37, i32** %39
%40 = add nuw nsw i64 %17, 1
%41 = icmp eq i64 %40, %9
br i1 %41, label %42, label %16
42: ; preds = %36, %6, %27, %10
%43 = phi i32** [ null, %27 ], [ null, %10 ], [ %4, %6 ], [ %4, %36 ]
ret i32** %43
}