#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 */

/* Variables and functions */
int EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getbit();
scalar_t__ malloc(int);
int /*<<< orphan*/ putblk(unsigned char *, int);
int /*<<< orphan*/ stderr;
int main() {
  int i;
  unsigned char *p;
  unsigned char *buf;
  buf = (unsigned char *)malloc(1048700);
  if (buf == NULL) {
    fprintf(stderr, "main: out of memory "
                    "allocating buf\n");
    exit(1);
  }
  i = 0;
  p = (unsigned char *)buf;
  while (1) {
    int j;
    int k;
    int ch;
    k = 0;
    j = 8;
    while (j--) {
      ch = getbit();
      if (ch == EOF)
        break;
      k <<= 1;
      k |= (ch - 0x30);
    }
    if (ch == EOF)
      break;
    *p++ = (unsigned char)k;
    i++;
    if (i >= 1024) {
      putblk(buf, i);
      i = 0;
      p = (unsigned char *)buf;
    }
  }
  if (i < 1024) {
    putblk(buf, i);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x10007c,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1197 <main+0x47>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x8,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     1203 <main+0xb3>
mov    $0x0,%al
call   1050 <getbit@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e0c(%rip),%rcx
cmp    (%rcx),%eax
jne    11e9 <main+0x99>
jmp    1203 <main+0xb3>
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x30,%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11b4 <main+0x64>
mov    -0x24(%rbp),%eax
mov    0x2ddb(%rip),%rcx
cmp    (%rcx),%eax
jne    121a <main+0xca>
jmp    1266 <main+0x116>
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x400,-0x8(%rbp)
jl     1261 <main+0x111>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <putblk@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11a6 <main+0x56>
cmpl   $0x400,-0x8(%rbp)
jge    127f <main+0x12f>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <putblk@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0x10007c,%edi
call   1040 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     130b <main+0x1bb>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getbit@plt>
mov    0x2e62(%rip),%rbp
cmp    0x0(%rbp),%eax
je     12ee <main+0x19e>
mov    %eax,%r13d
mov    0x8(%rsp),%r15
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <getbit@plt>
cmp    0x0(%rbp),%eax
je     12e3 <main+0x193>
mov    %eax,%r12d
xor    %eax,%eax
call   1050 <getbit@plt>
cmp    0x0(%rbp),%eax
je     12e3 <main+0x193>
mov    %rax,0x20(%rsp)
xor    %eax,%eax
call   1050 <getbit@plt>
cmp    0x0(%rbp),%eax
je     12e3 <main+0x193>
mov    %eax,%ebx
mov    %r13,0x18(%rsp)
xor    %eax,%eax
call   1050 <getbit@plt>
cmp    0x0(%rbp),%eax
je     12e3 <main+0x193>
mov    %eax,%r13d
mov    %r14,(%rsp)
xor    %eax,%eax
call   1050 <getbit@plt>
cmp    0x0(%rbp),%eax
je     12e8 <main+0x198>
mov    %eax,%r14d
mov    %r15,0x10(%rsp)
xor    %eax,%eax
call   1050 <getbit@plt>
cmp    0x0(%rbp),%eax
je     12e8 <main+0x198>
mov    %eax,%r15d
xor    %eax,%eax
call   1050 <getbit@plt>
cmp    0x0(%rbp),%eax
je     12e8 <main+0x198>
add    $0x10,%r14d
add    $0xfffffd0,%ebx
add    $0xfffffd0,%r12d
mov    0x18(%rsp),%rcx
add    %ecx,%ecx
add    $0xfffffa0,%ecx
or     %r12d,%ecx
shl    $0x2,%ecx
mov    0x20(%rsp),%rdx
add    %edx,%edx
add    $0x3fffffa0,%edx
or     %ebx,%edx
or     %ecx,%edx
shl    $0x2,%edx
lea    0x3fffffa0(%r13,%r13,1),%ecx
3f
or     %r14d,%ecx
or     %edx,%ecx
shl    $0x2,%ecx
lea    (%r15,%r15,1),%edx
add    $0xa0,%edx
add    $0xd0,%eax
or     %edx,%eax
or     %ecx,%eax
mov    0x10(%rsp),%r15
mov    %al,(%r15)
mov    (%rsp),%rax
lea    0x1(%rax),%ebx
cmp    $0x3ff,%eax
jge    12b0 <main+0x160>
add    $0x1,%r15
jmp    12c4 <main+0x174>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x8(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <putblk@plt>
xor    %ebx,%ebx
mov    %r14,%r15
mov    0x2d1d(%rip),%rbp
xor    %eax,%eax
call   1050 <getbit@plt>
mov    %eax,%r13d
mov    %ebx,%r14d
cmp    0x0(%rbp),%eax
jne    119a <main+0x4a>
jmp    12ee <main+0x19e>
mov    %r14d,%ebx
jmp    12ee <main+0x19e>
mov    (%rsp),%rax
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
mov    %ebx,%esi
call   1060 <putblk@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
lea    0xce5(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"main: out of memory allocating buf\0A\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i64 @malloc(i32 1048700)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
store i32 0, i32* %2
%17 = load i8*, i8** %4
store i8* %17, i8** %3
br label %18
18: ; preds = %16, %55
store i32 0, i32* %6
store i32 8, i32* %5
br label %19
19: ; preds = %29, %18
%20 = load i32, i32* %5
%21 = add nsw i32 %20, -1
store i32 %21, i32* %5
%22 = icmp ne i32 %20, 0
br i1 %22, label %23, label %36
23: ; preds = %19
%24 = call i32 (...) @getbit()
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %23
br label %36
29: ; preds = %23
%30 = load i32, i32* %6
%31 = shl i32 %30, 1
store i32 %31, i32* %6
%32 = load i32, i32* %7
%33 = sub nsw i32 %32, 48
%34 = load i32, i32* %6
%35 = or i32 %34, %33
store i32 %35, i32* %6
br label %19
36: ; preds = %28, %19
%37 = load i32, i32* %7
%38 = load i32, i32* @EOF
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %41
40: ; preds = %36
br label %56
41: ; preds = %36
%42 = load i32, i32* %6
%43 = trunc i32 %42 to i8
%44 = load i8*, i8** %3
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %3
store i8 %43, i8* %44
%46 = load i32, i32* %2
%47 = add nsw i32 %46, 1
store i32 %47, i32* %2
%48 = load i32, i32* %2
%49 = icmp sge i32 %48, 1024
br i1 %49, label %50, label %55
50: ; preds = %41
%51 = load i8*, i8** %4
%52 = load i32, i32* %2
%53 = call i32 @putblk(i8* %51, i32 %52)
store i32 0, i32* %2
%54 = load i8*, i8** %4
store i8* %54, i8** %3
br label %55
55: ; preds = %50, %41
br label %18
56: ; preds = %40
%57 = load i32, i32* %2
%58 = icmp slt i32 %57, 1024
br i1 %58, label %59, label %63
59: ; preds = %56
%60 = load i8*, i8** %4
%61 = load i32, i32* %2
%62 = call i32 @putblk(i8* %60, i32 %61)
br label %63
63: ; preds = %59, %56
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"main: out of memory allocating buf\0A\00"
@EOF = global i32 0
define i32 @main() {
%1 = tail call i64 @malloc(i32 1048700)
%2 = inttoptr i64 %1 to i8*
%3 = icmp eq i64 %1, 0
br i1 %3, label %8, label %4
4: ; preds = %0
%5 = tail call i32 (...) @getbit()
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %78, label %12
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %4, %72
%13 = phi i32 [ %75, %72 ], [ %5, %4 ]
%14 = phi i8* [ %74, %72 ], [ %2, %4 ]
%15 = phi i32 [ %73, %72 ], [ 0, %4 ]
%16 = tail call i32 (...) @getbit()
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %78, label %19
19: ; preds = %12
%20 = tail call i32 (...) @getbit()
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %78, label %23
23: ; preds = %19
%24 = tail call i32 (...) @getbit()
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %78, label %27
27: ; preds = %23
%28 = tail call i32 (...) @getbit()
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %78, label %31
31: ; preds = %27
%32 = tail call i32 (...) @getbit()
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %78, label %35
35: ; preds = %31
%36 = tail call i32 (...) @getbit()
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %36, %37
br i1 %38, label %78, label %39
39: ; preds = %35
%40 = tail call i32 (...) @getbit()
%41 = load i32, i32* @EOF
%42 = icmp eq i32 %40, %41
br i1 %42, label %78, label %43
43: ; preds = %39
%44 = add i32 %32, 16
%45 = add i32 %24, 268435408
%46 = add i32 %16, 268435408
%47 = shl i32 %13, 1
%48 = add i32 %47, 268435360
%49 = or i32 %46, %48
%50 = shl i32 %49, 2
%51 = shl i32 %20, 1
%52 = add i32 %51, 1073741728
%53 = or i32 %50, %52
%54 = or i32 %45, %53
%55 = shl i32 %54, 2
%56 = shl i32 %28, 1
%57 = add i32 %56, 1073741728
%58 = or i32 %55, %57
%59 = or i32 %44, %58
%60 = shl i32 %59, 2
%61 = shl i32 %36, 1
%62 = add i32 %61, 160
%63 = or i32 %60, %62
%64 = add i32 %40, 208
%65 = or i32 %64, %63
%66 = trunc i32 %65 to i8
%67 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %66, i8* %14
%68 = add nsw i32 %15, 1
%69 = icmp sgt i32 %15, 1022
br i1 %69, label %70, label %72
70: ; preds = %43
%71 = tail call i32 @putblk(i8* %2, i32 %68)
br label %72
72: ; preds = %43, %70
%73 = phi i32 [ 0, %70 ], [ %68, %43 ]
%74 = phi i8* [ %2, %70 ], [ %67, %43 ]
%75 = tail call i32 (...) @getbit()
%76 = load i32, i32* @EOF
%77 = icmp eq i32 %75, %76
br i1 %77, label %78, label %12
78: ; preds = %39, %35, %31, %27, %23, %19, %12, %72, %4
%79 = phi i32 [ 0, %4 ], [ %15, %39 ], [ %15, %35 ], [ %15, %31 ], [ %15, %27 ], [ %15, %23 ], [ %15, %19 ], [ %15, %12 ], [ %73, %72 ]
%80 = tail call i32 @putblk(i8* %2, i32 %79)
ret i32 0
}