#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 /*<<< orphan*/ value;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ die(char *, char *, int, char *);
const char *huffman_bin(unsigned long value, unsigned int bits) {
  static char buf[(8 * sizeof(value)) + 1];
  char *out = buf;
  do {
    if (1 && !(bits < sizeof(buf))) {
      die("Assertion failed at %s line %d: %s\n",
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/LiamLeane/wimboot/refs/heads/master/"
          "grub-core/wimboot/src/huffman.c",
          46, "bits < sizeof ( buf )");
    }
  } while (0);
  while (bits--)
    *(out++) = ((value & (1 << bits)) ? '1' : '0');
  *out = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<huffman_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0x2f1a(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
cmp    $0x41,%rax
jb     1156 <huffman_bin+0x46>
lea    0xec2(%rip),%rdi
lea    0xedf(%rip),%rsi
mov    $0x2e,%edx
lea    0xf71(%rip),%rcx
call   1030 <die@plt>
jmp    115b <huffman_bin+0x4b>
jmp    1160 <huffman_bin+0x50>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     11b0 <huffman_bin+0xa0>
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
and    %rax,%rdx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1160 <huffman_bin+0x50>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e82(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<huffman_bin>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
cmp    $0x41,%esi
jae    1194 <huffman_bin+0x84>
test   %r14d,%r14d
je     11f9 <huffman_bin+0xe9>
test   $0x1,%r14b
jne    11bd <huffman_bin+0xad>
lea    0x2f06(%rip),%rdx
mov    %r14d,%eax
cmp    $0x1,%r14d
je     11f0 <huffman_bin+0xe0>
add    $0xffffffff,%eax
nopw   0x0(%rax,%rax,1)
mov    $0x1,%esi
mov    %eax,%ecx
shl    %cl,%esi
movslq %esi,%rcx
and    %r15,%rcx
cmp    $0x1,%rcx
mov    $0x31,%bl
sbb    $0x0,%bl
lea    -0x1(%rax),%ecx
mov    $0x1,%esi
shl    %cl,%esi
mov    %bl,(%rdx)
movslq %esi,%rcx
and    %r15,%rcx
cmp    $0x1,%rcx
mov    $0x31,%cl
sbb    $0x0,%cl
mov    %cl,0x1(%rdx)
add    $0x2,%rdx
add    $0xfffffffe,%eax
cmp    $0xffffffff,%eax
jne    1150 <huffman_bin+0x40>
jmp    1200 <huffman_bin+0xf0>
lea    0xe65(%rip),%rdi
lea    0xe82(%rip),%rsi
lea    0xf19(%rip),%rcx
mov    $0x2e,%edx
call   1030 <die@plt>
test   $0x1,%r14b
je     1133 <huffman_bin+0x23>
lea    -0x1(%r14),%eax
mov    $0x1,%edx
mov    %eax,%ecx
shl    %cl,%edx
movslq %edx,%rcx
and    %r15,%rcx
cmp    $0x1,%rcx
mov    $0x31,%cl
sbb    $0x0,%cl
mov    %cl,0x2e61(%rip)
lea    0x2e5b(%rip),%rdx
cmp    $0x1,%r14d
jne    1147 <huffman_bin+0x37>
lea    0x2e4a(%rip),%rdx
jmp    1200 <huffman_bin+0xf0>
lea    0x2e40(%rip),%rdx
movb   $0x0,(%rdx)
lea    0x2e36(%rip),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@huffman_bin.buf = internal global [65 x i8] zeroinitializer
@.str = [36 x i8] c"Assertion failed at %s line %d: %s\0A\00"
@.str.1 = [158 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LiamLeane/wimboot/refs/heads/master/grub-core/wimboot/src/huffman.c\00"
@.str.2 = [22 x i8] c"bits < sizeof ( buf )\00"
define i8* @huffman_bin(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
store i64 %0, i64* %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([65 x i8], [65 x i8]* @huffman_bin.buf, i64 0, i64 0), i8** %5
br label %6
6: ; preds = %2
%7 = load i32, i32* %4
%8 = zext i32 %7 to i64
%9 = icmp ult i64 %8, 65
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = call i32 @die(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.1, i64 0, i64 0), i32 46, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
br label %13
13: ; preds = %12
br label %14
14: ; preds = %18, %13
%15 = load i32, i32* %4
%16 = add i32 %15, -1
store i32 %16, i32* %4
%17 = icmp ne i32 %15, 0
br i1 %17, label %18, label %30
18: ; preds = %14
%19 = load i64, i64* %3
%20 = load i32, i32* %4
%21 = shl i32 1, %20
%22 = sext i32 %21 to i64
%23 = and i64 %19, %22
%24 = icmp ne i64 %23, 0
%25 = zext i1 %24 to i64
%26 = select i1 %24, i32 49, i32 48
%27 = trunc i32 %26 to i8
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
store i8 %27, i8* %28
br label %14
30: ; preds = %14
%31 = load i8*, i8** %5
store i8 0, i8* %31
ret i8* getelementptr inbounds ([65 x i8], [65 x i8]* @huffman_bin.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@huffman_bin.buf = internal global [65 x i8] zeroinitializer
@.str = [36 x i8] c"Assertion failed at %s line %d: %s\0A\00"
@.str.1 = [158 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LiamLeane/wimboot/refs/heads/master/grub-core/wimboot/src/huffman.c\00"
@.str.2 = [22 x i8] c"bits < sizeof ( buf )\00"
define i8* @huffman_bin(i64 %0, i32 %1) {
%3 = icmp ult i32 %1, 65
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @die(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str.1, i64 0, i64 0), i32 46, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %8
6: ; preds = %2
%7 = icmp eq i32 %1, 0
br i1 %7, label %40, label %8
8: ; preds = %4, %6
%9 = and i32 %1, 1
%10 = icmp eq i32 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %8
%12 = add i32 %1, -1
%13 = shl nuw i32 1, %12
%14 = sext i32 %13 to i64
%15 = and i64 %14, %0
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i8 48, i8 49
store i8 %17, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @huffman_bin.buf, i64 0, i64 0)
br label %18
18: ; preds = %11, %8
%19 = phi i32 [ %1, %8 ], [ %12, %11 ]
%20 = phi i8* [ getelementptr inbounds ([65 x i8], [65 x i8]* @huffman_bin.buf, i64 0, i64 0), %8 ], [ getelementptr inbounds ([65 x i8], [65 x i8]* @huffman_bin.buf, i64 0, i64 1), %11 ]
%21 = icmp eq i32 %1, 1
br i1 %21, label %40, label %22
22: ; preds = %18, %22
%23 = phi i32 [ %32, %22 ], [ %19, %18 ]
%24 = phi i8* [ %38, %22 ], [ %20, %18 ]
%25 = add i32 %23, -1
%26 = shl nuw i32 1, %25
%27 = sext i32 %26 to i64
%28 = and i64 %27, %0
%29 = icmp eq i64 %28, 0
%30 = select i1 %29, i8 48, i8 49
%31 = getelementptr inbounds i8, i8* %24, i64 1
store i8 %30, i8* %24
%32 = add i32 %23, -2
%33 = shl nuw i32 1, %32
%34 = sext i32 %33 to i64
%35 = and i64 %34, %0
%36 = icmp eq i64 %35, 0
%37 = select i1 %36, i8 48, i8 49
%38 = getelementptr inbounds i8, i8* %24, i64 2
store i8 %37, i8* %31
%39 = icmp eq i32 %32, 0
br i1 %39, label %40, label %22
40: ; preds = %18, %22, %6
%41 = phi i8* [ getelementptr inbounds ([65 x i8], [65 x i8]* @huffman_bin.buf, i64 0, i64 0), %6 ], [ getelementptr inbounds ([65 x i8], [65 x i8]* @huffman_bin.buf, i64 0, i64 1), %18 ], [ %38, %22 ]
store i8 0, i8* %41
ret i8* getelementptr inbounds ([65 x i8], [65 x i8]* @huffman_bin.buf, i64 0, i64 0)
}