#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*/ uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ cut_file(int /*<<< orphan*/ *, size_t);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(int /*<<< orphan*/ *, int, size_t,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  if (argc <= 1) {
    usage();
    return -1;
  }
  uint8_t *src = NULL;
  size_t src_size = 0u;
  {
    FILE *fh = fopen(argv[1], "rb");
    if (fh == NULL) {
      printf("error: can't open %s\n", argv[1]);
      return -2;
    }
    fseek(fh, 0, SEEK_END);
    src_size = ftell(fh);
    fseek(fh, 0, SEEK_SET);
    src = (uint8_t *)malloc(src_size);
    if (src != NULL) {
      fread(src, 1, src_size, fh);
    }
    fclose(fh);
  }
  if (src == NULL) {
    return -3;
  }
  cut_file(src, src_size);
  free(src);
}


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)
cmpl   $0x1,-0x8(%rbp)
jg     11d3 <main+0x33>
mov    $0x0,%al
call   10b0 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12bf <main+0x11f>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0e(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1226 <main+0x86>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdee(%rip),%rdi
call   1060 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12bf <main+0x11f>
mov    -0x28(%rbp),%rdi
mov    0x2db7(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d86(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1289 <main+0xe9>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x18(%rbp)
jne    12a9 <main+0x109>
movl   $0xfffffffd,-0x4(%rbp)
jmp    12bf <main+0x11f>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <cut_file@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     11bd <main+0x1d>
xor    %eax,%eax
call   10b0 <usage@plt>
mov    $0xffffffff,%ebp
jmp    126f <main+0xcf>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe35(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     124b <main+0xab>
mov    %rax,%rbx
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %rax,%r14
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r14,%rdi
call   1090 <malloc@plt>
test   %rax,%rax
je     1262 <main+0xc2>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <cut_file@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    126f <main+0xcf>
mov    0x8(%rbp),%rsi
lea    0xdad(%rip),%rdi
call   1060 <printf@plt>
mov    $0xfffffffe,%ebp
jmp    126f <main+0xcf>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0xfffffffd,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [22 x i8] c"error: can't open %s\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %30
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i8*, i8** %7
%13 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %30
14: ; preds = %6
%15 = load i32, i32* @SEEK_END
%16 = tail call i32 @fseek(i32* %9, i32 0, i32 %15)
%17 = tail call i64 @ftell(i32* %9)
%18 = load i32, i32* @SEEK_SET
%19 = tail call i32 @fseek(i32* %9, i32 0, i32 %18)
%20 = tail call i64 @malloc(i64 %17)
%21 = inttoptr i64 %20 to i32*
%22 = icmp eq i64 %20, 0
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = tail call i32 @fclose(i32* %9)
br label %30
25: ; preds = %14
%26 = tail call i32 @fread(i32* %21, i32 1, i64 %17, i32* %9)
%27 = tail call i32 @fclose(i32* %9)
%28 = tail call i32 @cut_file(i32* %21, i64 %17)
%29 = tail call i32 @free(i32* %21)
br label %30
30: ; preds = %23, %11, %25, %4
%31 = phi i32 [ -1, %4 ], [ 0, %25 ], [ -2, %11 ], [ -3, %23 ]
ret i32 %31
}