#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 {
  size_t st_size;
  size_t st_blksize;
};
typedef size_t off_t;
typedef size_t blksize_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ fstat(int, struct stat *);
char *malloc(size_t);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ resparse(int, size_t, size_t, char *, size_t);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int ret = EXIT_FAILURE, fd = -1, flags = O_RDWR;
  struct stat st;
  off_t flen;
  blksize_t blksz;
  size_t bufsz = 65536;
  char *buf = NULL;
  if (argc != 2) {
    fprintf(stderr, "%s file\n", argv[0]);
    goto fail;
  }
  fd = open(argv[1], flags);
  if (fd < 0) {
    perror("open()");
    goto fail;
  }
  if (fstat(fd, &st) < 0) {
    perror("stat()");
    goto fail;
  }
  flen = st.st_size;
  blksz = st.st_blksize;
  if (blksz <= 0) {
    fprintf(stderr, "Fatal: blocksize = %i\n", (int)blksz);
    goto fail;
  }
  if (flen < 0) {
    fprintf(stderr, "Fatal: negative file size\n");
    goto fail;
  }
  flen -= flen % blksz;
  if (flen == 0)
    goto success;
  if (bufsz < (size_t)blksz) {
    bufsz = blksz;
  } else {
    bufsz = bufsz - bufsz % blksz;
  }
  buf = malloc(bufsz);
  if (buf == NULL) {
    perror("malloc()");
    goto fail;
  }
  if (!resparse(fd, flen, blksz, buf, bufsz))
    goto fail;
success:
  ret = EXIT_SUCCESS;
fail:
  if (fd >= 0)
    close(fd);
  if (buf != NULL)
    free(buf);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
movq   $0x10000,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f2 <main+0x72>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    136c <main+0x1ec>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1220 <main+0xa0>
lea    0xdf3(%rip),%rdi
call   1090 <perror@plt>
jmp    136c <main+0x1ec>
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   10a0 <fstat@plt>
cmp    $0x0,%rax
jge    1247 <main+0xc7>
lea    0xdd3(%rip),%rdi
call   1090 <perror@plt>
jmp    136c <main+0x1ec>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
ja     1284 <main+0x104>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rax
mov    %eax,%edx
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    136c <main+0x1ec>
cmpq   $0x0,-0x38(%rbp)
jae    12ab <main+0x12b>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xd8f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    136c <main+0x1ec>
mov    -0x38(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x40(%rbp)
mov    -0x38(%rbp),%rax
sub    %rdx,%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12d2 <main+0x152>
jmp    1360 <main+0x1e0>
mov    -0x48(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    12ed <main+0x16d>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    130c <main+0x18c>
mov    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x40(%rbp)
mov    -0x58(%rbp),%rax
sub    %rdx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1335 <main+0x1b5>
lea    0xd1e(%rip),%rdi
call   1090 <perror@plt>
jmp    136c <main+0x1ec>
mov    -0x18(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%r8
call   1050 <resparse@plt>
cmp    $0x0,%eax
jne    135b <main+0x1db>
jmp    136c <main+0x1ec>
jmp    1360 <main+0x1e0>
mov    0x2c61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     137e <main+0x1fe>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
cmpq   $0x0,-0x50(%rbp)
je     1392 <main+0x212>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e3b(%rip),%rax
mov    (%rax),%r14d
cmp    $0x2,%edi
jne    126f <main+0xef>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    0x8(%rsi),%rdi
mov    %eax,%esi
call   1080 <open@plt>
test   %eax,%eax
js     12c1 <main+0x141>
mov    %eax,%r15d
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10a0 <fstat@plt>
test   %rax,%rax
js     12cf <main+0x14f>
mov    0x10(%rsp),%rbx
test   %rbx,%rbx
je     128b <main+0x10b>
mov    0x8(%rsp),%rbp
mov    %rbp,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     12a6 <main+0x126>
mov    %rbp,%rax
xor    %edx,%edx
div    %rbx
sub    %rdx,%rbp
je     12b5 <main+0x135>
mov    %rbx,%r13
cmp    $0x10000,%rbx
ja     1227 <main+0xa7>
mov    $0x10000,%eax
xor    %edx,%edx
div    %ebx
mov    $0x10000,%r13d
sub    %rdx,%r13
mov    %r13,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     12d8 <main+0x158>
mov    %rax,%r12
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
mov    %r13,%r8
call   1050 <resparse@plt>
test   %eax,%eax
je     125d <main+0xdd>
mov    0x2d6e(%rip),%rax
mov    (%rax),%r14d
mov    %r15d,%edi
call   1040 <close@plt>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    12ec <main+0x16c>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd7e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12ec <main+0x16c>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12e4 <main+0x164>
mov    %ebp,%eax
xor    %edx,%edx
div    %ebx
sub    %rdx,%rbp
jne    1209 <main+0x89>
mov    0x2d0c(%rip),%rax
mov    (%rax),%r14d
jmp    12e4 <main+0x164>
lea    0xd41(%rip),%rdi
call   1090 <perror@plt>
jmp    12ec <main+0x16c>
lea    0xd3a(%rip),%rdi
jmp    12df <main+0x15f>
lea    0xd4f(%rip),%rdi
call   1090 <perror@plt>
mov    %r15d,%edi
call   1040 <close@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [9 x i8] c"%s file\0A\00"
@.str.1 = [7 x i8] c"open()\00"
@.str.2 = [7 x i8] c"stat()\00"
@.str.3 = [23 x i8] c"Fatal: blocksize = %i\0A\00"
@.str.4 = [27 x i8] c"Fatal: negative file size\0A\00"
@.str.5 = [9 x i8] c"malloc()\00"
@EXIT_SUCCESS = global i32 0
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
%9 = alloca %struct.stat
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %6
store i32 -1, i32* %7
%15 = load i32, i32* @O_RDWR
store i32 %15, i32* %8
store i64 65536, i64* %12
store i8* null, i8** %13
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 2
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %98
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* %8
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %98
34: ; preds = %24
%35 = load i32, i32* %7
%36 = call i64 @fstat(i32 %35, %struct.stat* %9)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %98
40: ; preds = %34
%41 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%42 = load i64, i64* %41
store i64 %42, i64* %10
%43 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 1
%44 = load i64, i64* %43
store i64 %44, i64* %11
%45 = load i64, i64* %11
%46 = icmp ule i64 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %40
%48 = load i32, i32* @stderr
%49 = load i64, i64* %11
%50 = trunc i64 %49 to i32
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %50)
br label %98
52: ; preds = %40
%53 = load i64, i64* %10
%54 = icmp ult i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %98
58: ; preds = %52
%59 = load i64, i64* %10
%60 = load i64, i64* %11
%61 = urem i64 %59, %60
%62 = load i64, i64* %10
%63 = sub i64 %62, %61
store i64 %63, i64* %10
%64 = load i64, i64* %10
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %58
br label %96
67: ; preds = %58
%68 = load i64, i64* %12
%69 = load i64, i64* %11
%70 = icmp ult i64 %68, %69
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = load i64, i64* %11
store i64 %72, i64* %12
br label %79
73: ; preds = %67
%74 = load i64, i64* %12
%75 = load i64, i64* %12
%76 = load i64, i64* %11
%77 = urem i64 %75, %76
%78 = sub i64 %74, %77
store i64 %78, i64* %12
br label %79
79: ; preds = %73, %71
%80 = load i64, i64* %12
%81 = call i8* @malloc(i64 %80)
store i8* %81, i8** %13
%82 = load i8*, i8** %13
%83 = icmp eq i8* %82, null
br i1 %83, label %84, label %86
84: ; preds = %79
%85 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %98
86: ; preds = %79
%87 = load i32, i32* %7
%88 = load i64, i64* %10
%89 = load i64, i64* %11
%90 = load i8*, i8** %13
%91 = load i64, i64* %12
%92 = call i32 @resparse(i32 %87, i64 %88, i64 %89, i8* %90, i64 %91)
%93 = icmp ne i32 %92, 0
br i1 %93, label %95, label %94
94: ; preds = %86
br label %98
95: ; preds = %86
br label %96
96: ; preds = %95, %66
%97 = load i32, i32* @EXIT_SUCCESS
store i32 %97, i32* %6
br label %98
98: ; preds = %96, %94, %84, %55, %47, %38, %32, %18
%99 = load i32, i32* %7
%100 = icmp sge i32 %99, 0
br i1 %100, label %101, label %104
101: ; preds = %98
%102 = load i32, i32* %7
%103 = call i32 @close(i32 %102)
br label %104
104: ; preds = %101, %98
%105 = load i8*, i8** %13
%106 = icmp ne i8* %105, null
br i1 %106, label %107, label %110
107: ; preds = %104
%108 = load i8*, i8** %13
%109 = call i32 @free(i8* %108)
br label %110
110: ; preds = %107, %104
%111 = load i32, i32* %6
ret i32 %111
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [9 x i8] c"%s file\0A\00"
@.str.1 = [7 x i8] c"open()\00"
@.str.2 = [7 x i8] c"stat()\00"
@.str.3 = [23 x i8] c"Fatal: blocksize = %i\0A\00"
@.str.5 = [9 x i8] c"malloc()\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = load i32, i32* @EXIT_FAILURE
%5 = load i32, i32* @O_RDWR
%6 = bitcast %struct.stat* %3 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %62
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @open(i8* %14, i32 %5)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %62
19: ; preds = %12
%20 = call i64 @fstat(i32 %15, %struct.stat* %3)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %60
24: ; preds = %19
%25 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%26 = load i64, i64* %25
%27 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%28 = load i64, i64* %27
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 0)
br label %60
33: ; preds = %24
%34 = urem i64 %26, %28
%35 = sub i64 %26, %34
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32, i32* @EXIT_SUCCESS
%39 = tail call i32 @close(i32 %15)
br label %62
40: ; preds = %33
%41 = icmp ugt i64 %28, 65536
br i1 %41, label %47, label %42
42: ; preds = %40
%43 = trunc i64 %28 to i32
%44 = urem i32 65536, %43
%45 = zext i32 %44 to i64
%46 = sub nuw nsw i64 65536, %45
br label %47
47: ; preds = %40, %42
%48 = phi i64 [ %46, %42 ], [ %28, %40 ]
%49 = tail call i8* @malloc(i64 %48)
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %60
53: ; preds = %47
%54 = tail call i32 @resparse(i32 %15, i64 %35, i64 %28, i8* %49, i64 %48)
%55 = icmp eq i32 %54, 0
%56 = load i32, i32* @EXIT_SUCCESS
%57 = select i1 %55, i32 %4, i32 %56
%58 = tail call i32 @close(i32 %15)
%59 = tail call i32 @free(i8* %49)
br label %62
60: ; preds = %51, %30, %22
%61 = tail call i32 @close(i32 %15)
br label %62
62: ; preds = %17, %8, %37, %60, %53
%63 = phi i32 [ %57, %53 ], [ %4, %60 ], [ %38, %37 ], [ %4, %8 ], [ %4, %17 ]
ret i32 %63
}