#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*/ fprintf(int /*<<< orphan*/, char *, long);
int /*<<< orphan*/ stdout;
long bits2Indices(FILE *fp) {
  long k = 0;
  int c;
  while ((c = fgetc(fp)) != EOF) {
    if (c == '0')
      k++;
    else if (c == '1') {
      k++;
      fprintf(stdout, "%li\n", k);
    }
  }
  return k;
}


x86 assembly (clang, -O0):
<bits2Indices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2ea1(%rip),%rcx
cmp    (%rcx),%eax
je     11a3 <bits2Indices+0x83>
cmpl   $0x30,-0x14(%rbp)
jne    116a <bits2Indices+0x4a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    119e <bits2Indices+0x7e>
cmpl   $0x31,-0x14(%rbp)
jne    1199 <bits2Indices+0x79>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe6c(%rip),%rsi
call   1040 <fprintf@plt>
jmp    119e <bits2Indices+0x7e>
jmp    1134 <bits2Indices+0x14>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bits2Indices>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
call   1030 <fgetc@plt>
mov    0x2eb0(%rip),%r12
cmp    (%r12),%eax
jne    114d <bits2Indices+0x2d>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %ebx,%ebx
mov    0x2e82(%rip),%r13
lea    0xea3(%rip),%r15
jmp    1181 <bits2Indices+0x61>
nop
add    $0x1,%rbx
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    (%r12),%eax
je     1140 <bits2Indices+0x20>
cmp    $0x31,%eax
je     1160 <bits2Indices+0x40>
cmp    $0x30,%eax
jne    1173 <bits2Indices+0x53>
add    $0x1,%rbx
jmp    1173 <bits2Indices+0x53>

LLVM IR (-O0):
@EOF = global i32 0
@stdout = global i32 0
@.str = [5 x i8] c"%li\0A\00"
define i64 @bits2Indices(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i32
store i32* %0, i32** %2
store i64 0, i64* %3
br label %5
5: ; preds = %26, %1
%6 = load i32*, i32** %2
%7 = call i32 @fgetc(i32* %6)
store i32 %7, i32* %4
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %27
10: ; preds = %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 48
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i64, i64* %3
%15 = add nsw i64 %14, 1
store i64 %15, i64* %3
br label %26
16: ; preds = %10
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 49
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i64, i64* %3
%21 = add nsw i64 %20, 1
store i64 %21, i64* %3
%22 = load i32, i32* @stdout
%23 = load i64, i64* %3
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %23)
br label %25
25: ; preds = %19, %16
br label %26
26: ; preds = %25, %13
br label %5
27: ; preds = %5
%28 = load i64, i64* %3
ret i64 %28
}

LLVM IR (-O2):
@EOF = global i32 0
@stdout = global i32 0
@.str = [5 x i8] c"%li\0A\00"
define i64 @bits2Indices(i32* nocapture %0) {
%2 = tail call i32 @fgetc(i32* %0)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %19, label %5
5: ; preds = %1, %14
%6 = phi i32 [ %16, %14 ], [ %2, %1 ]
%7 = phi i64 [ %15, %14 ], [ 0, %1 ]
switch i32 %6, label %14 [
i32 48, label %8
i32 49, label %10
]
8: ; preds = %5
%9 = add nsw i64 %7, 1
br label %14
10: ; preds = %5
%11 = add nsw i64 %7, 1
%12 = load i32, i32* @stdout
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %11)
br label %14
14: ; preds = %5, %10, %8
%15 = phi i64 [ %9, %8 ], [ %11, %10 ], [ %7, %5 ]
%16 = tail call i32 @fgetc(i32* %0)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %5
19: ; preds = %14, %1
%20 = phi i64 [ 0, %1 ], [ %15, %14 ]
ret i64 %20
}