#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ open_file(char *, int *, int *);
int /*<<< orphan*/ print_usage();
int read(int, int *, int);
int main(int argc, char **argv) {
  int sfd, ssz, red, i;
  int buf[1024];
  char *sfn, *tfn, *symname;
  FILE *tfd;
  if (argc != 4) {
    print_usage();
  }
  sfn = argv[1];
  tfn = argv[2];
  symname = argv[3];
  open_file(sfn, &sfd, &ssz);
  tfd = fopen(tfn, "w");
  fprintf(tfd, "int %s[] = {\n", symname);
  while ((red = read(sfd, buf, 1024 * sizeof(int)))) {
    for (i = 0; i < red / sizeof(int); i++)
      fprintf(tfd, "0x%x, \n", buf[i]);
  }
  fprintf(tfd, "};");
  fclose(tfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     118a <main+0x2a>
mov    $0x0,%al
call   1080 <print_usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x1028(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x1030(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x1038(%rbp)
mov    -0x1028(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <open_file@plt>
mov    -0x1030(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x1040(%rbp)
mov    -0x1040(%rbp),%rdi
mov    -0x1038(%rbp),%rdx
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1270 <main+0x110>
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shr    $0x2,%rcx
cmp    %rcx,%rax
jae    126b <main+0x10b>
mov    -0x1040(%rbp),%rdi
movslq -0x20(%rbp),%rax
mov    -0x1020(%rbp,%rax,4),%edx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1228 <main+0xc8>
jmp    1201 <main+0xa1>
mov    -0x1040(%rbp),%rdi
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1040(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
je     1190 <main+0x20>
xor    %eax,%eax
call   1090 <print_usage@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%r14
mov    0x18(%rbx),%r15
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1040 <open_file@plt>
lea    0xe4e(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%r13
lea    0xe3e(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
test   %eax,%eax
je     124c <main+0xdc>
lea    0x10(%rsp),%r14
mov    $0x1,%r12d
lea    0xe16(%rip),%r15
jmp    1215 <main+0xa5>
nopl   0x0(%rax)
mov    0x8(%rsp),%edi
mov    %r14,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
test   %eax,%eax
je     124c <main+0xdc>
cmp    $0x4,%eax
jb     1200 <main+0x90>
movslq %eax,%rbx
shr    $0x2,%rbx
cmp    $0x2,%rbx
cmovb  %r12,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbp,4),%edx
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1230 <main+0xc0>
jmp    1200 <main+0x90>
lea    0xdc5(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
mov    %r13,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [14 x i8] c"int %s[] = {\0A\00"
@.str.2 = [8 x i8] c"0x%x, \0A\00"
@.str.3 = [3 x i8] c"};\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 i32
%10 = alloca [1024 x i32]
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 4
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (...) @print_usage()
br label %19
19: ; preds = %17, %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %11
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
store i8* %25, i8** %12
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
store i8* %28, i8** %13
%29 = load i8*, i8** %11
%30 = call i32 @open_file(i8* %29, i32* %6, i32* %7)
%31 = load i8*, i8** %12
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %32, i32** %14
%33 = load i32*, i32** %14
%34 = load i8*, i8** %13
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %59, %19
%37 = load i32, i32* %6
%38 = getelementptr inbounds [1024 x i32], [1024 x i32]* %10, i64 0, i64 0
%39 = call i32 @read(i32 %37, i32* %38, i32 4096)
store i32 %39, i32* %8
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %60
41: ; preds = %36
store i32 0, i32* %9
br label %42
42: ; preds = %56, %41
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = udiv i64 %46, 4
%48 = icmp ult i64 %44, %47
br i1 %48, label %49, label %59
49: ; preds = %42
%50 = load i32*, i32** %14
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [1024 x i32], [1024 x i32]* %10, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %49
%57 = load i32, i32* %9
%58 = add nsw i32 %57, 1
store i32 %58, i32* %9
br label %42
59: ; preds = %42
br label %36
60: ; preds = %36
%61 = load i32*, i32** %14
%62 = call i32 (i32*, i8*, ...) @fprintf(i32* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%63 = load i32*, i32** %14
%64 = call i32 @fclose(i32* %63)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [14 x i8] c"int %s[] = {\0A\00"
@.str.2 = [8 x i8] c"0x%x, \0A\00"
@.str.3 = [3 x i8] c"};\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i32]
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast [1024 x i32]* %5 to i8*
%9 = icmp eq i32 %0, 4
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 (...) @print_usage()
br label %12
12: ; preds = %10, %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = call i32 @open_file(i8* %14, i32* %3, i32* %4)
%20 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%22 = getelementptr inbounds [1024 x i32], [1024 x i32]* %5, i64 0, i64 0
%23 = load i32, i32* %3
%24 = call i32 @read(i32 %23, i32* %22, i32 4096)
%25 = icmp eq i32 %24, 0
br i1 %25, label %44, label %30
26: ; preds = %37, %30
%27 = load i32, i32* %3
%28 = call i32 @read(i32 %27, i32* %22, i32 4096)
%29 = icmp eq i32 %28, 0
br i1 %29, label %44, label %30
30: ; preds = %12, %26
%31 = phi i32 [ %28, %26 ], [ %24, %12 ]
%32 = icmp ult i32 %31, 4
br i1 %32, label %26, label %33
33: ; preds = %30
%34 = sext i32 %31 to i64
%35 = lshr i64 %34, 2
%36 = call i64 @llvm.umax.i64(i64 %35, i64 1)
br label %37
37: ; preds = %33, %37
%38 = phi i64 [ 0, %33 ], [ %42, %37 ]
%39 = getelementptr inbounds [1024 x i32], [1024 x i32]* %5, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = add nuw nsw i64 %38, 1
%43 = icmp eq i64 %42, %36
br i1 %43, label %26, label %37
44: ; preds = %26, %12
%45 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %20)
%46 = call i32 @fclose(i32* %20)
ret i32 0
}