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

/* Variables and functions */
int fread(unsigned char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int unpack_input(unsigned char *code, int bits) {
  static unsigned int in_buffer = 0;
  static int in_bits = 0;
  unsigned char in_byte;
  if (in_bits < bits) {
    if (fread(&in_byte, sizeof(char), 1, stdin) != 1) {
      *code = 0;
      return (-1);
    }
    in_buffer |= (in_byte << in_bits);
    in_bits += 8;
  }
  *code = in_buffer & ((1 << bits) - 1);
  in_buffer >>= bits;
  in_bits -= bits;
  return (in_bits > 0);
}


x86 assembly (clang, -O0):
<unpack_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2f0b(%rip),%eax
cmp    -0x14(%rbp),%eax
jge    118a <unpack_input+0x7a>
mov    0x2eb3(%rip),%rax
mov    (%rax),%ecx
lea    -0x15(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
je     1163 <unpack_input+0x53>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <unpack_input+0xcd>
movzbl -0x15(%rbp),%eax
mov    0x2ec3(%rip),%ecx
shl    %cl,%eax
or     0x2eb7(%rip),%eax
mov    %eax,0x2eb1(%rip)
mov    0x2eaf(%rip),%eax
add    $0x8,%eax
mov    %eax,0x2ea6(%rip)
mov    0x2e9c(%rip),%eax
mov    -0x14(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
sub    $0x1,%ecx
and    %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x14(%rbp),%ecx
mov    0x2e7a(%rip),%eax
shr    %cl,%eax
mov    %eax,0x2e72(%rip)
mov    -0x14(%rbp),%ecx
mov    0x2e6d(%rip),%eax
sub    %ecx,%eax
mov    %eax,0x2e65(%rip)
cmpl   $0x0,0x2e5e(%rip)
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpack_input>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    0x2f11(%rip),%edx
cmp    %esi,%edx
jge    115f <unpack_input+0x4f>
mov    0x2ebe(%rip),%rax
mov    (%rax),%ecx
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    118c <unpack_input+0x7c>
movzbl 0x7(%rsp),%eax
mov    0x2ee0(%rip),%edx
mov    %edx,%ecx
shl    %cl,%eax
or     0x2ed2(%rip),%eax
add    $0x8,%edx
jmp    1165 <unpack_input+0x55>
mov    0x2ec7(%rip),%eax
mov    $0xffffffff,%esi
mov    %ebx,%ecx
shl    %cl,%esi
not    %esi
and    %eax,%esi
mov    %sil,(%r14)
shr    %cl,%eax
mov    %eax,0x2eaf(%rip)
xor    %eax,%eax
sub    %ebx,%edx
mov    %edx,0x2ea9(%rip)
setg   %al
jmp    1195 <unpack_input+0x85>
movb   $0x0,(%r14)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@unpack_input.in_buffer = internal global i32 0
@unpack_input.in_bits = internal global i32 0
@stdin = global i32 0
define i32 @unpack_input(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* @unpack_input.in_bits
%8 = load i32, i32* %5
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %25
10: ; preds = %2
%11 = load i32, i32* @stdin
%12 = call i32 @fread(i8* %6, i32 1, i32 1, i32 %11)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = load i8*, i8** %4
store i8 0, i8* %15
store i32 -1, i32* %3
br label %42
16: ; preds = %10
%17 = load i8, i8* %6
%18 = zext i8 %17 to i32
%19 = load i32, i32* @unpack_input.in_bits
%20 = shl i32 %18, %19
%21 = load i32, i32* @unpack_input.in_buffer
%22 = or i32 %21, %20
store i32 %22, i32* @unpack_input.in_buffer
%23 = load i32, i32* @unpack_input.in_bits
%24 = add nsw i32 %23, 8
store i32 %24, i32* @unpack_input.in_bits
br label %25
25: ; preds = %16, %2
%26 = load i32, i32* @unpack_input.in_buffer
%27 = load i32, i32* %5
%28 = shl i32 1, %27
%29 = sub nsw i32 %28, 1
%30 = and i32 %26, %29
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %4
store i8 %31, i8* %32
%33 = load i32, i32* %5
%34 = load i32, i32* @unpack_input.in_buffer
%35 = lshr i32 %34, %33
store i32 %35, i32* @unpack_input.in_buffer
%36 = load i32, i32* %5
%37 = load i32, i32* @unpack_input.in_bits
%38 = sub nsw i32 %37, %36
store i32 %38, i32* @unpack_input.in_bits
%39 = load i32, i32* @unpack_input.in_bits
%40 = icmp sgt i32 %39, 0
%41 = zext i1 %40 to i32
store i32 %41, i32* %3
br label %42
42: ; preds = %25, %14
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@unpack_input.in_buffer = internal unnamed_addr global i32 0
@unpack_input.in_bits = internal unnamed_addr global i32 0
@stdin = global i32 0
define i32 @unpack_input(i8* nocapture writeonly %0, i32 %1) {
%3 = alloca i8
%4 = load i32, i32* @unpack_input.in_bits
%5 = icmp slt i32 %4, %1
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = load i32, i32* @unpack_input.in_buffer
br label %21
8: ; preds = %2
%9 = load i32, i32* @stdin
%10 = call i32 @fread(i8* %3, i32 1, i32 1, i32 %9)
%11 = icmp eq i32 %10, 1
br i1 %11, label %13, label %12
12: ; preds = %8
store i8 0, i8* %0
br label %32
13: ; preds = %8
%14 = load i8, i8* %3
%15 = zext i8 %14 to i32
%16 = load i32, i32* @unpack_input.in_bits
%17 = shl i32 %15, %16
%18 = load i32, i32* @unpack_input.in_buffer
%19 = or i32 %18, %17
%20 = add nsw i32 %16, 8
br label %21
21: ; preds = %6, %13
%22 = phi i32 [ %4, %6 ], [ %20, %13 ]
%23 = phi i32 [ %7, %6 ], [ %19, %13 ]
%24 = shl nsw i32 -1, %1
%25 = xor i32 %24, -1
%26 = and i32 %23, %25
%27 = trunc i32 %26 to i8
store i8 %27, i8* %0
%28 = lshr i32 %23, %1
store i32 %28, i32* @unpack_input.in_buffer
%29 = sub nsw i32 %22, %1
store i32 %29, i32* @unpack_input.in_bits
%30 = icmp sgt i32 %29, 0
%31 = zext i1 %30 to i32
br label %32
32: ; preds = %21, %12
%33 = phi i32 [ -1, %12 ], [ %31, %21 ]
ret i32 %33
}