#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 */
struct stat {
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(unsigned char *, int, scalar_t__, int /*<<< orphan*/ *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ scan_libs(unsigned char *, scalar_t__);
scalar_t__ stat(char *, struct stat *);
int main(int argc, char **argv) {
  struct stat statbuf;
  FILE *infile;
  unsigned char *buffer = NULL;
  if (argc == 2) {
    if (stat(argv[1], &statbuf) >= 0) {
      if (statbuf.st_size > 0) {
        buffer = (unsigned char *)malloc(statbuf.st_size);
        if (buffer != NULL) {
          infile = fopen(argv[1], "rb");
          if (infile) {
            if (fread(buffer, 1, statbuf.st_size, infile) == statbuf.st_size) {
              scan_libs(buffer, statbuf.st_size);
            } else {
              fclose(infile);
            }
          }
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    123d <main+0xdd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jl     1238 <main+0xd8>
cmpq   $0x0,-0x18(%rbp)
jle    1233 <main+0xd3>
mov    -0x18(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     122e <main+0xce>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1229 <main+0xc9>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    -0x18(%rbp),%rax
jne    121b <main+0xbb>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <scan_libs@plt>
jmp    1224 <main+0xc4>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1229 <main+0xc9>
jmp    122e <main+0xce>
jmp    1233 <main+0xd3>
jmp    1238 <main+0xd8>
jmp    123d <main+0xdd>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11da <main+0x7a>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
call   1050 <stat@plt>
test   %rax,%rax
js     11da <main+0x7a>
mov    (%rsp),%rdi
test   %rdi,%rdi
jle    11da <main+0x7a>
call   1070 <malloc@plt>
test   %rax,%rax
je     11da <main+0x7a>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
lea    0xe62(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11da <main+0x7a>
mov    %rax,%rbx
mov    (%rsp),%rdx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    (%rsp),%rax
jne    11d2 <main+0x72>
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <scan_libs@plt>
jmp    11da <main+0x7a>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [3 x i8] c"rb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %57
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @stat(i8* %14, %struct.stat* %6)
%16 = icmp sge i64 %15, 0
br i1 %16, label %17, label %56
17: ; preds = %11
%18 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%19 = load i64, i64* %18
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %55
21: ; preds = %17
%22 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%23 = load i64, i64* %22
%24 = call i64 @malloc(i64 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %8
%26 = load i8*, i8** %8
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %54
28: ; preds = %21
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i32*, i32** %7
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %53
35: ; preds = %28
%36 = load i8*, i8** %8
%37 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%38 = load i64, i64* %37
%39 = load i32*, i32** %7
%40 = call i64 @fread(i8* %36, i32 1, i64 %38, i32* %39)
%41 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%42 = load i64, i64* %41
%43 = icmp eq i64 %40, %42
br i1 %43, label %44, label %49
44: ; preds = %35
%45 = load i8*, i8** %8
%46 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%47 = load i64, i64* %46
%48 = call i32 @scan_libs(i8* %45, i64 %47)
br label %52
49: ; preds = %35
%50 = load i32*, i32** %7
%51 = call i32 @fclose(i32* %50)
br label %52
52: ; preds = %49, %44
br label %53
53: ; preds = %52, %28
br label %54
54: ; preds = %53, %21
br label %55
55: ; preds = %54, %17
br label %56
56: ; preds = %55, %11
br label %57
57: ; preds = %56, %2
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [3 x i8] c"rb\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %32
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i64 @stat(i8* %8, %struct.stat* %3)
%10 = icmp sgt i64 %9, -1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%12 = load i64, i64* %11
%13 = icmp sgt i64 %12, 0
%14 = select i1 %10, i1 %13, i1 false
br i1 %14, label %15, label %32
15: ; preds = %6
%16 = call i64 @malloc(i64 %12)
%17 = inttoptr i64 %16 to i8*
%18 = icmp eq i64 %16, 0
br i1 %18, label %32, label %19
19: ; preds = %15
%20 = load i8*, i8** %7
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %32, label %23
23: ; preds = %19
%24 = load i64, i64* %11
%25 = call i64 @fread(i8* %17, i32 1, i64 %24, i32* %21)
%26 = load i64, i64* %11
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @scan_libs(i8* %17, i64 %25)
br label %32
30: ; preds = %23
%31 = call i32 @fclose(i32* %21)
br label %32
32: ; preds = %6, %15, %28, %30, %19, %2
ret i32 0
}