#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;
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;
  }
  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    0x2e7d(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jge    118a <main+0x4a>
movl   $0x1,-0x4(%rbp)
jmp    1244 <main+0x104>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    11b0 <main+0x70>
movl   $0x1,-0x4(%rbp)
jmp    1244 <main+0x104>
cmpq   $0x0,-0x20(%rbp)
jg     11c7 <main+0x87>
movl   $0x2,-0x4(%rbp)
jmp    1244 <main+0x104>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <lstat@plt>
cmp    $0x0,%rax
jge    11ed <main+0xad>
movl   $0x3,-0x4(%rbp)
jmp    1244 <main+0x104>
cmpq   $0x0,-0x20(%rbp)
jg     1204 <main+0xc4>
movl   $0x4,-0x4(%rbp)
jmp    1244 <main+0x104>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1060 <fstat@plt>
cmp    $0x0,%rax
jge    1226 <main+0xe6>
movl   $0x5,-0x4(%rbp)
jmp    1244 <main+0x104>
cmpq   $0x0,-0x20(%rbp)
jg     123d <main+0xfd>
movl   $0x6,-0x4(%rbp)
jmp    1244 <main+0x104>
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    0x2e98(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,%ebp
mov    $0x1,%eax
cmp    $0xffffffff,%ebp
jl     11d2 <main+0x92>
mov    (%rbx),%rdi
mov    %rsp,%rsi
call   1040 <stat@plt>
test   %rax,%rax
js     11b1 <main+0x71>
cmpq   $0x0,(%rsp)
jle    11b8 <main+0x78>
mov    (%rbx),%rdi
mov    %rsp,%rsi
call   1030 <lstat@plt>
test   %rax,%rax
js     11bf <main+0x7f>
cmpq   $0x0,(%rsp)
jle    11c6 <main+0x86>
mov    %rsp,%rsi
mov    %ebp,%edi
call   1060 <fstat@plt>
test   %rax,%rax
js     11cd <main+0x8d>
xor    %ecx,%ecx
cmpq   $0x0,(%rsp)
mov    $0x6,%eax
cmovg  %ecx,%eax
jmp    11d2 <main+0x92>
mov    $0x1,%eax
jmp    11d2 <main+0x92>
mov    $0x2,%eax
jmp    11d2 <main+0x92>
mov    $0x3,%eax
jmp    11d2 <main+0x92>
mov    $0x4,%eax
jmp    11d2 <main+0x92>
mov    $0x5,%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 %50
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 %50
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 %50
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 %50
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 %50
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 %50
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 %50
49: ; preds = %44
store i32 0, i32* %3
br label %50
50: ; preds = %49, %48, %43, %38, %33, %26, %21, %14
%51 = load i32, i32* %3
ret i32 %51
}

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 %33, 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 %31, 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 %31, 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 %31, label %21
21: ; preds = %17
%22 = load i64, i64* %14
%23 = icmp slt i64 %22, 1
br i1 %23, label %31, label %24
24: ; preds = %21
%25 = call i64 @fstat(i32 %6, %struct.stat* %3)
%26 = icmp slt i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %24
%28 = load i64, i64* %14
%29 = icmp slt i64 %28, 1
%30 = select i1 %29, i32 6, i32 0
br label %31
31: ; preds = %27, %24, %21, %17, %13, %8
%32 = phi i32 [ 1, %8 ], [ 2, %13 ], [ 3, %17 ], [ 4, %21 ], [ 5, %24 ], [ %30, %27 ]
br label %33
33: ; preds = %2, %31
%34 = phi i32 [ %32, %31 ], [ 1, %2 ]
ret i32 %34
}