#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 size_t uint32_t;

/* Variables and functions */
scalar_t__ minipack_is_bool(void *);
scalar_t__ minipack_is_double(void *);
scalar_t__ minipack_is_float(void *);
scalar_t__ minipack_is_nil(void *);
size_t minipack_sizeof_bool();
size_t minipack_sizeof_double();
size_t minipack_sizeof_float();
size_t minipack_sizeof_int_elem(void *);
size_t minipack_sizeof_nil();
size_t minipack_sizeof_uint_elem(void *);
size_t minipack_unpack_bin(void *, size_t *);
size_t minipack_unpack_str(void *, size_t *);
size_t minipack_sizeof_elem_and_data(void *ptr) {
  size_t sz;
  sz = minipack_sizeof_int_elem(ptr);
  if (sz > 0)
    return sz;
  sz = minipack_sizeof_uint_elem(ptr);
  if (sz > 0)
    return sz;
  if (minipack_is_float(ptr))
    return minipack_sizeof_float();
  if (minipack_is_double(ptr))
    return minipack_sizeof_double();
  if (minipack_is_nil(ptr))
    return minipack_sizeof_nil();
  if (minipack_is_bool(ptr))
    return minipack_sizeof_bool();
  uint32_t length = minipack_unpack_bin(ptr, &sz);
  if (sz > 0)
    return sz + length;
  length = minipack_unpack_str(ptr, &sz);
  if (sz > 0)
    return sz + length;
  return 0;
}


x86 assembly (clang, -O0):
<minipack_sizeof_elem_and_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10e0 <minipack_sizeof_int_elem@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    11f1 <minipack_sizeof_elem_and_data+0x31>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1304 <minipack_sizeof_elem_and_data+0x144>
mov    -0x10(%rbp),%rdi
call   10d0 <minipack_sizeof_uint_elem@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    1216 <minipack_sizeof_elem_and_data+0x56>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1304 <minipack_sizeof_elem_and_data+0x144>
mov    -0x10(%rbp),%rdi
call   10b0 <minipack_is_float@plt>
cmp    $0x0,%rax
je     1239 <minipack_sizeof_elem_and_data+0x79>
mov    $0x0,%al
call   1090 <minipack_sizeof_float@plt>
mov    %rax,-0x8(%rbp)
jmp    1304 <minipack_sizeof_elem_and_data+0x144>
mov    -0x10(%rbp),%rdi
call   1050 <minipack_is_double@plt>
cmp    $0x0,%rax
je     125c <minipack_sizeof_elem_and_data+0x9c>
mov    $0x0,%al
call   1060 <minipack_sizeof_double@plt>
mov    %rax,-0x8(%rbp)
jmp    1304 <minipack_sizeof_elem_and_data+0x144>
mov    -0x10(%rbp),%rdi
call   1070 <minipack_is_nil@plt>
cmp    $0x0,%rax
je     127f <minipack_sizeof_elem_and_data+0xbf>
mov    $0x0,%al
call   1030 <minipack_sizeof_nil@plt>
mov    %rax,-0x8(%rbp)
jmp    1304 <minipack_sizeof_elem_and_data+0x144>
mov    -0x10(%rbp),%rdi
call   10a0 <minipack_is_bool@plt>
cmp    $0x0,%rax
je     12a2 <minipack_sizeof_elem_and_data+0xe2>
mov    $0x0,%al
call   1040 <minipack_sizeof_bool@plt>
mov    %rax,-0x8(%rbp)
jmp    1304 <minipack_sizeof_elem_and_data+0x144>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10c0 <minipack_unpack_bin@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    12cf <minipack_sizeof_elem_and_data+0x10f>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1304 <minipack_sizeof_elem_and_data+0x144>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <minipack_unpack_str@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    12fc <minipack_sizeof_elem_and_data+0x13c>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1304 <minipack_sizeof_elem_and_data+0x144>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<minipack_sizeof_elem_and_data>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   10e0 <minipack_sizeof_int_elem@plt>
test   %rax,%rax
jne    11e4 <minipack_sizeof_elem_and_data+0x24>
mov    %rbx,%rdi
call   10d0 <minipack_sizeof_uint_elem@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     11ea <minipack_sizeof_elem_and_data+0x2a>
add    $0x10,%rsp
pop    %rbx
ret
mov    %rbx,%rdi
call   10b0 <minipack_is_float@plt>
test   %rax,%rax
je     1203 <minipack_sizeof_elem_and_data+0x43>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1090 <minipack_sizeof_float@plt>
mov    %rbx,%rdi
call   1050 <minipack_is_double@plt>
test   %rax,%rax
je     121c <minipack_sizeof_elem_and_data+0x5c>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1060 <minipack_sizeof_double@plt>
mov    %rbx,%rdi
call   1070 <minipack_is_nil@plt>
test   %rax,%rax
je     1235 <minipack_sizeof_elem_and_data+0x75>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1030 <minipack_sizeof_nil@plt>
mov    %rbx,%rdi
call   10a0 <minipack_is_bool@plt>
test   %rax,%rax
je     124e <minipack_sizeof_elem_and_data+0x8e>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1040 <minipack_sizeof_bool@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   10c0 <minipack_unpack_bin@plt>
mov    %rax,%rcx
mov    0x8(%rsp),%rax
test   %rax,%rax
je     1270 <minipack_sizeof_elem_and_data+0xb0>
add    %rcx,%rax
jmp    11e4 <minipack_sizeof_elem_and_data+0x24>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <minipack_unpack_str@plt>
mov    0x8(%rsp),%rcx
add    %rcx,%rax
test   %rcx,%rcx
cmove  %rcx,%rax
jmp    11e4 <minipack_sizeof_elem_and_data+0x24>

LLVM IR (-O0):
define i64 @minipack_sizeof_elem_and_data(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @minipack_sizeof_int_elem(i8* %6)
store i64 %7, i64* %4
%8 = load i64, i64* %4
%9 = icmp ugt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i64, i64* %4
store i64 %11, i64* %2
br label %62
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i64 @minipack_sizeof_uint_elem(i8* %13)
store i64 %14, i64* %4
%15 = load i64, i64* %4
%16 = icmp ugt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = load i64, i64* %4
store i64 %18, i64* %2
br label %62
19: ; preds = %12
%20 = load i8*, i8** %3
%21 = call i64 @minipack_is_float(i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i64 (...) @minipack_sizeof_float()
store i64 %24, i64* %2
br label %62
25: ; preds = %19
%26 = load i8*, i8** %3
%27 = call i64 @minipack_is_double(i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i64 (...) @minipack_sizeof_double()
store i64 %30, i64* %2
br label %62
31: ; preds = %25
%32 = load i8*, i8** %3
%33 = call i64 @minipack_is_nil(i8* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i64 (...) @minipack_sizeof_nil()
store i64 %36, i64* %2
br label %62
37: ; preds = %31
%38 = load i8*, i8** %3
%39 = call i64 @minipack_is_bool(i8* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i64 (...) @minipack_sizeof_bool()
store i64 %42, i64* %2
br label %62
43: ; preds = %37
%44 = load i8*, i8** %3
%45 = call i64 @minipack_unpack_bin(i8* %44, i64* %4)
store i64 %45, i64* %5
%46 = load i64, i64* %4
%47 = icmp ugt i64 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %43
%49 = load i64, i64* %4
%50 = load i64, i64* %5
%51 = add i64 %49, %50
store i64 %51, i64* %2
br label %62
52: ; preds = %43
%53 = load i8*, i8** %3
%54 = call i64 @minipack_unpack_str(i8* %53, i64* %4)
store i64 %54, i64* %5
%55 = load i64, i64* %4
%56 = icmp ugt i64 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %52
%58 = load i64, i64* %4
%59 = load i64, i64* %5
%60 = add i64 %58, %59
store i64 %60, i64* %2
br label %62
61: ; preds = %52
store i64 0, i64* %2
br label %62
62: ; preds = %61, %57, %48, %41, %35, %29, %23, %17, %10
%63 = load i64, i64* %2
ret i64 %63
}

LLVM IR (-O2):
define i64 @minipack_sizeof_elem_and_data(i8* %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = tail call i64 @minipack_sizeof_int_elem(i8* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %41
6: ; preds = %1
%7 = tail call i64 @minipack_sizeof_uint_elem(i8* %0)
store i64 %7, i64* %2
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %41
9: ; preds = %6
%10 = tail call i64 @minipack_is_float(i8* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i64 (...) @minipack_sizeof_float()
br label %41
14: ; preds = %9
%15 = tail call i64 @minipack_is_double(i8* %0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i64 (...) @minipack_sizeof_double()
br label %41
19: ; preds = %14
%20 = tail call i64 @minipack_is_nil(i8* %0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i64 (...) @minipack_sizeof_nil()
br label %41
24: ; preds = %19
%25 = tail call i64 @minipack_is_bool(i8* %0)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = tail call i64 (...) @minipack_sizeof_bool()
br label %41
29: ; preds = %24
%30 = call i64 @minipack_unpack_bin(i8* %0, i64* %2)
%31 = load i64, i64* %2
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %29
%34 = add i64 %31, %30
br label %41
35: ; preds = %29
%36 = call i64 @minipack_unpack_str(i8* %0, i64* %2)
%37 = load i64, i64* %2
%38 = icmp eq i64 %37, 0
%39 = add i64 %37, %36
%40 = select i1 %38, i64 0, i64 %39
br label %41
41: ; preds = %35, %33, %6, %1, %27, %22, %17, %12
%42 = phi i64 [ %13, %12 ], [ %18, %17 ], [ %23, %22 ], [ %28, %27 ], [ %4, %1 ], [ %7, %6 ], [ %34, %33 ], [ %40, %35 ]
ret i64 %42
}