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

/* Variables and functions */
scalar_t__ minipack_is_pos_fixnum(void *);
scalar_t__ minipack_is_uint16(void *);
scalar_t__ minipack_is_uint32(void *);
scalar_t__ minipack_is_uint64(void *);
scalar_t__ minipack_is_uint8(void *);
int /*<<< orphan*/ minipack_unpack_pos_fixnum(void *, size_t *);
int /*<<< orphan*/ minipack_unpack_uint16(void *, size_t *);
int /*<<< orphan*/ minipack_unpack_uint32(void *, size_t *);
int /*<<< orphan*/ minipack_unpack_uint64(void *, size_t *);
int /*<<< orphan*/ minipack_unpack_uint8(void *, size_t *);
uint64_t minipack_unpack_uint(void *ptr, size_t *sz) {
  if (minipack_is_pos_fixnum(ptr)) {
    return (uint64_t)minipack_unpack_pos_fixnum(ptr, sz);
  } else if (minipack_is_uint8(ptr)) {
    return (uint64_t)minipack_unpack_uint8(ptr, sz);
  } else if (minipack_is_uint16(ptr)) {
    return (uint64_t)minipack_unpack_uint16(ptr, sz);
  } else if (minipack_is_uint32(ptr)) {
    return (uint64_t)minipack_unpack_uint32(ptr, sz);
  } else if (minipack_is_uint64(ptr)) {
    return minipack_unpack_uint64(ptr, sz);
  } else {
    *sz = 0;
    return 0;
  }
}


x86 assembly (clang, -O0):
<minipack_unpack_uint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <minipack_is_pos_fixnum@plt>
cmp    $0x0,%rax
je     11d8 <minipack_unpack_uint+0x38>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <minipack_unpack_pos_fixnum@plt>
mov    %eax,-0x4(%rbp)
jmp    128a <minipack_unpack_uint+0xea>
mov    -0x10(%rbp),%rdi
call   1040 <minipack_is_uint8@plt>
cmp    $0x0,%rax
je     1200 <minipack_unpack_uint+0x60>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <minipack_unpack_uint8@plt>
mov    %eax,-0x4(%rbp)
jmp    128a <minipack_unpack_uint+0xea>
mov    -0x10(%rbp),%rdi
call   1080 <minipack_is_uint16@plt>
cmp    $0x0,%rax
je     1228 <minipack_unpack_uint+0x88>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <minipack_unpack_uint16@plt>
mov    %eax,-0x4(%rbp)
jmp    128a <minipack_unpack_uint+0xea>
mov    -0x10(%rbp),%rdi
call   1050 <minipack_is_uint32@plt>
cmp    $0x0,%rax
je     1250 <minipack_unpack_uint+0xb0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10c0 <minipack_unpack_uint32@plt>
mov    %eax,-0x4(%rbp)
jmp    128a <minipack_unpack_uint+0xea>
mov    -0x10(%rbp),%rdi
call   1030 <minipack_is_uint64@plt>
cmp    $0x0,%rax
je     1278 <minipack_unpack_uint+0xd8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <minipack_unpack_uint64@plt>
mov    %eax,-0x4(%rbp)
jmp    128a <minipack_unpack_uint+0xea>
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_uint>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1070 <minipack_is_pos_fixnum@plt>
test   %rax,%rax
je     11c6 <minipack_unpack_uint+0x26>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10b0 <minipack_unpack_pos_fixnum@plt>
mov    %rbx,%rdi
call   1040 <minipack_is_uint8@plt>
test   %rax,%rax
je     11e5 <minipack_unpack_uint+0x45>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <minipack_unpack_uint8@plt>
mov    %rbx,%rdi
call   1080 <minipack_is_uint16@plt>
test   %rax,%rax
je     1204 <minipack_unpack_uint+0x64>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10a0 <minipack_unpack_uint16@plt>
mov    %rbx,%rdi
call   1050 <minipack_is_uint32@plt>
test   %rax,%rax
je     1223 <minipack_unpack_uint+0x83>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10c0 <minipack_unpack_uint32@plt>
mov    %rbx,%rdi
call   1030 <minipack_is_uint64@plt>
test   %rax,%rax
je     1242 <minipack_unpack_uint+0xa2>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <minipack_unpack_uint64@plt>
movq   $0x0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @minipack_unpack_uint(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_pos_fixnum(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_pos_fixnum(i8* %10, i64* %11)
store i32 %12, i32* %3
br label %47
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i64 @minipack_is_uint8(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_uint8(i8* %18, i64* %19)
store i32 %20, i32* %3
br label %47
21: ; preds = %13
%22 = load i8*, i8** %4
%23 = call i64 @minipack_is_uint16(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_uint16(i8* %26, i64* %27)
store i32 %28, i32* %3
br label %47
29: ; preds = %21
%30 = load i8*, i8** %4
%31 = call i64 @minipack_is_uint32(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_uint32(i8* %34, i64* %35)
store i32 %36, i32* %3
br label %47
37: ; preds = %29
%38 = load i8*, i8** %4
%39 = call i64 @minipack_is_uint64(i8* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i8*, i8** %4
%43 = load i64*, i64** %5
%44 = call i32 @minipack_unpack_uint64(i8* %42, i64* %43)
store i32 %44, i32* %3
br label %47
45: ; preds = %37
%46 = load i64*, i64** %5
store i64 0, i64* %46
store i32 0, i32* %3
br label %47
47: ; preds = %45, %41, %33, %25, %17, %9
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
define i32 @minipack_unpack_uint(i8* %0, i64* %1) {
%3 = tail call i64 @minipack_is_pos_fixnum(i8* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @minipack_unpack_pos_fixnum(i8* %0, i64* %1)
br label %28
7: ; preds = %2
%8 = tail call i64 @minipack_is_uint8(i8* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @minipack_unpack_uint8(i8* %0, i64* %1)
br label %28
12: ; preds = %7
%13 = tail call i64 @minipack_is_uint16(i8* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @minipack_unpack_uint16(i8* %0, i64* %1)
br label %28
17: ; preds = %12
%18 = tail call i64 @minipack_is_uint32(i8* %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @minipack_unpack_uint32(i8* %0, i64* %1)
br label %28
22: ; preds = %17
%23 = tail call i64 @minipack_is_uint64(i8* %0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i32 @minipack_unpack_uint64(i8* %0, i64* %1)
br label %28
27: ; preds = %22
store i64 0, i64* %1
br label %28
28: ; preds = %27, %25, %20, %15, %10, %5
%29 = phi i32 [ %6, %5 ], [ %11, %10 ], [ %16, %15 ], [ %21, %20 ], [ %26, %25 ], [ 0, %27 ]
ret i32 %29
}