#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 check_args_validation(int, char **);
int /*<<< orphan*/ close_dump(int /*<<< orphan*/ *);
int get_dumpsize(int /*<<< orphan*/ *);
int /*<<< orphan*/ *open_dump(char *);
int read_tracebuffer(int /*<<< orphan*/ *, int);
int main(int argc, char **args) {
  FILE *file;
  int filesize, ret;
  if (-1 == check_args_validation(argc, args)) {
    return -1;
  }
  file = open_dump(args[1]);
  if (file == NULL) {
    return -1;
  }
  filesize = get_dumpsize(file);
  if (filesize <= 0) {
    close_dump(file);
    return -1;
  }
  ret = read_tracebuffer(file, filesize);
  close_dump(file);
  return ret;
}


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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <check_args_validation@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    118d <main+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <main+0xae>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <open_dump@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b5 <main+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <main+0xae>
mov    -0x18(%rbp),%rdi
call   1030 <get_dumpsize@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     11e0 <main+0x90>
mov    -0x18(%rbp),%rdi
call   1070 <close_dump@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <main+0xae>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <read_tracebuffer@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <close_dump@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
call   1060 <check_args_validation@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     119e <main+0x4e>
mov    0x8(%rbx),%rdi
call   1040 <open_dump@plt>
test   %rax,%rax
je     119e <main+0x4e>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <get_dumpsize@plt>
test   %eax,%eax
jle    1191 <main+0x41>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <read_tracebuffer@plt>
mov    %eax,%ebp
jmp    1196 <main+0x46>
mov    $0xffffffff,%ebp
mov    %r14,%rdi
call   1070 <close_dump@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main(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* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @check_args_validation(i32 %9, i8** %10)
%12 = icmp eq i32 -1, %11
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %37
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @open_dump(i8* %17)
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %14
store i32 -1, i32* %3
br label %37
22: ; preds = %14
%23 = load i32*, i32** %6
%24 = call i32 @get_dumpsize(i32* %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp sle i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32*, i32** %6
%29 = call i32 @close_dump(i32* %28)
store i32 -1, i32* %3
br label %37
30: ; preds = %22
%31 = load i32*, i32** %6
%32 = load i32, i32* %7
%33 = call i32 @read_tracebuffer(i32* %31, i32 %32)
store i32 %33, i32* %8
%34 = load i32*, i32** %6
%35 = call i32 @close_dump(i32* %34)
%36 = load i32, i32* %8
store i32 %36, i32* %3
br label %37
37: ; preds = %30, %27, %21, %13
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @check_args_validation(i32 %0, i8** %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @open_dump(i8* %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %18, label %10
10: ; preds = %5
%11 = tail call i32 @get_dumpsize(i32* %8)
%12 = icmp slt i32 %11, 1
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @read_tracebuffer(i32* %8, i32 %11)
br label %15
15: ; preds = %10, %13
%16 = phi i32 [ %14, %13 ], [ -1, %10 ]
%17 = tail call i32 @close_dump(i32* %8)
br label %18
18: ; preds = %15, %5, %2
%19 = phi i32 [ -1, %2 ], [ -1, %5 ], [ %16, %15 ]
ret i32 %19
}