#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 EOF;
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
main(int argc, char **argv) {
  FILE *fpr, *fpw;
  int i, c;
  char *s, *p;
  if (argc != 3) {
    printf("Usage: mkcqrom <input-filename> <output-filename>\n Please see "
           "comments in mkcqrom.c.\n");
    exit(1);
  }
  p = (char *)malloc((32 * 1024));
  if (p == NULL) {
    printf("malloc error\n");
    exit(1);
  }
  fpr = fopen(*++argv, "rb");
  if (fpr == NULL) {
    printf("open error %s %d\n", *argv, errno);
    exit(1);
  }
  memset(p, 0xff, (32 * 1024));
  i = 0;
  while (1) {
    c = getc(fpr);
    if (c == EOF)
      break;
    s = p + (i / 2) + (i % 2) * 0x4000;
    *s = (char)c;
    i++;
  }
  fclose(fpr);
  fpw = fopen(*++argv, "wb");
  if (fpw == NULL) {
    printf("open error %s %d\n", *argv, errno);
    exit(1);
  }
  fwrite(p, (32 * 1024), sizeof(char), fpw);
  fclose(fpw);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b8 <main+0x38>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    $0x8000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11e9 <main+0x69>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe61(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    123f <main+0xbf>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    0x2db3(%rip),%rax
mov    (%rax),%edx
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    $0xff,%esi
mov    $0x8000,%edx
call   1050 <memset@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2d79(%rip),%rcx
cmp    (%rcx),%eax
jne    127c <main+0xfc>
jmp    12d4 <main+0x154>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x40(%rbp),%rax
shl    $0xe,%edx
movslq %edx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1259 <main+0xd9>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xd82(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1333 <main+0x1b3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    0x2cbf(%rip),%rax
mov    (%rax),%edx
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x8000,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    1288 <main+0xf8>
mov    %rsi,%r14
mov    $0x8000,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1291 <main+0x101>
mov    %rax,%r15
mov    0x8(%r14),%rdi
lea    0xe38(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12a7 <main+0x117>
mov    %rax,%r13
mov    %r15,%rdi
mov    $0xff,%esi
mov    $0x8000,%edx
call   1060 <memset@plt>
mov    %r13,%rdi
call   10b0 <getc@plt>
mov    0x2dee(%rip),%r12
cmp    (%r12),%eax
je     123a <main+0xaa>
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%ecx
shr    %rcx
add    %r15,%rcx
mov    %ebx,%edx
and    $0x4000,%edx
mov    %al,(%rdx,%rcx,1)
add    $0x1,%ebp
mov    %r13,%rdi
call   10b0 <getc@plt>
add    $0x4000,%ebx
cmp    (%r12),%eax
jne    1210 <main+0x80>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    0x10(%r14),%rdi
lea    0xdc8(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12ad <main+0x11d>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x8000,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd96(%rip),%rdi
jmp    1298 <main+0x108>
lea    0xd80(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x8(%r14),%rsi
jmp    12b1 <main+0x121>
mov    0x10(%r14),%rsi
mov    0x2d20(%rip),%rax
mov    (%rax),%edx
lea    0xd42(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [86 x i8] c"Usage: mkcqrom <input-filename> <output-filename>\0A Please see comments in mkcqrom.c.\0A\00"
@.str.1 = [14 x i8] c"malloc error\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [18 x i8] c"open error %s %d\0A\00"
@errno = global i32 0
@EOF = global i32 0
@.str.4 = [3 x i8] c"wb\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 i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = call i64 @malloc(i32 32768)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %11
%20 = load i8*, i8** %11
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i32 1
store i8** %27, i8*** %5
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %29, i32** %6
%30 = load i32*, i32** %6
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %38
32: ; preds = %25
%33 = load i8**, i8*** %5
%34 = load i8*, i8** %33
%35 = load i32, i32* @errno
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %34, i32 %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %25
%39 = load i8*, i8** %11
%40 = call i32 @memset(i8* %39, i32 255, i32 32768)
store i32 0, i32* %8
br label %41
41: ; preds = %38, %48
%42 = load i32*, i32** %6
%43 = call i32 @getc(i32* %42)
store i32 %43, i32* %9
%44 = load i32, i32* %9
%45 = load i32, i32* @EOF
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %41
br label %64
48: ; preds = %41
%49 = load i8*, i8** %11
%50 = load i32, i32* %8
%51 = sdiv i32 %50, 2
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %49, i64 %52
%54 = load i32, i32* %8
%55 = srem i32 %54, 2
%56 = mul nsw i32 %55, 16384
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %53, i64 %57
store i8* %58, i8** %10
%59 = load i32, i32* %9
%60 = trunc i32 %59 to i8
%61 = load i8*, i8** %10
store i8 %60, i8* %61
%62 = load i32, i32* %8
%63 = add nsw i32 %62, 1
store i32 %63, i32* %8
br label %41
64: ; preds = %47
%65 = load i32*, i32** %6
%66 = call i32 @fclose(i32* %65)
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i32 1
store i8** %68, i8*** %5
%69 = load i8*, i8** %68
%70 = call i32* @fopen(i8* %69, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %70, i32** %7
%71 = load i32*, i32** %7
%72 = icmp eq i32* %71, null
br i1 %72, label %73, label %79
73: ; preds = %64
%74 = load i8**, i8*** %5
%75 = load i8*, i8** %74
%76 = load i32, i32* @errno
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %75, i32 %76)
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %64
%80 = load i8*, i8** %11
%81 = load i32*, i32** %7
%82 = call i32 @fwrite(i8* %80, i32 32768, i32 1, i32* %81)
%83 = load i32*, i32** %7
%84 = call i32 @fclose(i32* %83)
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [18 x i8] c"open error %s %d\0A\00"
@errno = global i32 0
@EOF = global i32 0
@.str.4 = [3 x i8] c"wb\00"
@str = [13 x i8] c"malloc error\00"
@str.5 = [85 x i8] c"Usage: mkcqrom <input-filename> <output-filename>\0A Please see comments in mkcqrom.c.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str.5, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = tail call i64 @malloc(i32 32768)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %7
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i8*, i8** %15
%21 = load i32, i32* @errno
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %20, i32 %21)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %14
%25 = tail call i32 @memset(i8* %9, i32 255, i32 32768)
%26 = tail call i32 @getc(i32* %17)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %44, label %29
29: ; preds = %24, %29
%30 = phi i32 [ %41, %29 ], [ %26, %24 ]
%31 = phi i32 [ %40, %29 ], [ 0, %24 ]
%32 = lshr i32 %31, 1
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %9, i64 %33
%35 = shl i32 %31, 14
%36 = and i32 %35, 16384
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = trunc i32 %30 to i8
store i8 %39, i8* %38
%40 = add nuw nsw i32 %31, 1
%41 = tail call i32 @getc(i32* %17)
%42 = load i32, i32* @EOF
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %29
44: ; preds = %29, %24
%45 = tail call i32 @fclose(i32* %17)
%46 = getelementptr inbounds i8*, i8** %1, i64 2
%47 = load i8*, i8** %46
%48 = tail call i32* @fopen(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %55
50: ; preds = %44
%51 = load i8*, i8** %46
%52 = load i32, i32* @errno
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %51, i32 %52)
%54 = tail call i32 @exit(i32 1)
unreachable
55: ; preds = %44
%56 = tail call i32 @fwrite(i8* %9, i32 32768, i32 1, i32* %48)
%57 = tail call i32 @fclose(i32* %48)
ret i32 0
}