#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*/ uint32_t;

/* Variables and functions */
scalar_t__ minipack_is_fixstr(void *);
scalar_t__ minipack_is_str16(void *);
scalar_t__ minipack_is_str32(void *);
scalar_t__ minipack_is_str8(void *);
int /*<<< orphan*/ minipack_unpack_fixstr(void *, size_t *);
int /*<<< orphan*/ minipack_unpack_str16(void *, size_t *);
int /*<<< orphan*/ minipack_unpack_str32(void *, size_t *);
int /*<<< orphan*/ minipack_unpack_str8(void *, size_t *);
uint32_t minipack_unpack_str(void *ptr, size_t *sz) {
  if (minipack_is_fixstr(ptr)) {
    return (uint32_t)minipack_unpack_fixstr(ptr, sz);
  } else if (minipack_is_str8(ptr)) {
    return (uint32_t)minipack_unpack_str8(ptr, sz);
  } else if (minipack_is_str16(ptr)) {
    return (uint32_t)minipack_unpack_str16(ptr, sz);
  } else if (minipack_is_str32(ptr)) {
    return minipack_unpack_str32(ptr, sz);
  } else {
    *sz = 0;
    return 0;
  }
}


x86 assembly (clang, -O0):
<minipack_unpack_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <minipack_is_fixstr@plt>
cmp    $0x0,%rax
je     11b8 <minipack_unpack_str+0x38>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <minipack_unpack_fixstr@plt>
mov    %eax,-0x4(%rbp)
jmp    1242 <minipack_unpack_str+0xc2>
mov    -0x10(%rbp),%rdi
call   10a0 <minipack_is_str8@plt>
cmp    $0x0,%rax
je     11e0 <minipack_unpack_str+0x60>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <minipack_unpack_str8@plt>
mov    %eax,-0x4(%rbp)
jmp    1242 <minipack_unpack_str+0xc2>
mov    -0x10(%rbp),%rdi
call   1040 <minipack_is_str16@plt>
cmp    $0x0,%rax
je     1208 <minipack_unpack_str+0x88>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <minipack_unpack_str16@plt>
mov    %eax,-0x4(%rbp)
jmp    1242 <minipack_unpack_str+0xc2>
mov    -0x10(%rbp),%rdi
call   1070 <minipack_is_str32@plt>
cmp    $0x0,%rax
je     1230 <minipack_unpack_str+0xb0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <minipack_unpack_str32@plt>
mov    %eax,-0x4(%rbp)
jmp    1242 <minipack_unpack_str+0xc2>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<minipack_unpack_str>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <minipack_is_fixstr@plt>
test   %rax,%rax
je     11a6 <minipack_unpack_str+0x26>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <minipack_unpack_fixstr@plt>
mov    %rbx,%rdi
call   10a0 <minipack_is_str8@plt>
test   %rax,%rax
je     11c5 <minipack_unpack_str+0x45>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <minipack_unpack_str8@plt>
mov    %rbx,%rdi
call   1040 <minipack_is_str16@plt>
test   %rax,%rax
je     11e4 <minipack_unpack_str+0x64>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <minipack_unpack_str16@plt>
mov    %rbx,%rdi
call   1070 <minipack_is_str32@plt>
test   %rax,%rax
je     1203 <minipack_unpack_str+0x83>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <minipack_unpack_str32@plt>
movq   $0x0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @minipack_unpack_str(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
store i8* %0, i8** %4
store i64* %1, i64** %5
%6 = load i8*, i8** %4
%7 = call i64 @minipack_is_fixstr(i8* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = load i64*, i64** %5
%12 = call i32 @minipack_unpack_fixstr(i8* %10, i64* %11)
store i32 %12, i32* %3
br label %39
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i64 @minipack_is_str8(i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = load i64*, i64** %5
%20 = call i32 @minipack_unpack_str8(i8* %18, i64* %19)
store i32 %20, i32* %3
br label %39
21: ; preds = %13
%22 = load i8*, i8** %4
%23 = call i64 @minipack_is_str16(i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = load i64*, i64** %5
%28 = call i32 @minipack_unpack_str16(i8* %26, i64* %27)
store i32 %28, i32* %3
br label %39
29: ; preds = %21
%30 = load i8*, i8** %4
%31 = call i64 @minipack_is_str32(i8* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i8*, i8** %4
%35 = load i64*, i64** %5
%36 = call i32 @minipack_unpack_str32(i8* %34, i64* %35)
store i32 %36, i32* %3
br label %39
37: ; preds = %29
%38 = load i64*, i64** %5
store i64 0, i64* %38
store i32 0, i32* %3
br label %39
39: ; preds = %37, %33, %25, %17, %9
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
define i32 @minipack_unpack_str(i8* %0, i64* %1) {
%3 = tail call i64 @minipack_is_fixstr(i8* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @minipack_unpack_fixstr(i8* %0, i64* %1)
br label %23
7: ; preds = %2
%8 = tail call i64 @minipack_is_str8(i8* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @minipack_unpack_str8(i8* %0, i64* %1)
br label %23
12: ; preds = %7
%13 = tail call i64 @minipack_is_str16(i8* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @minipack_unpack_str16(i8* %0, i64* %1)
br label %23
17: ; preds = %12
%18 = tail call i64 @minipack_is_str32(i8* %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @minipack_unpack_str32(i8* %0, i64* %1)
br label %23
22: ; preds = %17
store i64 0, i64* %1
br label %23
23: ; preds = %22, %20, %15, %10, %5
%24 = phi i32 [ %6, %5 ], [ %11, %10 ], [ %16, %15 ], [ %21, %20 ], [ 0, %22 ]
ret i32 %24
}