#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;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ fstat(int, struct stat *);
scalar_t__ lstat(char *, struct stat *);
int open(char *, int /*<<< orphan*/);
scalar_t__ stat(char *, struct stat *);
int main(int argc, char **argv) {
  int file = 0;
  if ((file = open(argv[0], O_RDONLY)) < -1)
    return 1;
  struct stat fileStat;
  if (stat(argv[0], &fileStat) < 0)
    return 1;
  if (fileStat.st_size <= 0) {
    return 2;
  }
  if (lstat(argv[0], &fileStat) < 0)
    return 3;
  if (fileStat.st_size <= 0) {
    return 4;
  }
  if (fstat(file, &fileStat) < 0)
    return 5;
  if (fileStat.st_size <= 0) {
    return 6;
  }
  close(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jge    119a <main+0x4a>
movl   $0x1,-0x4(%rbp)
jmp    125c <main+0x10c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11c0 <main+0x70>
movl   $0x1,-0x4(%rbp)
jmp    125c <main+0x10c>
cmpq   $0x0,-0x20(%rbp)
jg     11d7 <main+0x87>
movl   $0x2,-0x4(%rbp)
jmp    125c <main+0x10c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
jge    11fd <main+0xad>
movl   $0x3,-0x4(%rbp)
jmp    125c <main+0x10c>
cmpq   $0x0,-0x20(%rbp)
jg     1214 <main+0xc4>
movl   $0x4,-0x4(%rbp)
jmp    125c <main+0x10c>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1070 <fstat@plt>
cmp    $0x0,%rax
jge    1236 <main+0xe6>
movl   $0x5,-0x4(%rbp)
jmp    125c <main+0x10c>
cmpq   $0x0,-0x20(%rbp)
jg     124d <main+0xfd>
movl   $0x6,-0x4(%rbp)
jmp    125c <main+0x10c>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    (%rsi),%rdi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebp
mov    $0x1,%eax
cmp    $0xffffffff,%ebp
jl     11ea <main+0x9a>
mov    (%rbx),%rdi
mov    %rsp,%rsi
call   1050 <stat@plt>
test   %rax,%rax
js     11c2 <main+0x72>
cmpq   $0x0,(%rsp)
jle    11c9 <main+0x79>
mov    (%rbx),%rdi
mov    %rsp,%rsi
call   1040 <lstat@plt>
test   %rax,%rax
js     11d0 <main+0x80>
cmpq   $0x0,(%rsp)
jle    11d7 <main+0x87>
mov    %rsp,%rsi
mov    %ebp,%edi
call   1070 <fstat@plt>
test   %rax,%rax
js     11de <main+0x8e>
cmpq   $0x0,(%rsp)
jle    11e5 <main+0x95>
mov    %ebp,%edi
call   1030 <close@plt>
xor    %eax,%eax
jmp    11ea <main+0x9a>
mov    $0x1,%eax
jmp    11ea <main+0x9a>
mov    $0x2,%eax
jmp    11ea <main+0x9a>
mov    $0x3,%eax
jmp    11ea <main+0x9a>
mov    $0x4,%eax
jmp    11ea <main+0x9a>
mov    $0x5,%eax
jmp    11ea <main+0x9a>
mov    $0x6,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %6
%13 = icmp slt i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %52
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i64 @stat(i8* %18, %struct.stat* %7)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 1, i32* %3
br label %52
22: ; preds = %15
%23 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%24 = load i64, i64* %23
%25 = icmp sle i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 2, i32* %3
br label %52
27: ; preds = %22
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i64 @lstat(i8* %30, %struct.stat* %7)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 3, i32* %3
br label %52
34: ; preds = %27
%35 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%36 = load i64, i64* %35
%37 = icmp sle i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 4, i32* %3
br label %52
39: ; preds = %34
%40 = load i32, i32* %6
%41 = call i64 @fstat(i32 %40, %struct.stat* %7)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 5, i32* %3
br label %52
44: ; preds = %39
%45 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%46 = load i64, i64* %45
%47 = icmp sle i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %44
store i32 6, i32* %3
br label %52
49: ; preds = %44
%50 = load i32, i32* %6
%51 = call i32 @close(i32 %50)
store i32 0, i32* %3
br label %52
52: ; preds = %49, %48, %43, %38, %33, %26, %21, %14
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = load i8*, i8** %1
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %4, i32 %5)
%7 = icmp slt i32 %6, -1
br i1 %7, label %34, label %8
8: ; preds = %2
%9 = bitcast %struct.stat* %3 to i8*
%10 = load i8*, i8** %1
%11 = call i64 @stat(i8* %10, %struct.stat* %3)
%12 = icmp slt i64 %11, 0
br i1 %12, label %32, label %13
13: ; preds = %8
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%15 = load i64, i64* %14
%16 = icmp slt i64 %15, 1
br i1 %16, label %32, label %17
17: ; preds = %13
%18 = load i8*, i8** %1
%19 = call i64 @lstat(i8* %18, %struct.stat* %3)
%20 = icmp slt i64 %19, 0
br i1 %20, label %32, label %21
21: ; preds = %17
%22 = load i64, i64* %14
%23 = icmp slt i64 %22, 1
br i1 %23, label %32, label %24
24: ; preds = %21
%25 = call i64 @fstat(i32 %6, %struct.stat* %3)
%26 = icmp slt i64 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = load i64, i64* %14
%29 = icmp slt i64 %28, 1
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 @close(i32 %6)
br label %32
32: ; preds = %27, %24, %21, %17, %13, %8, %30
%33 = phi i32 [ 0, %30 ], [ 1, %8 ], [ 2, %13 ], [ 3, %17 ], [ 4, %21 ], [ 5, %24 ], [ 6, %27 ]
br label %34
34: ; preds = %2, %32
%35 = phi i32 [ %33, %32 ], [ 1, %2 ]
ret i32 %35
}