#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 uint8_t;
typedef int int32_t;

/* Variables and functions */
int readInBit();
int32_t readInt(void) {
  uint8_t dataSize = 0;
  for (int i = 0; i < 5; i++) {
    dataSize <<= 1;
    uint8_t newBit = readInBit();
    dataSize |= newBit;
  }
  int32_t dataRead = 0;
  for (int i = 0; i <= dataSize; i++) {
    dataRead <<= 1;
    uint8_t newBit = readInBit();
    dataRead |= newBit;
  }
  return dataRead;
}


x86 assembly (clang, -O0):
<readInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    115a <readInt+0x4a>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1030 <readInBit@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1126 <readInt+0x16>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     119e <readInt+0x8e>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <readInBit@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1168 <readInt+0x58>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readInt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <readInBit@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1030 <readInBit@plt>
mov    %eax,%ebx
shl    $0x2,%r14d
add    %eax,%ebx
or     %r14d,%ebx
xor    %eax,%eax
call   1030 <readInBit@plt>
mov    %eax,%r14d
or     %ebx,%r14d
xor    %eax,%eax
call   1030 <readInBit@plt>
mov    %eax,%r15d
shl    $0x2,%r14d
add    %eax,%r15d
or     %r14d,%r15d
xor    %eax,%eax
call   1030 <readInBit@plt>
mov    %eax,%r14d
or     %r15d,%r14d
js     1185 <readInt+0x75>
add    $0x1,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
add    %ebx,%ebx
xor    %eax,%eax
call   1030 <readInBit@plt>
mov    %eax,%ebp
or     %ebx,%ebp
mov    %ebp,%ebx
add    $0xffffffff,%r14d
jne    1170 <readInt+0x60>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @readInt() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %7
7: ; preds = %17, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 5
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = load i32, i32* %1
%12 = shl i32 %11, 1
store i32 %12, i32* %1
%13 = call i32 (...) @readInBit()
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = load i32, i32* %1
%16 = or i32 %15, %14
store i32 %16, i32* %1
br label %17
17: ; preds = %10
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %7
20: ; preds = %7
store i32 0, i32* %4
store i32 0, i32* %5
br label %21
21: ; preds = %32, %20
%22 = load i32, i32* %5
%23 = load i32, i32* %1
%24 = icmp sle i32 %22, %23
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = load i32, i32* %4
%27 = shl i32 %26, 1
store i32 %27, i32* %4
%28 = call i32 (...) @readInBit()
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = load i32, i32* %4
%31 = or i32 %30, %29
store i32 %31, i32* %4
br label %32
32: ; preds = %25
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %21
35: ; preds = %21
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
define i32 @readInt() {
%1 = tail call i32 (...) @readInBit()
%2 = tail call i32 (...) @readInBit()
%3 = shl i32 %1, 2
%4 = shl i32 %2, 1
%5 = or i32 %3, %4
%6 = tail call i32 (...) @readInBit()
%7 = or i32 %6, %5
%8 = tail call i32 (...) @readInBit()
%9 = shl i32 %7, 2
%10 = shl i32 %8, 1
%11 = or i32 %9, %10
%12 = tail call i32 (...) @readInBit()
%13 = or i32 %12, %11
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %17, %0
%16 = phi i32 [ 0, %0 ], [ %22, %17 ]
ret i32 %16
17: ; preds = %0, %17
%18 = phi i32 [ %23, %17 ], [ 0, %0 ]
%19 = phi i32 [ %22, %17 ], [ 0, %0 ]
%20 = shl i32 %19, 1
%21 = tail call i32 (...) @readInBit()
%22 = or i32 %21, %20
%23 = add nuw i32 %18, 1
%24 = icmp eq i32 %18, %13
br i1 %24, label %15, label %17
}