#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 nbits(int *, int);
int /*<<< orphan*/ refill(int *);
int fun_C(int *bitfill, int gkw) {
  static int tab1[] = {0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10,
                       11, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
                       23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
                       12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22};
  static int tab[] = {8,  9,   10,  11,  12,  13,  14,  15,  16,  17,  18, 19,
                      -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19};
  unsigned int tmp;
  if (gkw == 0xfe) {
    if (nbits(bitfill, 1) == 0)
      return 7;
    else
      return -8;
  }
  if (gkw != 0xff)
    return 0xff;
  tmp = nbits(bitfill, 7) - 72;
  if (tmp > 43)
    return 0xff;
  refill(bitfill);
  return tab[tab1[tmp]];
}


x86 assembly (clang, -O0):
<fun_C>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0xfe,-0x14(%rbp)
jne    116b <fun_C+0x4b>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <nbits@plt>
cmp    $0x0,%eax
jne    115f <fun_C+0x3f>
movl   $0x7,-0x4(%rbp)
jmp    11d4 <fun_C+0xb4>
movl   $0xfffffff8,-0x4(%rbp)
jmp    11d4 <fun_C+0xb4>
cmpl   $0xff,-0x14(%rbp)
je     1184 <fun_C+0x64>
movl   $0xff,-0x4(%rbp)
jmp    11d4 <fun_C+0xb4>
mov    -0x10(%rbp),%rdi
mov    $0x7,%esi
call   1030 <nbits@plt>
sub    $0x48,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x2b,-0x18(%rbp)
jbe    11ae <fun_C+0x8e>
movl   $0xff,-0x4(%rbp)
jmp    11d4 <fun_C+0xb4>
mov    -0x10(%rbp),%rdi
call   1040 <refill@plt>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
lea    0x2e7d(%rip),%rax
movslq (%rax,%rcx,4),%rcx
lea    0x2f22(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun_C>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0xff,%ebx
cmp    $0xff,%esi
je     115a <fun_C+0x3a>
cmp    $0xfe,%esi
jne    1190 <fun_C+0x70>
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <nbits@plt>
test   %eax,%eax
mov    $0x7,%eax
mov    $0xfffffff8,%ebx
cmove  %eax,%ebx
jmp    1190 <fun_C+0x70>
mov    %r14,%rdi
mov    $0x7,%esi
call   1030 <nbits@plt>
mov    %eax,%ebp
add    $0xffffffb8,%ebp
cmp    $0x2b,%ebp
ja     1190 <fun_C+0x70>
mov    %r14,%rdi
call   1040 <refill@plt>
mov    %ebp,%eax
lea    0xe7e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
lea    0xf23(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@fun_C.tab1 = internal global [44 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22]
@fun_C.tab = internal global [23 x i32] [i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 -9, i32 -10, i32 -11, i32 -12, i32 -13, i32 -14, i32 -15, i32 -16, i32 -17, i32 -18, i32 -19]
define i32 @fun_C(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp eq i32 %7, 254
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32*, i32** %4
%11 = call i32 @nbits(i32* %10, i32 1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 7, i32* %3
br label %36
14: ; preds = %9
store i32 -8, i32* %3
br label %36
15: ; preds = %2
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 255
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 255, i32* %3
br label %36
19: ; preds = %15
%20 = load i32*, i32** %4
%21 = call i32 @nbits(i32* %20, i32 7)
%22 = sub nsw i32 %21, 72
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp ugt i32 %23, 43
br i1 %24, label %25, label %26
25: ; preds = %19
store i32 255, i32* %3
br label %36
26: ; preds = %19
%27 = load i32*, i32** %4
%28 = call i32 @refill(i32* %27)
%29 = load i32, i32* %6
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds [44 x i32], [44 x i32]* @fun_C.tab1, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [23 x i32], [23 x i32]* @fun_C.tab, i64 0, i64 %33
%35 = load i32, i32* %34
store i32 %35, i32* %3
br label %36
36: ; preds = %26, %25, %18, %14, %13
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@fun_C.tab1 = internal unnamed_addr constant [44 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 23, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22]
@fun_C.tab = internal unnamed_addr constant [23 x i32] [i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 -9, i32 -10, i32 -11, i32 -12, i32 -13, i32 -14, i32 -15, i32 -16, i32 -17, i32 -18, i32 -19]
define i32 @fun_C(i32* %0, i32 %1) {
switch i32 %1, label %19 [
i32 254, label %3
i32 255, label %7
]
3: ; preds = %2
%4 = tail call i32 @nbits(i32* %0, i32 1)
%5 = icmp eq i32 %4, 0
%6 = select i1 %5, i32 7, i32 -8
br label %19
7: ; preds = %2
%8 = tail call i32 @nbits(i32* %0, i32 7)
%9 = add nsw i32 %8, -72
%10 = icmp ugt i32 %9, 43
br i1 %10, label %19, label %11
11: ; preds = %7
%12 = tail call i32 @refill(i32* %0)
%13 = zext i32 %9 to i64
%14 = getelementptr inbounds [44 x i32], [44 x i32]* @fun_C.tab1, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [23 x i32], [23 x i32]* @fun_C.tab, i64 0, i64 %16
%18 = load i32, i32* %17
br label %19
19: ; preds = %7, %2, %3, %11
%20 = phi i32 [ %18, %11 ], [ %6, %3 ], [ 255, %2 ], [ 255, %7 ]
ret i32 %20
}