#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 */
struct bs_iter {
  int dummy;
};
struct bit_stream {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ bitstream_destroy(struct bit_stream *);
struct bit_stream *bitstream_init();
int /*<<< orphan*/ bitstream_print(struct bit_stream *);
int /*<<< orphan*/ bitstream_push(struct bit_stream *, int, int);
int /*<<< orphan*/ bitstream_push_str(struct bit_stream *, char *);
int /*<<< orphan*/ bs_iter_destroy(struct bs_iter *);
struct bs_iter *bs_iter_init(struct bit_stream *);
int bs_iter_unpack(struct bs_iter *, int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  struct bit_stream *bs = bitstream_init();
  bitstream_push(bs, 15, 15);
  bitstream_push(bs, 1, 2);
  bitstream_push(bs, 22, 20);
  bitstream_push(bs, 122, 11);
  bitstream_push(bs, 1023, 19);
  bitstream_print(bs);
  bitstream_push_str(bs, "10111011");
  bitstream_print(bs);
  struct bs_iter *iter = bs_iter_init(bs);
  printf("Unpack 4: %d\n", bs_iter_unpack(iter, 4));
  printf("Unpack 4: %d\n", bs_iter_unpack(iter, 4));
  printf("Unpack 4: %d\n", bs_iter_unpack(iter, 4));
  printf("Unpack 4: %d\n", bs_iter_unpack(iter, 4));
  printf("Unpack 8: %d\n", bs_iter_unpack(iter, 8));
  printf("Unpack 8: %d\n", bs_iter_unpack(iter, 8));
  printf("Unpack 8: %d\n", bs_iter_unpack(iter, 8));
  printf("Unpack 8: %d\n", bs_iter_unpack(iter, 8));
  printf("Unpack 8: %d\n", bs_iter_unpack(iter, 8));
  printf("Unpack 8: %d\n", bs_iter_unpack(iter, 8));
  printf("Unpack 8: %d\n", bs_iter_unpack(iter, 8));
  printf("Unpack 8: %d\n", bs_iter_unpack(iter, 8));
  bitstream_destroy(bs);
  bs_iter_destroy(iter);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1090 <bitstream_init@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0xf,%edx
mov    %edx,%esi
call   1060 <bitstream_push@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
call   1060 <bitstream_push@plt>
mov    -0x8(%rbp),%rdi
mov    $0x16,%esi
mov    $0x14,%edx
call   1060 <bitstream_push@plt>
mov    -0x8(%rbp),%rdi
mov    $0x7a,%esi
mov    $0xb,%edx
call   1060 <bitstream_push@plt>
mov    -0x8(%rbp),%rdi
mov    $0x3ff,%esi
mov    $0x13,%edx
call   1060 <bitstream_push@plt>
mov    -0x8(%rbp),%rdi
call   1030 <bitstream_print@plt>
mov    -0x8(%rbp),%rdi
lea    0xded(%rip),%rsi
call   1050 <bitstream_push_str@plt>
mov    -0x8(%rbp),%rdi
call   1030 <bitstream_print@plt>
mov    -0x8(%rbp),%rdi
call   10b0 <bs_iter_init@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1070 <bs_iter_unpack@plt>
mov    %eax,%esi
lea    0xdc4(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1070 <bs_iter_unpack@plt>
mov    %eax,%esi
lea    0xda8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1070 <bs_iter_unpack@plt>
mov    %eax,%esi
lea    0xd8c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1070 <bs_iter_unpack@plt>
mov    %eax,%esi
lea    0xd70(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %eax,%esi
lea    0xd62(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %eax,%esi
lea    0xd46(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %eax,%esi
lea    0xd2a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %eax,%esi
lea    0xd0e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %eax,%esi
lea    0xcf2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %eax,%esi
lea    0xcd6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %eax,%esi
lea    0xcba(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %eax,%esi
lea    0xc9e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1080 <bitstream_destroy@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <bs_iter_destroy@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1090 <bitstream_init@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0xf,%esi
mov    $0xf,%edx
call   1060 <bitstream_push@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
call   1060 <bitstream_push@plt>
mov    %r14,%rdi
mov    $0x16,%esi
mov    $0x14,%edx
call   1060 <bitstream_push@plt>
mov    %r14,%rdi
mov    $0x7a,%esi
mov    $0xb,%edx
call   1060 <bitstream_push@plt>
mov    %r14,%rdi
mov    $0x3ff,%esi
mov    $0x13,%edx
call   1060 <bitstream_push@plt>
mov    %r14,%rdi
call   1030 <bitstream_print@plt>
lea    0xdf8(%rip),%rsi
mov    %r14,%rdi
call   1050 <bitstream_push_str@plt>
mov    %r14,%rdi
call   1030 <bitstream_print@plt>
mov    %r14,%rdi
call   10b0 <bs_iter_init@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x4,%esi
call   1070 <bs_iter_unpack@plt>
lea    0xdd2(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1070 <bs_iter_unpack@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1070 <bs_iter_unpack@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1070 <bs_iter_unpack@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
lea    0xd7d(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1070 <bs_iter_unpack@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1080 <bitstream_destroy@plt>
mov    %rbx,%rdi
call   10a0 <bs_iter_destroy@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.bit_stream = type { i32 }
%struct.bs_iter = type { i32 }
@.str = [9 x i8] c"10111011\00"
@.str.1 = [14 x i8] c"Unpack 4: %d\0A\00"
@.str.2 = [14 x i8] c"Unpack 8: %d\0A\00"
define i32 @main() {
%1 = alloca %struct.bit_stream*
%2 = alloca %struct.bs_iter*
%3 = call %struct.bit_stream* (...) @bitstream_init()
store %struct.bit_stream* %3, %struct.bit_stream** %1
%4 = load %struct.bit_stream*, %struct.bit_stream** %1
%5 = call i32 @bitstream_push(%struct.bit_stream* %4, i32 15, i32 15)
%6 = load %struct.bit_stream*, %struct.bit_stream** %1
%7 = call i32 @bitstream_push(%struct.bit_stream* %6, i32 1, i32 2)
%8 = load %struct.bit_stream*, %struct.bit_stream** %1
%9 = call i32 @bitstream_push(%struct.bit_stream* %8, i32 22, i32 20)
%10 = load %struct.bit_stream*, %struct.bit_stream** %1
%11 = call i32 @bitstream_push(%struct.bit_stream* %10, i32 122, i32 11)
%12 = load %struct.bit_stream*, %struct.bit_stream** %1
%13 = call i32 @bitstream_push(%struct.bit_stream* %12, i32 1023, i32 19)
%14 = load %struct.bit_stream*, %struct.bit_stream** %1
%15 = call i32 @bitstream_print(%struct.bit_stream* %14)
%16 = load %struct.bit_stream*, %struct.bit_stream** %1
%17 = call i32 @bitstream_push_str(%struct.bit_stream* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%18 = load %struct.bit_stream*, %struct.bit_stream** %1
%19 = call i32 @bitstream_print(%struct.bit_stream* %18)
%20 = load %struct.bit_stream*, %struct.bit_stream** %1
%21 = call %struct.bs_iter* @bs_iter_init(%struct.bit_stream* %20)
store %struct.bs_iter* %21, %struct.bs_iter** %2
%22 = load %struct.bs_iter*, %struct.bs_iter** %2
%23 = call i32 @bs_iter_unpack(%struct.bs_iter* %22, i32 4)
%24 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load %struct.bs_iter*, %struct.bs_iter** %2
%26 = call i32 @bs_iter_unpack(%struct.bs_iter* %25, i32 4)
%27 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = load %struct.bs_iter*, %struct.bs_iter** %2
%29 = call i32 @bs_iter_unpack(%struct.bs_iter* %28, i32 4)
%30 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load %struct.bs_iter*, %struct.bs_iter** %2
%32 = call i32 @bs_iter_unpack(%struct.bs_iter* %31, i32 4)
%33 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = load %struct.bs_iter*, %struct.bs_iter** %2
%35 = call i32 @bs_iter_unpack(%struct.bs_iter* %34, i32 8)
%36 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = load %struct.bs_iter*, %struct.bs_iter** %2
%38 = call i32 @bs_iter_unpack(%struct.bs_iter* %37, i32 8)
%39 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load %struct.bs_iter*, %struct.bs_iter** %2
%41 = call i32 @bs_iter_unpack(%struct.bs_iter* %40, i32 8)
%42 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = load %struct.bs_iter*, %struct.bs_iter** %2
%44 = call i32 @bs_iter_unpack(%struct.bs_iter* %43, i32 8)
%45 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %44)
%46 = load %struct.bs_iter*, %struct.bs_iter** %2
%47 = call i32 @bs_iter_unpack(%struct.bs_iter* %46, i32 8)
%48 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %47)
%49 = load %struct.bs_iter*, %struct.bs_iter** %2
%50 = call i32 @bs_iter_unpack(%struct.bs_iter* %49, i32 8)
%51 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %50)
%52 = load %struct.bs_iter*, %struct.bs_iter** %2
%53 = call i32 @bs_iter_unpack(%struct.bs_iter* %52, i32 8)
%54 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %53)
%55 = load %struct.bs_iter*, %struct.bs_iter** %2
%56 = call i32 @bs_iter_unpack(%struct.bs_iter* %55, i32 8)
%57 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %56)
%58 = load %struct.bit_stream*, %struct.bit_stream** %1
%59 = call i32 @bitstream_destroy(%struct.bit_stream* %58)
%60 = load %struct.bs_iter*, %struct.bs_iter** %2
%61 = call i32 @bs_iter_destroy(%struct.bs_iter* %60)
ret i32 0
}

LLVM IR (-O2):
%struct.bit_stream = type { i32 }
%struct.bs_iter = type { i32 }
@.str = [9 x i8] c"10111011\00"
@.str.1 = [14 x i8] c"Unpack 4: %d\0A\00"
@.str.2 = [14 x i8] c"Unpack 8: %d\0A\00"
define i32 @main() {
%1 = tail call %struct.bit_stream* (...) @bitstream_init()
%2 = tail call i32 @bitstream_push(%struct.bit_stream* %1, i32 15, i32 15)
%3 = tail call i32 @bitstream_push(%struct.bit_stream* %1, i32 1, i32 2)
%4 = tail call i32 @bitstream_push(%struct.bit_stream* %1, i32 22, i32 20)
%5 = tail call i32 @bitstream_push(%struct.bit_stream* %1, i32 122, i32 11)
%6 = tail call i32 @bitstream_push(%struct.bit_stream* %1, i32 1023, i32 19)
%7 = tail call i32 @bitstream_print(%struct.bit_stream* %1)
%8 = tail call i32 @bitstream_push_str(%struct.bit_stream* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @bitstream_print(%struct.bit_stream* %1)
%10 = tail call %struct.bs_iter* @bs_iter_init(%struct.bit_stream* %1)
%11 = tail call i32 @bs_iter_unpack(%struct.bs_iter* %10, i32 4)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = tail call i32 @bs_iter_unpack(%struct.bs_iter* %10, i32 4)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = tail call i32 @bs_iter_unpack(%struct.bs_iter* %10, i32 4)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = tail call i32 @bs_iter_unpack(%struct.bs_iter* %10, i32 4)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = tail call i32 @bs_iter_unpack(%struct.bs_iter* %10, i32 8)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = tail call i32 @bs_iter_unpack(%struct.bs_iter* %10, i32 8)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = tail call i32 @bs_iter_unpack(%struct.bs_iter* %10, i32 8)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = tail call i32 @bs_iter_unpack(%struct.bs_iter* %10, i32 8)
%26 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = tail call i32 @bs_iter_unpack(%struct.bs_iter* %10, i32 8)
%28 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = tail call i32 @bs_iter_unpack(%struct.bs_iter* %10, i32 8)
%30 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = tail call i32 @bs_iter_unpack(%struct.bs_iter* %10, i32 8)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = tail call i32 @bs_iter_unpack(%struct.bs_iter* %10, i32 8)
%34 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = tail call i32 @bitstream_destroy(%struct.bit_stream* %1)
%36 = tail call i32 @bs_iter_destroy(%struct.bs_iter* %10)
ret i32 0
}