#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_fixstr(void *, int /*<<< orphan*/, size_t *);
int /*<<< orphan*/ minipack_pack_str16(void *, int /*<<< orphan*/, size_t *);
int /*<<< orphan*/ minipack_pack_str32(void *, int, size_t *);
int /*<<< orphan*/ minipack_pack_str8(void *, int /*<<< orphan*/, size_t *);
void minipack_pack_str(void *ptr, uint32_t length, size_t *sz) {
  if (length <= 31) {
    minipack_pack_fixstr(ptr, (uint8_t)length, sz);
    return;
  } else if (length <= 255) {
    minipack_pack_str8(ptr, (uint8_t)length, sz);
    return;
  } else if (length <= 65535) {
    minipack_pack_str16(ptr, (uint16_t)length, sz);
    return;
  }
  minipack_pack_str32(ptr, length, sz);
}


x86 assembly (clang, -O0):
<minipack_pack_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x1f,-0xc(%rbp)
jg     1172 <minipack_pack_str+0x32>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <minipack_pack_fixstr@plt>
jmp    11d0 <minipack_pack_str+0x90>
cmpl   $0xff,-0xc(%rbp)
jg     1194 <minipack_pack_str+0x54>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <minipack_pack_str8@plt>
jmp    11d0 <minipack_pack_str+0x90>
cmpl   $0xffff,-0xc(%rbp)
jg     11b6 <minipack_pack_str+0x76>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1060 <minipack_pack_str16@plt>
jmp    11d0 <minipack_pack_str+0x90>
jmp    11bb <minipack_pack_str+0x7b>
jmp    11c0 <minipack_pack_str+0x80>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1050 <minipack_pack_str32@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<minipack_pack_str>:
cmp    $0x1f,%esi
jg     114a <minipack_pack_str+0xa>
jmp    1040 <minipack_pack_fixstr@plt>
cmp    $0xff,%esi
ja     1157 <minipack_pack_str+0x17>
jmp    1030 <minipack_pack_str8@plt>
cmp    $0xffff,%esi
ja     1164 <minipack_pack_str+0x24>
jmp    1060 <minipack_pack_str16@plt>
jmp    1050 <minipack_pack_str32@plt>

LLVM IR (-O0):
define void @minipack_pack_str(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, 31
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_fixstr(i8* %10, i32 %11, i64* %12)
br label %37
14: ; preds = %3
%15 = load i32, i32* %5
%16 = icmp sle i32 %15, 255
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_str8(i8* %18, i32 %19, i64* %20)
br label %37
22: ; preds = %14
%23 = load i32, i32* %5
%24 = icmp sle i32 %23, 65535
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i8*, i8** %4
%27 = load i32, i32* %5
%28 = load i64*, i64** %6
%29 = call i32 @minipack_pack_str16(i8* %26, i32 %27, i64* %28)
br label %37
30: ; preds = %22
br label %31
31: ; preds = %30
br label %32
32: ; preds = %31
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = load i64*, i64** %6
%36 = call i32 @minipack_pack_str32(i8* %33, i32 %34, i64* %35)
br label %37
37: ; preds = %32, %25, %17, %9
ret void
}

LLVM IR (-O2):
define void @minipack_pack_str(i8* %0, i32 %1, i64* %2) {
%4 = icmp slt i32 %1, 32
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @minipack_pack_fixstr(i8* %0, i32 %1, i64* %2)
br label %17
7: ; preds = %3
%8 = icmp ult i32 %1, 256
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @minipack_pack_str8(i8* %0, i32 %1, i64* %2)
br label %17
11: ; preds = %7
%12 = icmp ult i32 %1, 65536
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = tail call i32 @minipack_pack_str16(i8* %0, i32 %1, i64* %2)
br label %17
15: ; preds = %11
%16 = tail call i32 @minipack_pack_str32(i8* %0, i32 %1, i64* %2)
br label %17
17: ; preds = %15, %13, %9, %5
ret void
}