#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 int8_t;
typedef int int16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ c64WriteBit(int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ readBit(int *, int);
int main(int argc, const char *argv[]) {
  FILE *inf = fopen(argv[1], "rb");
  FILE *outf = fopen(argv[2], "wb");
  int8_t in[320 * 200];
  int8_t out[(320 * 200) / 8];
  memset(out, 0, (320 * 200) / 8);
  int8_t *loc = in;
  for (int i = 0; i < 320 * 200; ++i) {
    int16_t sh;
    fread(&sh, 2, 1, inf);
    *loc = 0x03 & sh;
    loc += 1;
  }
  for (int i = 0; i < 320 * 200; ++i) {
    c64WriteBit(out, i, readBit(in, i));
  }
  loc = out;
  for (int i = 0; i < (320 * 200) / 8; ++i) {
    fwrite(loc, 1, 1, outf);
    loc += 1;
  }
  fclose(inf);
  fclose(outf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x46550,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe68(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe53(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x46520(%rbp),%rdi
xor    %esi,%esi
mov    $0x1f40,%edx
call   1060 <memset@plt>
lea    -0x3e820(%rbp),%rax
mov    %rax,-0x46528(%rbp)
movl   $0x0,-0x4652c(%rbp)
cmpl   $0xfa00,-0x4652c(%rbp)
jge    1246 <main+0xd6>
mov    -0x18(%rbp),%rcx
lea    -0x46530(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x46530(%rbp),%ecx
and    $0x3,%ecx
mov    -0x46528(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x46528(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x46528(%rbp)
mov    -0x4652c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4652c(%rbp)
jmp    11e4 <main+0x74>
movl   $0x0,-0x46534(%rbp)
cmpl   $0xfa00,-0x46534(%rbp)
jge    12b4 <main+0x144>
lea    -0x46520(%rbp),%rax
mov    %rax,-0x46548(%rbp)
mov    -0x46534(%rbp),%eax
mov    %eax,-0x4653c(%rbp)
lea    -0x3e820(%rbp),%rdi
mov    -0x46534(%rbp),%esi
call   1050 <readBit@plt>
mov    -0x46548(%rbp),%rdi
mov    -0x4653c(%rbp),%esi
mov    %eax,%edx
call   1070 <c64WriteBit@plt>
mov    -0x46534(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x46534(%rbp)
jmp    1250 <main+0xe0>
lea    -0x46520(%rbp),%rax
mov    %rax,-0x46528(%rbp)
movl   $0x0,-0x46538(%rbp)
cmpl   $0x1f40,-0x46538(%rbp)
jge    1319 <main+0x1a9>
mov    -0x46528(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1090 <fwrite@plt>
mov    -0x46528(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x46528(%rbp)
mov    -0x46538(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x46538(%rbp)
jmp    12cc <main+0x15c>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x46550,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x46510,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe72(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x1f40,%edx
call   1060 <memset@plt>
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    0xc(%rsp),%eax
and    $0x3,%eax
mov    %eax,0x7d10(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0xfa00,%ebx
jne    11d0 <main+0x60>
xor    %ebx,%ebx
lea    0x7d10(%rsp),%r12
lea    0x10(%rsp),%r13
xchg   %ax,%ax
mov    %r12,%rdi
mov    %ebx,%esi
call   1050 <readBit@plt>
mov    %r13,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1080 <c64WriteBit@plt>
add    $0x1,%ebx
cmp    $0xfa00,%ebx
jne    1210 <main+0xa0>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl 0x10(%rsp,%rbx,4),%edi
mov    %r15,%rsi
call   1070 <fputc@plt>
add    $0x1,%rbx
cmp    $0x1f40,%ebx
jne    1240 <main+0xd0>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x46510,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [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 [64000 x i32]
%9 = alloca [8000 x i32]
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %7
%23 = getelementptr inbounds [8000 x i32], [8000 x i32]* %9, i64 0, i64 0
%24 = call i32 @memset(i32* %23, i32 0, i32 8000)
%25 = getelementptr inbounds [64000 x i32], [64000 x i32]* %8, i64 0, i64 0
store i32* %25, i32** %10
store i32 0, i32* %11
br label %26
26: ; preds = %37, %2
%27 = load i32, i32* %11
%28 = icmp slt i32 %27, 64000
br i1 %28, label %29, label %40
29: ; preds = %26
%30 = load i32*, i32** %6
%31 = call i32 @fread(i32* %12, i32 2, i32 1, i32* %30)
%32 = load i32, i32* %12
%33 = and i32 3, %32
%34 = load i32*, i32** %10
store i32 %33, i32* %34
%35 = load i32*, i32** %10
%36 = getelementptr inbounds i32, i32* %35, i64 1
store i32* %36, i32** %10
br label %37
37: ; preds = %29
%38 = load i32, i32* %11
%39 = add nsw i32 %38, 1
store i32 %39, i32* %11
br label %26
40: ; preds = %26
store i32 0, i32* %13
br label %41
41: ; preds = %51, %40
%42 = load i32, i32* %13
%43 = icmp slt i32 %42, 64000
br i1 %43, label %44, label %54
44: ; preds = %41
%45 = getelementptr inbounds [8000 x i32], [8000 x i32]* %9, i64 0, i64 0
%46 = load i32, i32* %13
%47 = getelementptr inbounds [64000 x i32], [64000 x i32]* %8, i64 0, i64 0
%48 = load i32, i32* %13
%49 = call i32 @readBit(i32* %47, i32 %48)
%50 = call i32 @c64WriteBit(i32* %45, i32 %46, i32 %49)
br label %51
51: ; preds = %44
%52 = load i32, i32* %13
%53 = add nsw i32 %52, 1
store i32 %53, i32* %13
br label %41
54: ; preds = %41
%55 = getelementptr inbounds [8000 x i32], [8000 x i32]* %9, i64 0, i64 0
store i32* %55, i32** %10
store i32 0, i32* %14
br label %56
56: ; preds = %65, %54
%57 = load i32, i32* %14
%58 = icmp slt i32 %57, 8000
br i1 %58, label %59, label %68
59: ; preds = %56
%60 = load i32*, i32** %10
%61 = load i32*, i32** %7
%62 = call i32 @fwrite(i32* %60, i32 1, i32 1, i32* %61)
%63 = load i32*, i32** %10
%64 = getelementptr inbounds i32, i32* %63, i64 1
store i32* %64, i32** %10
br label %65
65: ; preds = %59
%66 = load i32, i32* %14
%67 = add nsw i32 %66, 1
store i32 %67, i32* %14
br label %56
68: ; preds = %56
%69 = load i32*, i32** %6
%70 = call i32 @fclose(i32* %69)
%71 = load i32*, i32** %7
%72 = call i32 @fclose(i32* %71)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [64000 x i32]
%4 = alloca [8000 x i32]
%5 = alloca i32
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = bitcast [64000 x i32]* %3 to i8*
%13 = bitcast [8000 x i32]* %4 to i8*
%14 = getelementptr inbounds [8000 x i32], [8000 x i32]* %4, i64 0, i64 0
%15 = call i32 @memset(i32* %14, i32 0, i32 8000)
%16 = getelementptr inbounds [64000 x i32], [64000 x i32]* %3, i64 0, i64 0
%17 = bitcast i32* %5 to i8*
br label %18
18: ; preds = %2, %18
%19 = phi i32 [ 0, %2 ], [ %25, %18 ]
%20 = phi i32* [ %16, %2 ], [ %24, %18 ]
%21 = call i32 @fread(i32* %5, i32 2, i32 1, i32* %8)
%22 = load i32, i32* %5
%23 = and i32 %22, 3
store i32 %23, i32* %20
%24 = getelementptr inbounds i32, i32* %20, i64 1
%25 = add nuw nsw i32 %19, 1
%26 = icmp eq i32 %25, 64000
br i1 %26, label %27, label %18
27: ; preds = %18, %27
%28 = phi i32 [ %31, %27 ], [ 0, %18 ]
%29 = call i32 @readBit(i32* %16, i32 %28)
%30 = call i32 @c64WriteBit(i32* %14, i32 %28, i32 %29)
%31 = add nuw nsw i32 %28, 1
%32 = icmp eq i32 %31, 64000
br i1 %32, label %36, label %27
33: ; preds = %36
%34 = call i32 @fclose(i32* %8)
%35 = call i32 @fclose(i32* %11)
ret i32 0
36: ; preds = %27, %36
%37 = phi i32 [ %44, %36 ], [ 0, %27 ]
%38 = phi i32* [ %43, %36 ], [ %14, %27 ]
%39 = bitcast i32* %38 to i8*
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = call i32 @fputc(i32 %41, i32* %11)
%43 = getelementptr inbounds i32, i32* %38, i64 1
%44 = add nuw nsw i32 %37, 1
%45 = icmp eq i32 %44, 8000
br i1 %45, label %33, label %36
}