#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ assembly(size_t, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
char *malloc(size_t);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  FILE *input;
  FILE *output;
  size_t size;
  char *data;
  if (argc < 3) {
    printf("too few parameters\n");
    return EXIT_FAILURE;
  }
  input = fopen(argv[1], "rb");
  fseek(input, 0, SEEK_END);
  size = ftell(input);
  rewind(input);
  data = malloc(size);
  fread(data, size, 1, input);
  fclose(input);
  output = fopen(argv[2], "wb");
  assembly(size, data, output);
  free(data);
  fclose(output);
  return EXIT_SUCCESS;
}


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   $0x3,-0x8(%rbp)
jge    11dd <main+0x3d>
lea    0xe39(%rip),%rdi
call   1060 <printf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1292 <main+0xf2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe28(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2de8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <rewind@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdbd(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1080 <assembly@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     11c5 <main+0x25>
lea    0xe52(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e18(%rip),%rax
jmp    125f <main+0xbf>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe2d(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
mov    0x2e06(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rbx,%rdi
call   1090 <ftell@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1070 <rewind@plt>
mov    %r15,%rdi
call   10a0 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x10(%r14),%rdi
lea    0xdd1(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1080 <assembly@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"too few parameters\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.2 = [3 x i8] c"wb\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 i64
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %3
br label %48
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = load i32, i32* @SEEK_END
%22 = call i32 @fseek(i32* %20, i32 0, i32 %21)
%23 = load i32*, i32** %6
%24 = call i64 @ftell(i32* %23)
store i64 %24, i64* %8
%25 = load i32*, i32** %6
%26 = call i32 @rewind(i32* %25)
%27 = load i64, i64* %8
%28 = call i8* @malloc(i64 %27)
store i8* %28, i8** %9
%29 = load i8*, i8** %9
%30 = load i64, i64* %8
%31 = load i32*, i32** %6
%32 = call i32 @fread(i8* %29, i64 %30, i32 1, i32* %31)
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %38, i32** %7
%39 = load i64, i64* %8
%40 = load i8*, i8** %9
%41 = load i32*, i32** %7
%42 = call i32 @assembly(i64 %39, i8* %40, i32* %41)
%43 = load i8*, i8** %9
%44 = call i32 @free(i8* %43)
%45 = load i32*, i32** %7
%46 = call i32 @fclose(i32* %45)
%47 = load i32, i32* @EXIT_SUCCESS
store i32 %47, i32* %3
br label %48
48: ; preds = %15, %12
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.2 = [3 x i8] c"wb\00"
@EXIT_SUCCESS = global i32 0
@str = [19 x i8] c"too few parameters\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %23
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.1, i64 0, i64 0))
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %9, i32 0, i32 %10)
%12 = tail call i64 @ftell(i32* %9)
%13 = tail call i32 @rewind(i32* %9)
%14 = tail call i8* @malloc(i64 %12)
%15 = tail call i32 @fread(i8* %14, i64 %12, i32 1, i32* %9)
%16 = tail call i32 @fclose(i32* %9)
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @assembly(i64 %12, i8* %14, i32* %19)
%21 = tail call i32 @free(i8* %14)
%22 = tail call i32 @fclose(i32* %19)
br label %23
23: ; preds = %6, %4
%24 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_SUCCESS, %6 ]
%25 = load i32, i32* %24
ret i32 %25
}