#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 uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ typeMap;

/* Variables and functions */
int get_u24(int const *);
void *get_u32(int const *);
char *indent(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
void mp4tree_box_size_print(const uint8_t *p, size_t len, int depth) {
  uint32_t flags = get_u24(p + 1);
  const uint32_t entries = get_u32(p + 4);
  uint32_t i = 0;
  static const char *typeMap[] = {"HLS-TS",
                                  "HLS-TS-AES-128",
                                  "HLS-TS-SAMPLE-AES",
                                  "HLS-PACKED-AUDIO",
                                  "HLS-PACKED-AUDIO-AES-128",
                                  "DASH",
                                  "MSS",
                                  "MDAT"};
  printf("%s  Version: %u\n", indent(depth, 0), p[0]);
  printf("%s  Flags:   0x%.6x\n", indent(depth, 0), flags);
  printf("%s  Entries: %u\n", indent(depth, 0), entries);
  printf("%s  Sizes:   \n", indent(depth, 0));
  p += 8;
  for (i = 0; i < entries; i++) {
    uint8_t type = p[0];
    uint32_t size = get_u32(p + 1);
    const char *type_str = "Unknown";
    if (type < sizeof(typeMap) / sizeof(typeMap[0]))
      type_str = typeMap[type];
    printf("%s    %s (%u): %u\n", indent(depth, 0), type_str, type, size);
    p += 5;
  }
}


x86 assembly (clang, -O0):
<mp4tree_box_size_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1060 <get_u24@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x10,%rdi
call   1040 <get_u32@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
mov    -0x18(%rbp),%edx
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
mov    -0x1c(%rbp),%edx
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1296 <mp4tree_box_size_print+0x156>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1040 <get_u32@plt>
mov    %eax,-0x28(%rbp)
lea    0xe75(%rip),%rax
mov    %rax,-0x30(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x8,%rax
jae    1256 <mp4tree_box_size_print+0x116>
movslq -0x24(%rbp),%rcx
lea    0x2e02(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
mov    -0x30(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x14,%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1205 <mp4tree_box_size_print+0xc5>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp4tree_box_size_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rdi,%rbx
add    $0x4,%rdi
call   1060 <get_u24@plt>
mov    %eax,%r15d
lea    0x10(%rbx),%rdi
call   1040 <get_u32@plt>
mov    %rax,%r12
mov    %r14d,%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    (%rbx),%edx
lea    0xf04(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14d,%edi
xor    %esi,%esi
call   1050 <indent@plt>
lea    0xefa(%rip),%rdi
mov    %rax,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14d,%edi
xor    %esi,%esi
call   1050 <indent@plt>
lea    0xef1(%rip),%rdi
mov    %rax,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14d,%edi
xor    %esi,%esi
call   1050 <indent@plt>
lea    0xee4(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
test   %r12d,%r12d
jle    124b <mp4tree_box_size_print+0x10b>
add    $0x20,%rbx
jmp    121d <mp4tree_box_size_print+0xdd>
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
xor    %esi,%esi
call   1050 <indent@plt>
lea    0xecd(%rip),%rdi
mov    %rax,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
mov    %r13d,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x10,%rbx
add    $0xffffffff,%r12d
je     124b <mp4tree_box_size_print+0x10b>
mov    (%rbx),%ebp
add    $0x4,%rbx
mov    %rbx,%rdi
call   1040 <get_u32@plt>
mov    %rax,%r13
lea    0xe91(%rip),%r15
cmp    $0x7,%rbp
ja     11f0 <mp4tree_box_size_print+0xb0>
lea    0xdbe(%rip),%rax
movslq (%rax,%rbp,4),%r15
add    %rax,%r15
jmp    11f0 <mp4tree_box_size_print+0xb0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@mp4tree_box_size_print.typeMap = internal global [8 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0)]
@.str = [7 x i8] c"HLS-TS\00"
@.str.1 = [15 x i8] c"HLS-TS-AES-128\00"
@.str.2 = [18 x i8] c"HLS-TS-SAMPLE-AES\00"
@.str.3 = [17 x i8] c"HLS-PACKED-AUDIO\00"
@.str.4 = [25 x i8] c"HLS-PACKED-AUDIO-AES-128\00"
@.str.5 = [5 x i8] c"DASH\00"
@.str.6 = [4 x i8] c"MSS\00"
@.str.7 = [5 x i8] c"MDAT\00"
@.str.8 = [17 x i8] c"%s Version: %u\0A\00"
@.str.9 = [21 x i8] c"%s Flags: 0x%.6x\0A\00"
@.str.10 = [17 x i8] c"%s Entries: %u\0A\00"
@.str.11 = [15 x i8] c"%s Sizes: \0A\00"
@.str.12 = [8 x i8] c"Unknown\00"
@.str.13 = [19 x i8] c"%s %s (%u): %u\0A\00"
define void @mp4tree_box_size_print(i32* %0, i64 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i32* %0, i32** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%13 = load i32*, i32** %4
%14 = getelementptr inbounds i32, i32* %13, i64 1
%15 = call i32 @get_u24(i32* %14)
store i32 %15, i32* %7
%16 = load i32*, i32** %4
%17 = getelementptr inbounds i32, i32* %16, i64 4
%18 = call i8* @get_u32(i32* %17)
%19 = ptrtoint i8* %18 to i32
store i32 %19, i32* %8
store i32 0, i32* %9
%20 = load i32, i32* %6
%21 = call i8* @indent(i32 %20, i32 0)
%22 = load i32*, i32** %4
%23 = getelementptr inbounds i32, i32* %22, i64 0
%24 = load i32, i32* %23
%25 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %21, i32 %24)
%26 = load i32, i32* %6
%27 = call i8* @indent(i32 %26, i32 0)
%28 = load i32, i32* %7
%29 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i8* %27, i32 %28)
%30 = load i32, i32* %6
%31 = call i8* @indent(i32 %30, i32 0)
%32 = load i32, i32* %8
%33 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i8* %31, i32 %32)
%34 = load i32, i32* %6
%35 = call i8* @indent(i32 %34, i32 0)
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8* %35)
%37 = load i32*, i32** %4
%38 = getelementptr inbounds i32, i32* %37, i64 8
store i32* %38, i32** %4
store i32 0, i32* %9
br label %39
39: ; preds = %68, %3
%40 = load i32, i32* %9
%41 = load i32, i32* %8
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %71
43: ; preds = %39
%44 = load i32*, i32** %4
%45 = getelementptr inbounds i32, i32* %44, i64 0
%46 = load i32, i32* %45
store i32 %46, i32* %10
%47 = load i32*, i32** %4
%48 = getelementptr inbounds i32, i32* %47, i64 1
%49 = call i8* @get_u32(i32* %48)
%50 = ptrtoint i8* %49 to i32
store i32 %50, i32* %11
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), i8** %12
%51 = load i32, i32* %10
%52 = sext i32 %51 to i64
%53 = icmp ult i64 %52, 8
br i1 %53, label %54, label %59
54: ; preds = %43
%55 = load i32, i32* %10
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [8 x i8*], [8 x i8*]* @mp4tree_box_size_print.typeMap, i64 0, i64 %56
%58 = load i8*, i8** %57
store i8* %58, i8** %12
br label %59
59: ; preds = %54, %43
%60 = load i32, i32* %6
%61 = call i8* @indent(i32 %60, i32 0)
%62 = load i8*, i8** %12
%63 = load i32, i32* %10
%64 = load i32, i32* %11
%65 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0), i8* %61, i8* %62, i32 %63, i32 %64)
%66 = load i32*, i32** %4
%67 = getelementptr inbounds i32, i32* %66, i64 5
store i32* %67, i32** %4
br label %68
68: ; preds = %59
%69 = load i32, i32* %9
%70 = add nsw i32 %69, 1
store i32 %70, i32* %9
br label %39
71: ; preds = %39
ret void
}

LLVM IR (-O2):
@reltable.mp4tree_box_size_print = internal unnamed_addr constant [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str to i64), i64 ptrtoint ([8 x i32]* @reltable.mp4tree_box_size_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.mp4tree_box_size_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.2 to i64), i64 ptrtoint ([8 x i32]* @reltable.mp4tree_box_size_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.mp4tree_box_size_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([25 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.mp4tree_box_size_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.mp4tree_box_size_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.6 to i64), i64 ptrtoint ([8 x i32]* @reltable.mp4tree_box_size_print to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.7 to i64), i64 ptrtoint ([8 x i32]* @reltable.mp4tree_box_size_print to i64)) to i32)]
@.str = [7 x i8] c"HLS-TS\00"
@.str.1 = [15 x i8] c"HLS-TS-AES-128\00"
@.str.2 = [18 x i8] c"HLS-TS-SAMPLE-AES\00"
@.str.3 = [17 x i8] c"HLS-PACKED-AUDIO\00"
@.str.4 = [25 x i8] c"HLS-PACKED-AUDIO-AES-128\00"
@.str.5 = [5 x i8] c"DASH\00"
@.str.6 = [4 x i8] c"MSS\00"
@.str.7 = [5 x i8] c"MDAT\00"
@.str.8 = [17 x i8] c"%s Version: %u\0A\00"
@.str.9 = [21 x i8] c"%s Flags: 0x%.6x\0A\00"
@.str.10 = [17 x i8] c"%s Entries: %u\0A\00"
@.str.11 = [15 x i8] c"%s Sizes: \0A\00"
@.str.12 = [8 x i8] c"Unknown\00"
@.str.13 = [19 x i8] c"%s %s (%u): %u\0A\00"
define void @mp4tree_box_size_print(i32* %0, i64 %1, i32 %2) {
%4 = getelementptr inbounds i32, i32* %0, i64 1
%5 = tail call i32 @get_u24(i32* %4)
%6 = getelementptr inbounds i32, i32* %0, i64 4
%7 = tail call i8* @get_u32(i32* %6)
%8 = ptrtoint i8* %7 to i64
%9 = trunc i64 %8 to i32
%10 = tail call i8* @indent(i32 %2, i32 0)
%11 = load i32, i32* %0
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %10, i32 %11)
%13 = tail call i8* @indent(i32 %2, i32 0)
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i8* %13, i32 %5)
%15 = tail call i8* @indent(i32 %2, i32 0)
%16 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i64 0, i64 0), i8* %15, i32 %9)
%17 = tail call i8* @indent(i32 %2, i32 0)
%18 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8* %17)
%19 = icmp sgt i32 %9, 0
br i1 %19, label %20, label %42
20: ; preds = %3
%21 = getelementptr inbounds i32, i32* %0, i64 8
br label %22
22: ; preds = %20, %35
%23 = phi i32* [ %39, %35 ], [ %21, %20 ]
%24 = phi i32 [ %40, %35 ], [ 0, %20 ]
%25 = load i32, i32* %23
%26 = getelementptr inbounds i32, i32* %23, i64 1
%27 = tail call i8* @get_u32(i32* %26)
%28 = ptrtoint i8* %27 to i64
%29 = trunc i64 %28 to i32
%30 = icmp ult i32 %25, 8
br i1 %30, label %31, label %35
31: ; preds = %22
%32 = zext i32 %25 to i64
%33 = shl i64 %32, 2
%34 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.mp4tree_box_size_print to i8*), i64 %33)
br label %35
35: ; preds = %31, %22
%36 = phi i8* [ %34, %31 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0), %22 ]
%37 = tail call i8* @indent(i32 %2, i32 0)
%38 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0), i8* %37, i8* %36, i32 %25, i32 %29)
%39 = getelementptr inbounds i32, i32* %23, i64 5
%40 = add nuw nsw i32 %24, 1
%41 = icmp eq i32 %40, %9
br i1 %41, label %42, label %22
42: ; preds = %35, %3
ret void
}