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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
scalar_t__ isspace(char);
int /*<<< orphan*/ stdin;
scalar_t__ strlen(char *);
unsigned short scanBinary() {
  char buf[256];
  fgets(buf, sizeof(buf), stdin);
  unsigned short val = 0;
  int len = (int)strlen(buf);
  int i = 0;
  while ((i < len) && (isspace(buf[i]))) {
    i++;
  }
  while ((i < len) && ((buf[i] == '0') || (buf[i] == '1'))) {
    val = val << 1;
    if (buf[i] == '1') {
      val = val | 01;
    }
    i++;
  }
  return val;
}


x86 assembly (clang, -O0):
<scanBinary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    -0x100(%rbp),%rdi
mov    0x2e9f(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1050 <fgets@plt>
movw   $0x0,-0x102(%rbp)
lea    -0x100(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x108(%rbp)
movl   $0x0,-0x10c(%rbp)
mov    -0x10c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x108(%rbp),%ecx
mov    %al,-0x10d(%rbp)
jge    11b5 <scanBinary+0x85>
movslq -0x10c(%rbp),%rax
movsbl -0x100(%rbp,%rax,1),%edi
ff
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x10d(%rbp)
mov    -0x10d(%rbp),%al
test   $0x1,%al
jne    11c8 <scanBinary+0x98>
jmp    11dc <scanBinary+0xac>
mov    -0x10c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10c(%rbp)
jmp    117a <scanBinary+0x4a>
jmp    11e1 <scanBinary+0xb1>
mov    -0x10c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x108(%rbp),%ecx
mov    %al,-0x10e(%rbp)
jge    1242 <scanBinary+0x112>
movslq -0x10c(%rbp),%rax
movsbl -0x100(%rbp,%rax,1),%ecx
ff
mov    $0x1,%al
cmp    $0x30,%ecx
mov    %al,-0x10f(%rbp)
je     1236 <scanBinary+0x106>
movslq -0x10c(%rbp),%rax
movsbl -0x100(%rbp,%rax,1),%eax
ff
cmp    $0x31,%eax
sete   %al
mov    %al,-0x10f(%rbp)
mov    -0x10f(%rbp),%al
mov    %al,-0x10e(%rbp)
mov    -0x10e(%rbp),%al
test   $0x1,%al
jne    1255 <scanBinary+0x125>
jmp    12a3 <scanBinary+0x173>
movzwl -0x102(%rbp),%eax
shl    $0x1,%eax
mov    %ax,-0x102(%rbp)
movslq -0x10c(%rbp),%rax
movsbl -0x100(%rbp,%rax,1),%eax
ff
cmp    $0x31,%eax
jne    128f <scanBinary+0x15f>
movzwl -0x102(%rbp),%eax
or     $0x1,%eax
mov    %ax,-0x102(%rbp)
mov    -0x10c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10c(%rbp)
jmp    11e1 <scanBinary+0xb1>
movzwl -0x102(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scanBinary>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    0x2ea5(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r14
test   %r14d,%r14d
jle    1189 <scanBinary+0x59>
mov    %r14d,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%rsp,%rbx,1),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     118b <scanBinary+0x5b>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1170 <scanBinary+0x40>
jmp    11c6 <scanBinary+0x96>
xor    %ebx,%ebx
cmp    %r14d,%ebx
jge    11c6 <scanBinary+0x96>
mov    %ebx,%eax
lea    (%rsp,%rax,1),%rsi
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movzbl (%rsi),%ecx
mov    %ecx,%edx
and    $0xfe,%dl
cmp    $0x30,%dl
jne    11c8 <scanBinary+0x98>
xor    %edx,%edx
cmp    $0x31,%cl
sete   %dl
lea    (%rdx,%rax,2),%eax
add    $0x1,%rsi
add    $0x1,%ebx
cmp    %r14d,%ebx
jl     11a0 <scanBinary+0x70>
jmp    11c8 <scanBinary+0x98>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
define zeroext i16 @scanBinary() {
%1 = alloca [256 x i8]
%2 = alloca i16
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %5, i32 256, i32 %6)
store i16 0, i16* %2
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%9 = call i64 @strlen(i8* %8)
%10 = trunc i64 %9 to i32
store i32 %10, i32* %3
store i32 0, i32* %4
br label %11
11: ; preds = %24, %0
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %22
15: ; preds = %11
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = call i64 @isspace(i8 signext %19)
%21 = icmp ne i64 %20, 0
br label %22
22: ; preds = %15, %11
%23 = phi i1 [ false, %11 ], [ %21, %15 ]
br i1 %23, label %24, label %27
24: ; preds = %22
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %11
27: ; preds = %22
br label %28
28: ; preds = %66, %27
%29 = load i32, i32* %4
%30 = load i32, i32* %3
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %48
32: ; preds = %28
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 48
br i1 %38, label %46, label %39
39: ; preds = %32
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 49
br label %46
46: ; preds = %39, %32
%47 = phi i1 [ true, %32 ], [ %45, %39 ]
br label %48
48: ; preds = %46, %28
%49 = phi i1 [ false, %28 ], [ %47, %46 ]
br i1 %49, label %50, label %69
50: ; preds = %48
%51 = load i16, i16* %2
%52 = zext i16 %51 to i32
%53 = shl i32 %52, 1
%54 = trunc i32 %53 to i16
store i16 %54, i16* %2
%55 = load i32, i32* %4
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %56
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 49
br i1 %60, label %61, label %66
61: ; preds = %50
%62 = load i16, i16* %2
%63 = zext i16 %62 to i32
%64 = or i32 %63, 1
%65 = trunc i32 %64 to i16
store i16 %65, i16* %2
br label %66
66: ; preds = %61, %50
%67 = load i32, i32* %4
%68 = add nsw i32 %67, 1
store i32 %68, i32* %4
br label %28
69: ; preds = %48
%70 = load i16, i16* %2
ret i16 %70
}

LLVM IR (-O2):
@stdin = global i32 0
define zeroext i16 @scanBinary() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32 @fgets(i8* %2, i32 256, i32 %3)
%5 = call i64 @strlen(i8* %2)
%6 = trunc i64 %5 to i32
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %21
8: ; preds = %0
%9 = and i64 %5, 4294967295
br label %10
10: ; preds = %8, %16
%11 = phi i64 [ 0, %8 ], [ %17, %16 ]
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = call i64 @isspace(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %10
%17 = add nuw nsw i64 %11, 1
%18 = icmp eq i64 %17, %9
br i1 %18, label %41, label %10
19: ; preds = %10
%20 = trunc i64 %11 to i32
br label %21
21: ; preds = %19, %0
%22 = phi i32 [ 0, %0 ], [ %20, %19 ]
%23 = icmp slt i32 %22, %6
br i1 %23, label %24, label %41
24: ; preds = %21
%25 = zext i32 %22 to i64
br label %26
26: ; preds = %24, %33
%27 = phi i64 [ %25, %24 ], [ %38, %33 ]
%28 = phi i16 [ 0, %24 ], [ %37, %33 ]
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %27
%30 = load i8, i8* %29
%31 = and i8 %30, -2
%32 = icmp eq i8 %31, 48
br i1 %32, label %33, label %41
33: ; preds = %26
%34 = shl i16 %28, 1
%35 = icmp eq i8 %30, 49
%36 = zext i1 %35 to i16
%37 = or i16 %34, %36
%38 = add nuw nsw i64 %27, 1
%39 = trunc i64 %38 to i32
%40 = icmp slt i32 %39, %6
br i1 %40, label %26, label %41
41: ; preds = %16, %33, %26, %21
%42 = phi i16 [ 0, %21 ], [ %28, %26 ], [ %37, %33 ], [ 0, %16 ]
ret i16 %42
}