#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
void ascii2bin(FILE *input, FILE *output) {
  unsigned char holder = 0;
  int num = 0;
  while (1) {
    int x = fgetc(input);
    if (x == EOF)
      break;
    holder <<= 1;
    if (x >= '1') {
      holder = holder | 0x01;
    }
    num++;
    if (num % 8 == 0) {
      fputc(holder, output);
      holder = 0;
    }
  }
  if (num % 8 != 0)
    fputc(holder, output);
  return;
}


x86 assembly (clang, -O0):
<ascii2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e97(%rip),%rcx
cmp    (%rcx),%eax
jne    115e <ascii2bin+0x3e>
jmp    11b1 <ascii2bin+0x91>
movzbl -0x11(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x11(%rbp)
cmpl   $0x31,-0x1c(%rbp)
jl     117c <ascii2bin+0x5c>
movzbl -0x11(%rbp),%eax
or     $0x1,%eax
mov    %al,-0x11(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ac <ascii2bin+0x8c>
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1040 <fputc@plt>
movb   $0x0,-0x11(%rbp)
jmp    113b <ascii2bin+0x1b>
mov    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11d4 <ascii2bin+0xb4>
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1040 <fputc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ascii2bin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <fgetc@plt>
mov    0x2eae(%rip),%r15
cmp    (%r15),%eax
je     119d <ascii2bin+0x7d>
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    115d <ascii2bin+0x3d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1030 <fgetc@plt>
cmp    (%r15),%eax
je     1184 <ascii2bin+0x64>
mov    %ebp,%ecx
add    %bpl,%cl
cmp    $0x31,%eax
setge  %bpl
or     %cl,%bpl
add    $0x1,%ebx
test   $0x7,%bl
jne    1150 <ascii2bin+0x30>
movzbl %bpl,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
xor    %ebp,%ebp
jmp    1150 <ascii2bin+0x30>
test   $0x7,%bl
je     119d <ascii2bin+0x7d>
movzbl %bpl,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fputc@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define void @ascii2bin(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i8 0, i8* %5
store i32 0, i32* %6
br label %8
8: ; preds = %2, %37
%9 = load i32*, i32** %3
%10 = call i32 @fgetc(i32* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %8
br label %38
15: ; preds = %8
%16 = load i8, i8* %5
%17 = zext i8 %16 to i32
%18 = shl i32 %17, 1
%19 = trunc i32 %18 to i8
store i8 %19, i8* %5
%20 = load i32, i32* %7
%21 = icmp sge i32 %20, 49
br i1 %21, label %22, label %27
22: ; preds = %15
%23 = load i8, i8* %5
%24 = zext i8 %23 to i32
%25 = or i32 %24, 1
%26 = trunc i32 %25 to i8
store i8 %26, i8* %5
br label %27
27: ; preds = %22, %15
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = srem i32 %30, 8
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %27
%34 = load i8, i8* %5
%35 = load i32*, i32** %4
%36 = call i32 @fputc(i8 zeroext %34, i32* %35)
store i8 0, i8* %5
br label %37
37: ; preds = %33, %27
br label %8
38: ; preds = %14
%39 = load i32, i32* %6
%40 = srem i32 %39, 8
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load i8, i8* %5
%44 = load i32*, i32** %4
%45 = call i32 @fputc(i8 zeroext %43, i32* %44)
br label %46
46: ; preds = %42, %38
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @ascii2bin(i32* nocapture %0, i32* nocapture %1) {
%3 = tail call i32 @fgetc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %29, label %6
6: ; preds = %2, %19
%7 = phi i32 [ %21, %19 ], [ %3, %2 ]
%8 = phi i8 [ %20, %19 ], [ 0, %2 ]
%9 = phi i32 [ %14, %19 ], [ 0, %2 ]
%10 = shl i8 %8, 1
%11 = icmp sgt i32 %7, 48
%12 = zext i1 %11 to i8
%13 = or i8 %10, %12
%14 = add nuw nsw i32 %9, 1
%15 = and i32 %14, 7
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %6
%18 = tail call i32 @fputc(i8 zeroext %13, i32* %1)
br label %19
19: ; preds = %6, %17
%20 = phi i8 [ 0, %17 ], [ %13, %6 ]
%21 = tail call i32 @fgetc(i32* %0)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %6
24: ; preds = %19
%25 = and i32 %14, 7
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = tail call i32 @fputc(i8 zeroext %20, i32* %1)
br label %29
29: ; preds = %2, %27, %24
ret void
}