#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 rc {
  int dummy;
};

/* Variables and functions */
scalar_t__ rc_is_bit_0(struct rc *, unsigned short *);
int /*<<< orphan*/ rc_update_bit_0(struct rc *, unsigned short *);
int /*<<< orphan*/ rc_update_bit_1(struct rc *, unsigned short *);
int rc_get_bit(struct rc *rc, unsigned short int *p, int *symbol) {
  if (rc_is_bit_0(rc, p)) {
    rc_update_bit_0(rc, p);
    *symbol *= 2;
    return 0;
  } else {
    rc_update_bit_1(rc, p);
    *symbol = *symbol * 2 + 1;
    return 1;
  }
}


x86 assembly (clang, -O0):
<rc_get_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <rc_is_bit_0@plt>
cmp    $0x0,%rax
je     117f <rc_get_bit+0x4f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <rc_update_bit_0@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
shl    $0x1,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11a5 <rc_get_bit+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <rc_update_bit_1@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rc_get_bit>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <rc_is_bit_0@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
test   %rax,%rax
je     115c <rc_get_bit+0x2c>
call   1030 <rc_update_bit_0@plt>
mov    (%r14),%ecx
add    %ecx,%ecx
xor    %eax,%eax
jmp    116f <rc_get_bit+0x3f>
call   1050 <rc_update_bit_1@plt>
mov    (%r14),%eax
lea    (%rax,%rax,1),%ecx
add    $0x1,%ecx
mov    $0x1,%eax
mov    %ecx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.rc = type { i32 }
define i32 @rc_get_bit(%struct.rc* %0, i16* %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.rc*
%6 = alloca i16*
%7 = alloca i32*
store %struct.rc* %0, %struct.rc** %5
store i16* %1, i16** %6
store i32* %2, i32** %7
%8 = load %struct.rc*, %struct.rc** %5
%9 = load i16*, i16** %6
%10 = call i64 @rc_is_bit_0(%struct.rc* %8, i16* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %3
%13 = load %struct.rc*, %struct.rc** %5
%14 = load i16*, i16** %6
%15 = call i32 @rc_update_bit_0(%struct.rc* %13, i16* %14)
%16 = load i32*, i32** %7
%17 = load i32, i32* %16
%18 = mul nsw i32 %17, 2
store i32 %18, i32* %16
store i32 0, i32* %4
br label %28
19: ; preds = %3
%20 = load %struct.rc*, %struct.rc** %5
%21 = load i16*, i16** %6
%22 = call i32 @rc_update_bit_1(%struct.rc* %20, i16* %21)
%23 = load i32*, i32** %7
%24 = load i32, i32* %23
%25 = mul nsw i32 %24, 2
%26 = add nsw i32 %25, 1
%27 = load i32*, i32** %7
store i32 %26, i32* %27
store i32 1, i32* %4
br label %28
28: ; preds = %19, %12
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
%struct.rc = type { i32 }
define i32 @rc_get_bit(%struct.rc* %0, i16* %1, i32* nocapture %2) {
%4 = tail call i64 @rc_is_bit_0(%struct.rc* %0, i16* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i32 @rc_update_bit_0(%struct.rc* %0, i16* %1)
%8 = load i32, i32* %2
%9 = shl nsw i32 %8, 1
br label %15
10: ; preds = %3
%11 = tail call i32 @rc_update_bit_1(%struct.rc* %0, i16* %1)
%12 = load i32, i32* %2
%13 = shl nsw i32 %12, 1
%14 = or i32 %13, 1
br label %15
15: ; preds = %10, %6
%16 = phi i32 [ %14, %10 ], [ %9, %6 ]
%17 = phi i32 [ 1, %10 ], [ 0, %6 ]
store i32 %16, i32* %2
ret i32 %17
}