#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*/ uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ minipack_pack_bin16(void *, int /*<<< orphan*/, size_t *);
int /*<<< orphan*/ minipack_pack_bin32(void *, int, size_t *);
int /*<<< orphan*/ minipack_pack_bin8(void *, int /*<<< orphan*/, size_t *);
void minipack_pack_bin(void *ptr, uint32_t length, size_t *sz) {
  if (length <= 255) {
    minipack_pack_bin8(ptr, (uint8_t)length, sz);
    return;
  } else if (length <= 65535) {
    minipack_pack_bin16(ptr, (uint16_t)length, sz);
    return;
  }
  minipack_pack_bin32(ptr, length, sz);
}


x86 assembly (clang, -O0):
<minipack_pack_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0xff,-0xc(%rbp)
jg     1165 <minipack_pack_bin+0x35>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <minipack_pack_bin8@plt>
jmp    119c <minipack_pack_bin+0x6c>
cmpl   $0xffff,-0xc(%rbp)
jg     1187 <minipack_pack_bin+0x57>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1050 <minipack_pack_bin16@plt>
jmp    119c <minipack_pack_bin+0x6c>
jmp    118c <minipack_pack_bin+0x5c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <minipack_pack_bin32@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<minipack_pack_bin>:
cmp    $0xff,%esi
jg     113d <minipack_pack_bin+0xd>
jmp    1040 <minipack_pack_bin8@plt>
cmp    $0xffff,%esi
ja     114a <minipack_pack_bin+0x1a>
jmp    1050 <minipack_pack_bin16@plt>
jmp    1030 <minipack_pack_bin32@plt>

LLVM IR (-O0):
define void @minipack_pack_bin(i8* %0, i32 %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64* %2, i64** %6
%7 = load i32, i32* %5
%8 = icmp sle i32 %7, 255
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i8*, i8** %4
%11 = load i32, i32* %5
%12 = load i64*, i64** %6
%13 = call i32 @minipack_pack_bin8(i8* %10, i32 %11, i64* %12)
br label %28
14: ; preds = %3
%15 = load i32, i32* %5
%16 = icmp sle i32 %15, 65535
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = load i32, i32* %5
%20 = load i64*, i64** %6
%21 = call i32 @minipack_pack_bin16(i8* %18, i32 %19, i64* %20)
br label %28
22: ; preds = %14
br label %23
23: ; preds = %22
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = load i64*, i64** %6
%27 = call i32 @minipack_pack_bin32(i8* %24, i32 %25, i64* %26)
br label %28
28: ; preds = %23, %17, %9
ret void
}

LLVM IR (-O2):
define void @minipack_pack_bin(i8* %0, i32 %1, i64* %2) {
%4 = icmp slt i32 %1, 256
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @minipack_pack_bin8(i8* %0, i32 %1, i64* %2)
br label %13
7: ; preds = %3
%8 = icmp ult i32 %1, 65536
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @minipack_pack_bin16(i8* %0, i32 %1, i64* %2)
br label %13
11: ; preds = %7
%12 = tail call i32 @minipack_pack_bin32(i8* %0, i32 %1, i64* %2)
br label %13
13: ; preds = %11, %9, %5
ret void
}