#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 {
  int /*<<< orphan*/ st_size;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fstat(int, struct stat *);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ parse(int, int /*<<< orphan*/, char const **);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *path;
  int fd;
  struct stat st;
  const char *error;
  error = malloc(512);
  path = argv[1];
  if (!path)
    fprintf(stderr, "No file given!!!\n");
  fd = open(path, O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "open failed\n");
    exit(1);
  }
  if (fstat(fd, &st) < 0) {
    fprintf(stderr, "Stat failed\n");
    exit(1);
  }
  if (!parse(fd, st.st_size, &error)) {
    fprintf(stderr, "Parsing failed: %s\n", error);
    exit(1);
  }
  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)
mov    $0x200,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b2 <main+0x52>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11f2 <main+0x92>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0x0,%rax
jge    1229 <main+0xc9>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
lea    -0x28(%rbp),%rdx
call   1060 <parse@plt>
cmp    $0x0,%eax
jne    1266 <main+0x106>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdd7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    $0x200,%edi
call   1040 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    0x8(%rbx),%rbx
test   %rbx,%rbx
jne    1197 <main+0x37>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
test   %eax,%eax
js     11d8 <main+0x78>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
call   1080 <fstat@plt>
test   %rax,%rax
js     11ea <main+0x8a>
mov    (%rsp),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1060 <parse@plt>
test   %eax,%eax
je     120b <main+0xab>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
jmp    11fa <main+0x9a>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
lea    0xe0c(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"No file given!!!\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"open failed\0A\00"
@.str.2 = [13 x i8] c"Stat failed\0A\00"
@.str.3 = [20 x i8] c"Parsing failed: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.stat
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i8* @malloc(i32 512)
store i8* %10, i8** %9
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %16, %2
%20 = load i8*, i8** %6
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %19
%30 = load i32, i32* %7
%31 = call i64 @fstat(i32 %30, %struct.stat* %8)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %29
%38 = load i32, i32* %7
%39 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 @parse(i32 %38, i32 %40, i8** %9)
%42 = icmp ne i32 %41, 0
br i1 %42, label %48, label %43
43: ; preds = %37
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %9
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %37
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"No file given!!!\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"open failed\0A\00"
@.str.2 = [13 x i8] c"Stat failed\0A\00"
@.str.3 = [20 x i8] c"Parsing failed: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca i8*
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = tail call dereferenceable_or_null(512) i8* @malloc(i32 512)
store i8* %7, i8** %4
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %11, %2
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @open(i8* %9, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = call i64 @fstat(i32 %16, %struct.stat* %3)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %22
%30 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 @parse(i32 %16, i32 %31, i8** %4)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %4
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %29
ret i32 0
}