#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*/ decode(size_t, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t 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*/ *);
size_t fwrite(int /*<<< orphan*/ *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(size_t);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *ip = NULL, *op = NULL;
  uint8_t *buf;
  size_t i, buf_size;
  int ret = 0;
  if (argc < 3) {
    printf("Usage: %s <input> <output>\n", argv[0]);
    ret = -1;
    goto end;
  }
  if (!(ip = fopen(argv[1], "rb"))) {
    printf("Error: Cannot open %s!\n", argv[1]);
    ret = -1;
    goto end;
  }
  fseek(ip, 0, SEEK_END);
  buf_size = ftell(ip);
  if (!(buf = malloc(buf_size))) {
    printf("Error: Cannot allocate input buffer of size %zu!\n", buf_size);
    ret = -1;
    goto end_buf;
  }
  rewind(ip);
  if (fread(buf, sizeof(*buf), buf_size / sizeof(*buf), ip) !=
      buf_size / sizeof(*buf)) {
    perror(NULL);
    printf("Error: Cannot read %zu bytes!\n", buf_size);
    ret = -1;
    goto end_buf;
  }
  for (i = 0; i < buf_size; i++) {
    buf[i] = decode(i, buf[i]);
  }
  if (!(op = fopen(argv[2], "wb"))) {
    printf("Error: Cannot open %s!\n", argv[2]);
    ret = -1;
    goto end_buf;
  }
  if (fwrite(buf, sizeof(*buf), buf_size / sizeof(*buf), op) !=
      buf_size / sizeof(*buf)) {
    printf("Error: Cannot write to output file!\n");
    ret = -1;
  }
  fclose(op);
end_buf:
  free(buf);
  fclose(ip);
end:
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1218 <main+0x58>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x3c(%rbp)
jmp    13f4 <main+0x234>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf5(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    125c <main+0x9c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x3c(%rbp)
jmp    13f4 <main+0x234>
mov    -0x18(%rbp),%rdi
mov    0x2d81(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12b2 <main+0xf2>
mov    -0x38(%rbp),%rsi
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x3c(%rbp)
jmp    13e2 <main+0x222>
mov    -0x18(%rbp),%rdi
call   1070 <rewind@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rdx
shr    $0x2,%rdx
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
call   1040 <fread@plt>
mov    -0x38(%rbp),%rcx
shr    $0x2,%rcx
cmp    %rcx,%rax
je     130d <main+0x14d>
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <perror@plt>
mov    -0x38(%rbp),%rsi
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x3c(%rbp)
jmp    13e2 <main+0x222>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    1355 <main+0x195>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   10b0 <decode@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1315 <main+0x155>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd24(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1399 <main+0x1d9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xc99(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x3c(%rbp)
jmp    13e2 <main+0x222>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rdx
shr    $0x2,%rdx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   10e0 <fwrite@plt>
mov    -0x38(%rbp),%rcx
shr    $0x2,%rcx
cmp    %rcx,%rax
je     13d9 <main+0x219>
lea    0xcc0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
cmp    $0x2,%edi
jg     11f2 <main+0x22>
mov    (%r15),%rsi
lea    0xe13(%rip),%rdi
jmp    12ef <main+0x11f>
mov    0x8(%r15),%rdi
lea    0xe1f(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     12e4 <main+0x114>
mov    %rax,%r14
mov    0x2dd3(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r14,%rdi
call   1090 <ftell@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   10a0 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12fd <main+0x12d>
mov    %r14,%rdi
call   1080 <rewind@plt>
mov    %r12,%r13
shr    $0x2,%r13
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r13,%rdx
mov    %r14,%rcx
call   1050 <fread@plt>
cmp    %r13,%rax
jne    1341 <main+0x171>
test   %r12,%r12
je     1297 <main+0xc7>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx,%rbp,4),%esi
mov    %rbp,%rdi
call   10c0 <decode@plt>
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1280 <main+0xb0>
mov    0x10(%r15),%rdi
lea    0xde6(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1309 <main+0x139>
mov    %rax,%r12
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r13,%rdx
mov    %rax,%rcx
call   10f0 <fwrite@plt>
xor    %ebp,%ebp
cmp    %r13,%rax
je     12da <main+0x10a>
lea    0xdbb(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebp
mov    %r12,%rdi
call   1060 <fclose@plt>
jmp    1320 <main+0x150>
mov    0x8(%r15),%rsi
lea    0xd30(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%ebp
jmp    1330 <main+0x160>
lea    0xd33(%rip),%rdi
mov    %r12,%rsi
jmp    1314 <main+0x144>
mov    0x10(%r15),%rsi
lea    0xd0b(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   10e0 <perror@plt>
lea    0xd1a(%rip),%rdi
jmp    1304 <main+0x134>

LLVM IR (-O0):
@.str = [28 x i8] c"Usage: %s <input> <output>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [24 x i8] c"Error: Cannot open %s!\0A\00"
@SEEK_END = global i32 0
@.str.3 = [50 x i8] c"Error: Cannot allocate input buffer of size %zu!\0A\00"
@.str.4 = [31 x i8] c"Error: Cannot read %zu bytes!\0A\00"
@.str.5 = [3 x i8] c"wb\00"
@.str.6 = [37 x i8] c"Error: Cannot write to output file!\0A\00"
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 i64
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32* null, i32** %7
store i32 0, i32* %11
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 -1, i32* %11
br label %105
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = icmp ne i32* %23, null
br i1 %24, label %30, label %25
25: ; preds = %19
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %28)
store i32 -1, i32* %11
br label %105
30: ; preds = %19
%31 = load i32*, i32** %6
%32 = load i32, i32* @SEEK_END
%33 = call i32 @fseek(i32* %31, i32 0, i32 %32)
%34 = load i32*, i32** %6
%35 = call i64 @ftell(i32* %34)
store i64 %35, i64* %10
%36 = load i64, i64* %10
%37 = call i32* @malloc(i64 %36)
store i32* %37, i32** %8
%38 = icmp ne i32* %37, null
br i1 %38, label %42, label %39
39: ; preds = %30
%40 = load i64, i64* %10
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i64 %40)
store i32 -1, i32* %11
br label %100
42: ; preds = %30
%43 = load i32*, i32** %6
%44 = call i32 @rewind(i32* %43)
%45 = load i32*, i32** %8
%46 = load i64, i64* %10
%47 = udiv i64 %46, 4
%48 = load i32*, i32** %6
%49 = call i64 @fread(i32* %45, i32 4, i64 %47, i32* %48)
%50 = load i64, i64* %10
%51 = udiv i64 %50, 4
%52 = icmp ne i64 %49, %51
br i1 %52, label %53, label %57
53: ; preds = %42
%54 = call i32 @perror(i32* null)
%55 = load i64, i64* %10
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i64 %55)
store i32 -1, i32* %11
br label %100
57: ; preds = %42
store i64 0, i64* %9
br label %58
58: ; preds = %72, %57
%59 = load i64, i64* %9
%60 = load i64, i64* %10
%61 = icmp ult i64 %59, %60
br i1 %61, label %62, label %75
62: ; preds = %58
%63 = load i64, i64* %9
%64 = load i32*, i32** %8
%65 = load i64, i64* %9
%66 = getelementptr inbounds i32, i32* %64, i64 %65
%67 = load i32, i32* %66
%68 = call i32 @decode(i64 %63, i32 %67)
%69 = load i32*, i32** %8
%70 = load i64, i64* %9
%71 = getelementptr inbounds i32, i32* %69, i64 %70
store i32 %68, i32* %71
br label %72
72: ; preds = %62
%73 = load i64, i64* %9
%74 = add i64 %73, 1
store i64 %74, i64* %9
br label %58
75: ; preds = %58
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 2
%78 = load i8*, i8** %77
%79 = call i32* @fopen(i8* %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %79, i32** %7
%80 = icmp ne i32* %79, null
br i1 %80, label %86, label %81
81: ; preds = %75
%82 = load i8**, i8*** %5
%83 = getelementptr inbounds i8*, i8** %82, i64 2
%84 = load i8*, i8** %83
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %84)
store i32 -1, i32* %11
br label %100
86: ; preds = %75
%87 = load i32*, i32** %8
%88 = load i64, i64* %10
%89 = udiv i64 %88, 4
%90 = load i32*, i32** %7
%91 = call i64 @fwrite(i32* %87, i32 4, i64 %89, i32* %90)
%92 = load i64, i64* %10
%93 = udiv i64 %92, 4
%94 = icmp ne i64 %91, %93
br i1 %94, label %95, label %97
95: ; preds = %86
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %11
br label %97
97: ; preds = %95, %86
%98 = load i32*, i32** %7
%99 = call i32 @fclose(i32* %98)
br label %100
100: ; preds = %97, %81, %53, %39
%101 = load i32*, i32** %8
%102 = call i32 @free(i32* %101)
%103 = load i32*, i32** %6
%104 = call i32 @fclose(i32* %103)
br label %105
105: ; preds = %100, %25, %14
%106 = load i32, i32* %11
ret i32 %106
}

LLVM IR (-O2):
@.str = [28 x i8] c"Usage: %s <input> <output>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [24 x i8] c"Error: Cannot open %s!\0A\00"
@SEEK_END = global i32 0
@.str.3 = [50 x i8] c"Error: Cannot allocate input buffer of size %zu!\0A\00"
@.str.4 = [31 x i8] c"Error: Cannot read %zu bytes!\0A\00"
@.str.5 = [3 x i8] c"wb\00"
@str = [36 x i8] c"Error: Cannot write to output file!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %60
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i8*, i8** %8
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %60
15: ; preds = %7
%16 = load i32, i32* @SEEK_END
%17 = tail call i32 @fseek(i32* %10, i32 0, i32 %16)
%18 = tail call i64 @ftell(i32* %10)
%19 = tail call i32* @malloc(i64 %18)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i64 %18)
br label %56
23: ; preds = %15
%24 = tail call i32 @rewind(i32* %10)
%25 = lshr i64 %18, 2
%26 = tail call i64 @fread(i32* %19, i32 4, i64 %25, i32* %10)
%27 = icmp eq i64 %26, %25
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = icmp eq i64 %18, 0
br i1 %29, label %40, label %33
30: ; preds = %23
%31 = tail call i32 @perror(i32* null)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i64 %18)
br label %56
33: ; preds = %28, %33
%34 = phi i64 [ %38, %33 ], [ 0, %28 ]
%35 = getelementptr inbounds i32, i32* %19, i64 %34
%36 = load i32, i32* %35
%37 = tail call i32 @decode(i64 %34, i32 %36)
store i32 %37, i32* %35
%38 = add nuw i64 %34, 1
%39 = icmp eq i64 %38, %18
br i1 %39, label %40, label %33
40: ; preds = %33, %28
%41 = getelementptr inbounds i8*, i8** %1, i64 2
%42 = load i8*, i8** %41
%43 = tail call i32* @fopen(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i8*, i8** %41
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %46)
br label %56
48: ; preds = %40
%49 = tail call i64 @fwrite(i32* %19, i32 4, i64 %25, i32* %43)
%50 = icmp eq i64 %49, %25
br i1 %50, label %53, label %51
51: ; preds = %48
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %53
53: ; preds = %51, %48
%54 = phi i32 [ -1, %51 ], [ 0, %48 ]
%55 = tail call i32 @fclose(i32* %43)
br label %56
56: ; preds = %53, %45, %30, %21
%57 = phi i32 [ -1, %30 ], [ %54, %53 ], [ -1, %45 ], [ -1, %21 ]
%58 = tail call i32 @free(i32* %19)
%59 = tail call i32 @fclose(i32* %10)
br label %60
60: ; preds = %56, %12, %4
%61 = phi i32 [ -1, %4 ], [ %57, %56 ], [ -1, %12 ]
ret i32 %61
}