#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_fixmap(void *);
scalar_t__ minipack_is_map16(void *);
scalar_t__ minipack_is_map32(void *);
int /*<<< orphan*/ minipack_unpack_fixmap(void *, size_t *);
int /*<<< orphan*/ minipack_unpack_map16(void *, size_t *);
int /*<<< orphan*/ minipack_unpack_map32(void *, size_t *);
uint32_t minipack_unpack_map(void *ptr, size_t *sz) {
  if (minipack_is_fixmap(ptr)) {
    return (uint32_t)minipack_unpack_fixmap(ptr, sz);
  } else if (minipack_is_map16(ptr)) {
    return (uint32_t)minipack_unpack_map16(ptr, sz);
  } else if (minipack_is_map32(ptr)) {
    return minipack_unpack_map32(ptr, sz);
  } else {
    *sz = 0;
    return 0;
  }
}


x86 assembly (clang, -O0):
<minipack_unpack_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <minipack_is_fixmap@plt>
cmp    $0x0,%rax
je     1198 <minipack_unpack_map+0x38>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <minipack_unpack_fixmap@plt>
mov    %eax,-0x4(%rbp)
jmp    11fa <minipack_unpack_map+0x9a>
mov    -0x10(%rbp),%rdi
call   1030 <minipack_is_map16@plt>
cmp    $0x0,%rax
je     11c0 <minipack_unpack_map+0x60>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <minipack_unpack_map16@plt>
mov    %eax,-0x4(%rbp)
jmp    11fa <minipack_unpack_map+0x9a>
mov    -0x10(%rbp),%rdi
call   1080 <minipack_is_map32@plt>
cmp    $0x0,%rax
je     11e8 <minipack_unpack_map+0x88>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <minipack_unpack_map32@plt>
mov    %eax,-0x4(%rbp)
jmp    11fa <minipack_unpack_map+0x9a>
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_map>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <minipack_is_fixmap@plt>
test   %rax,%rax
je     1186 <minipack_unpack_map+0x26>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <minipack_unpack_fixmap@plt>
mov    %rbx,%rdi
call   1030 <minipack_is_map16@plt>
test   %rax,%rax
je     11a5 <minipack_unpack_map+0x45>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <minipack_unpack_map16@plt>
mov    %rbx,%rdi
call   1080 <minipack_is_map32@plt>
test   %rax,%rax
je     11c4 <minipack_unpack_map+0x64>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <minipack_unpack_map32@plt>
movq   $0x0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @minipack_unpack_map(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_fixmap(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_fixmap(i8* %10, i64* %11)
store i32 %12, i32* %3
br label %31
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i64 @minipack_is_map16(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_map16(i8* %18, i64* %19)
store i32 %20, i32* %3
br label %31
21: ; preds = %13
%22 = load i8*, i8** %4
%23 = call i64 @minipack_is_map32(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_map32(i8* %26, i64* %27)
store i32 %28, i32* %3
br label %31
29: ; preds = %21
%30 = load i64*, i64** %5
store i64 0, i64* %30
store i32 0, i32* %3
br label %31
31: ; preds = %29, %25, %17, %9
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
define i32 @minipack_unpack_map(i8* %0, i64* %1) {
%3 = tail call i64 @minipack_is_fixmap(i8* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @minipack_unpack_fixmap(i8* %0, i64* %1)
br label %18
7: ; preds = %2
%8 = tail call i64 @minipack_is_map16(i8* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @minipack_unpack_map16(i8* %0, i64* %1)
br label %18
12: ; preds = %7
%13 = tail call i64 @minipack_is_map32(i8* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @minipack_unpack_map32(i8* %0, i64* %1)
br label %18
17: ; preds = %12
store i64 0, i64* %1
br label %18
18: ; preds = %17, %15, %10, %5
%19 = phi i32 [ %6, %5 ], [ %11, %10 ], [ %16, %15 ], [ 0, %17 ]
ret i32 %19
}