#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 */
scalar_t__ EOF;
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp;
  int a;
  if (argc != 2) {
    printf("Usage: %s [FILE]\n", argv[0]);
    return 1;
  }
  fp = fopen(*++argv, "r");
  while (fscanf(fp, "%d", &a) != EOF) {
    int b = 0, c = a;
    while (a) {
      b <<= 1;
      b += a & 1;
      a >>= 1;
    }
    if (c == 0)
      printf("0");
    while (c) {
      printf("%d", b & 1);
      b >>= 1;
      c >>= 1;
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1171 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    125e <main+0x12e>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe87(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe75(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <fscanf@plt>
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%rax
je     1257 <main+0x127>
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11f2 <main+0xc2>
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x1,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c5 <main+0x95>
cmpl   $0x0,-0x24(%rbp)
jne    120a <main+0xda>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120f <main+0xdf>
cmpl   $0x0,-0x24(%rbp)
je     1244 <main+0x114>
mov    -0x20(%rbp),%esi
and    $0x1,%esi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    120f <main+0xdf>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1194 <main+0x64>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    121e <main+0xde>
mov    0x8(%rsi),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xea6(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rax,%rcx
mov    0x2e63(%rip),%r12
xor    %eax,%eax
cmp    (%r12),%rcx
je     1238 <main+0xf8>
lea    0xe7c(%rip),%r13
lea    0x4(%rsp),%r15
jmp    11c8 <main+0x88>
nop
mov    $0x30,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1050 <fscanf@plt>
cmp    (%r12),%rax
je     1236 <main+0xf6>
mov    0x4(%rsp),%ebp
test   %ebp,%ebp
je     11a0 <main+0x60>
xor    %ebx,%ebx
mov    %ebp,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%ecx
mov    %eax,%edx
and    $0x1,%edx
lea    (%rdx,%rbx,2),%ebx
sar    %eax
cmp    $0x1,%ecx
ja     11e0 <main+0xa0>
mov    %eax,0x4(%rsp)
test   %ebp,%ebp
je     11a0 <main+0x60>
nopl   0x0(%rax)
mov    %ebx,%esi
and    $0x1,%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
sar    %ebx
mov    %ebp,%eax
sar    %eax
cmp    $0x1,%ebp
mov    %eax,%ebp
ja     1200 <main+0xc0>
jmp    11aa <main+0x6a>
mov    (%rsi),%rsi
lea    0xdd8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
jmp    1238 <main+0xf8>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s [FILE]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.3 = [2 x i8] c"0\00"
@.str.4 = [2 x i8] c"\0A\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %61
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i32 1
store i8** %19, i8*** %5
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
br label %22
22: ; preds = %58, %17
%23 = load i32*, i32** %6
%24 = call i64 @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%25 = load i64, i64* @EOF
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %60
27: ; preds = %22
store i32 0, i32* %8
%28 = load i32, i32* %7
store i32 %28, i32* %9
br label %29
29: ; preds = %32, %27
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %29
%33 = load i32, i32* %8
%34 = shl i32 %33, 1
store i32 %34, i32* %8
%35 = load i32, i32* %7
%36 = and i32 %35, 1
%37 = load i32, i32* %8
%38 = add nsw i32 %37, %36
store i32 %38, i32* %8
%39 = load i32, i32* %7
%40 = ashr i32 %39, 1
store i32 %40, i32* %7
br label %29
41: ; preds = %29
%42 = load i32, i32* %9
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
br label %47
47: ; preds = %50, %46
%48 = load i32, i32* %9
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %58
50: ; preds = %47
%51 = load i32, i32* %8
%52 = and i32 %51, 1
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %52)
%54 = load i32, i32* %8
%55 = ashr i32 %54, 1
store i32 %55, i32* %8
%56 = load i32, i32* %9
%57 = ashr i32 %56, 1
store i32 %57, i32* %9
br label %47
58: ; preds = %47
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %22
60: ; preds = %22
store i32 0, i32* %3
br label %61
61: ; preds = %60, %12
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s [FILE]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i64 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %43
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = call i64 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%14 = load i64, i64* @EOF
%15 = icmp eq i64 %13, %14
br i1 %15, label %43, label %16
16: ; preds = %9, %38
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %16, %19
%20 = phi i32 [ %24, %19 ], [ 0, %16 ]
%21 = phi i32 [ %25, %19 ], [ %17, %16 ]
%22 = shl i32 %20, 1
%23 = and i32 %21, 1
%24 = or i32 %22, %23
%25 = ashr i32 %21, 1
%26 = icmp ult i32 %21, 2
br i1 %26, label %27, label %19
27: ; preds = %19
store i32 %25, i32* %3
br i1 %18, label %28, label %30
28: ; preds = %16, %27
%29 = call i32 @putchar(i32 48)
br label %38
30: ; preds = %27, %30
%31 = phi i32 [ %36, %30 ], [ %17, %27 ]
%32 = phi i32 [ %35, %30 ], [ %24, %27 ]
%33 = and i32 %32, 1
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = ashr i32 %32, 1
%36 = ashr i32 %31, 1
%37 = icmp ult i32 %31, 2
br i1 %37, label %38, label %30
38: ; preds = %30, %28
%39 = call i32 @putchar(i32 10)
%40 = call i64 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%41 = load i64, i64* @EOF
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %16
43: ; preds = %38, %9, %6
%44 = phi i32 [ 1, %6 ], [ 0, %9 ], [ 0, %38 ]
ret i32 %44
}