#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(char, int /*<<< orphan*/ *);
void bin2ascii(FILE *input, FILE *output) {
  while (1) {
    int x = fgetc(input);
    if (x == EOF)
      break;
    int num;
    int hold = 0;
    for (num = 0; num < 8; num++) {
      if ((char)(x << num) >> 8) {
        fputc('1', output);
      } else {
        fputc('0', output);
      }
    }
  }
  return;
}


x86 assembly (clang, -O0):
<bin2ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2ea2(%rip),%rcx
cmp    (%rcx),%eax
jne    1153 <bin2ascii+0x33>
jmp    11bb <bin2ascii+0x9b>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    11b6 <bin2ascii+0x96>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    %cl,%eax
movsbl %al,%eax
sar    $0x8,%eax
cmp    $0x0,%eax
je     1195 <bin2ascii+0x75>
mov    -0x10(%rbp),%rsi
mov    $0x31,%edi
call   1040 <fputc@plt>
jmp    11a3 <bin2ascii+0x83>
mov    -0x10(%rbp),%rsi
mov    $0x30,%edi
call   1040 <fputc@plt>
jmp    11a8 <bin2ascii+0x88>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1161 <bin2ascii+0x41>
jmp    1130 <bin2ascii+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin2ascii>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <fgetc@plt>
mov    0x2ea8(%rip),%rcx
cmp    (%rcx),%eax
je     1261 <bin2ascii+0x141>
mov    %r14,0x10(%rsp)
nopl   (%rax)
movd   %eax,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa %xmm0,%xmm1
pand   0xe9b(%rip),%xmm1
pand   0xea3(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%ebp
mov    %ebp,%eax
and    $0x2,%al
shr    %al
mov    %al,0xf(%rsp)
mov    %ebp,%eax
and    $0x4,%al
shr    $0x2,%al
mov    %al,0xe(%rsp)
mov    %ebp,%r15d
and    $0x8,%r15b
shr    $0x3,%r15b
mov    %ebp,%r14d
and    $0x10,%r14b
shr    $0x4,%r14b
mov    %ebp,%r12d
and    $0x20,%r12b
shr    $0x5,%r12b
mov    %ebp,%r13d
and    $0x40,%r13b
shr    $0x6,%r13b
mov    %ebp,%eax
shr    $0x7,%al
movzbl %al,%edi
xor    $0x31,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
movzbl %r13b,%edi
xor    $0x31,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
movzbl %r12b,%edi
xor    $0x31,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
movzbl %r14b,%edi
mov    0x10(%rsp),%r14
xor    $0x31,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
movzbl %r15b,%edi
xor    $0x31,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
movzbl 0xe(%rsp),%edi
xor    $0x31,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
movzbl 0xf(%rsp),%edi
xor    $0x31,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
and    $0x1,%ebp
xor    $0x31,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    0x2d8f(%rip),%rcx
cmp    (%rcx),%eax
jne    1150 <bin2ascii+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define void @bin2ascii(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
br label %8
8: ; preds = %2, %37
%9 = load i32*, i32** %3
%10 = call i32 @fgetc(i32* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%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
store i32 0, i32* %7
store i32 0, i32* %6
br label %16
16: ; preds = %34, %15
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 8
br i1 %18, label %19, label %37
19: ; preds = %16
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = shl i32 %20, %21
%23 = trunc i32 %22 to i8
%24 = sext i8 %23 to i32
%25 = ashr i32 %24, 8
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = load i32*, i32** %4
%29 = call i32 @fputc(i8 signext 49, i32* %28)
br label %33
30: ; preds = %19
%31 = load i32*, i32** %4
%32 = call i32 @fputc(i8 signext 48, i32* %31)
br label %33
33: ; preds = %30, %27
br label %34
34: ; preds = %33
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %16
37: ; preds = %16
br label %8
38: ; preds = %14
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @bin2ascii(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 %39, label %6
6: ; preds = %2, %6
%7 = phi i32 [ %36, %6 ], [ %3, %2 ]
%8 = insertelement <8 x i32> poison, i32 %7, i64 0
%9 = shufflevector <8 x i32> %8, <8 x i32> poison, <8 x i32> zeroinitializer
%10 = and <8 x i32> %9, <i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128>
%11 = icmp eq <8 x i32> %10, zeroinitializer
%12 = extractelement <8 x i1> %11, i64 7
%13 = select i1 %12, i8 48, i8 49
%14 = tail call i32 @fputc(i8 signext %13, i32* %1)
%15 = extractelement <8 x i1> %11, i64 6
%16 = select i1 %15, i8 48, i8 49
%17 = tail call i32 @fputc(i8 signext %16, i32* %1)
%18 = extractelement <8 x i1> %11, i64 5
%19 = select i1 %18, i8 48, i8 49
%20 = tail call i32 @fputc(i8 signext %19, i32* %1)
%21 = extractelement <8 x i1> %11, i64 4
%22 = select i1 %21, i8 48, i8 49
%23 = tail call i32 @fputc(i8 signext %22, i32* %1)
%24 = extractelement <8 x i1> %11, i64 3
%25 = select i1 %24, i8 48, i8 49
%26 = tail call i32 @fputc(i8 signext %25, i32* %1)
%27 = extractelement <8 x i1> %11, i64 2
%28 = select i1 %27, i8 48, i8 49
%29 = tail call i32 @fputc(i8 signext %28, i32* %1)
%30 = extractelement <8 x i1> %11, i64 1
%31 = select i1 %30, i8 48, i8 49
%32 = tail call i32 @fputc(i8 signext %31, i32* %1)
%33 = extractelement <8 x i1> %11, i64 0
%34 = select i1 %33, i8 48, i8 49
%35 = tail call i32 @fputc(i8 signext %34, i32* %1)
%36 = tail call i32 @fgetc(i32* %0)
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %6
39: ; preds = %6, %2
ret void
}