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

/* Variables and functions */
int get_u16(int const *);
int get_u32(int const *);
char *indent(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void mp4tree_box_subs_print(const uint8_t *p, size_t len, int depth) {
  const int num = get_u32(p + 4);
  const int version = p[0];
  int entry, sub, last_entry = 0;
  printf("%s  Version:     %u\n", indent(depth, 0), version);
  printf("%s  Flags:       0x%.2x%.2x%.2x\n", indent(depth, 0), p[1], p[2],
         p[3]);
  printf("%s  Num Entries: %u\n", indent(depth, 0), num);
  p += 8;
  for (entry = 0; entry < num; entry++) {
    const int delta = get_u32(p);
    const int sub_count = get_u16(p + 4);
    p += 6;
    if (sub_count) {
      last_entry += delta;
      printf("%s      %3u      Size     Prio  Discardable\n", indent(depth, 0),
             last_entry);
    }
    for (sub = 0; sub < sub_count; sub++) {
      printf("%s      %3d:", indent(depth, 0), sub + 1);
      if (version == 1) {
        printf("   %6u", get_u32(p));
        p += 4;
      } else {
        printf("   %6u", get_u16(p));
        p += 2;
      }
      printf("   %6u", p[0]);
      printf("   %6u", p[1]);
      printf("\n");
      p += 6;
    }
  }
}


x86 assembly (clang, -O0):
<mp4tree_box_subs_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    $0x10,%rdi
call   1040 <get_u32@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
mov    -0x1c(%rbp),%edx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%r8d
lea    0xe5a(%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    0xe5d(%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    -0x18(%rbp),%eax
jge    1349 <mp4tree_box_subs_print+0x209>
mov    -0x8(%rbp),%rdi
call   1040 <get_u32@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x10,%rdi
call   1060 <get_u16@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x8(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1258 <mp4tree_box_subs_print+0x118>
mov    -0x2c(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
mov    -0x28(%rbp),%edx
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1336 <mp4tree_box_subs_print+0x1f6>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x1c(%rbp)
jne    12c0 <mp4tree_box_subs_print+0x180>
mov    -0x8(%rbp),%rdi
call   1040 <get_u32@plt>
mov    %eax,%esi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
jmp    12e5 <mp4tree_box_subs_print+0x1a5>
mov    -0x8(%rbp),%rdi
call   1060 <get_u16@plt>
mov    %eax,%esi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x8(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    125f <mp4tree_box_subs_print+0x11f>
jmp    133b <mp4tree_box_subs_print+0x1fb>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11f3 <mp4tree_box_subs_print+0xb3>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp4tree_box_subs_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %rdi,%rbx
add    $0x10,%rdi
call   1050 <get_u32@plt>
mov    %eax,%r15d
mov    (%rbx),%ebp
mov    %r14d,%edi
xor    %esi,%esi
call   1060 <indent@plt>
lea    0xe7d(%rip),%rdi
mov    %rax,%rsi
mov    %ebp,0x14(%rsp)
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%edi
xor    %esi,%esi
call   1060 <indent@plt>
mov    0x4(%rbx),%edx
mov    0x8(%rbx),%ecx
mov    0xc(%rbx),%r8d
lea    0xe67(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,0xc(%rsp)
mov    %r14d,%edi
xor    %esi,%esi
call   1060 <indent@plt>
lea    0xe68(%rip),%rdi
mov    %rax,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %r15d,%r15d
jle    136a <mp4tree_box_subs_print+0x21a>
add    $0x20,%rbx
lea    0xe96(%rip),%r12
xor    %r13d,%r13d
movl   $0x0,0x8(%rsp)
mov    %r15d,0x4(%rsp)
jmp    122a <mp4tree_box_subs_print+0xda>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x4(%rsp),%r15d
mov    0x10(%rsp),%r13d
add    $0x1,%r13d
mov    %rbp,%rbx
cmp    %r15d,%r13d
je     136a <mp4tree_box_subs_print+0x21a>
mov    %rbx,%rdi
call   1050 <get_u32@plt>
mov    %eax,%ebp
lea    0x10(%rbx),%rdi
call   1070 <get_u16@plt>
test   %eax,%eax
je     1350 <mp4tree_box_subs_print+0x200>
mov    %eax,%r14d
mov    0x8(%rsp),%r15d
add    %ebp,%r15d
mov    0xc(%rsp),%edi
xor    %esi,%esi
call   1060 <indent@plt>
lea    0xde9(%rip),%rdi
mov    %rax,%rsi
mov    %r15d,0x8(%rsp)
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x18(%rbx),%rbp
test   %r14d,%r14d
jle    1360 <mp4tree_box_subs_print+0x210>
mov    %r13d,0x10(%rsp)
neg    %r14d
mov    $0x1,%r13d
jmp    1306 <mp4tree_box_subs_print+0x1b6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1070 <get_u16@plt>
mov    %eax,%esi
mov    $0x8,%ebp
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%rbx,%rbp,4),%r15
mov    (%rbx,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rbx,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    (%rbx,%rbp,4),%rbp
add    $0x18,%rbp
lea    (%r14,%r13,1),%eax
add    $0x1,%eax
mov    %r13d,%ecx
add    $0x1,%ecx
mov    %ecx,%r13d
mov    %r15,%rbx
cmp    $0x1,%eax
je     1210 <mp4tree_box_subs_print+0xc0>
mov    0xc(%rsp),%edi
xor    %esi,%esi
call   1060 <indent@plt>
lea    0xd60(%rip),%rdi
mov    %rax,%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x1,0x14(%rsp)
jne    12a0 <mp4tree_box_subs_print+0x150>
mov    %rbp,%rdi
call   1050 <get_u32@plt>
mov    %eax,%esi
mov    $0xa,%ebp
jmp    12af <mp4tree_box_subs_print+0x15f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x18,%rbx
mov    %rbx,%rbp
jmp    121a <mp4tree_box_subs_print+0xca>
nopl   0x0(%rax)
mov    0x4(%rsp),%r15d
jmp    121a <mp4tree_box_subs_print+0xca>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"%s Version: %u\0A\00"
@.str.1 = [33 x i8] c"%s Flags: 0x%.2x%.2x%.2x\0A\00"
@.str.2 = [21 x i8] c"%s Num Entries: %u\0A\00"
@.str.3 = [45 x i8] c"%s %3u Size Prio Discardable\0A\00"
@.str.4 = [13 x i8] c"%s %3d:\00"
@.str.5 = [7 x i8] c" %6u\00"
@.str.6 = [2 x i8] c"\0A\00"
define void @mp4tree_box_subs_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 i32
%13 = alloca i32
store i32* %0, i32** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%14 = load i32*, i32** %4
%15 = getelementptr inbounds i32, i32* %14, i64 4
%16 = call i32 @get_u32(i32* %15)
store i32 %16, i32* %7
%17 = load i32*, i32** %4
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
store i32 %19, i32* %8
store i32 0, i32* %11
%20 = load i32, i32* %6
%21 = call i8* @indent(i32 %20, i32 0)
%22 = load i32, i32* %8
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %21, i32 %22)
%24 = load i32, i32* %6
%25 = call i8* @indent(i32 %24, i32 0)
%26 = load i32*, i32** %4
%27 = getelementptr inbounds i32, i32* %26, i64 1
%28 = load i32, i32* %27
%29 = load i32*, i32** %4
%30 = getelementptr inbounds i32, i32* %29, i64 2
%31 = load i32, i32* %30
%32 = load i32*, i32** %4
%33 = getelementptr inbounds i32, i32* %32, i64 3
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %25, i32 %28, i32 %31, i32 %34)
%36 = load i32, i32* %6
%37 = call i8* @indent(i32 %36, i32 0)
%38 = load i32, i32* %7
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %37, i32 %38)
%40 = load i32*, i32** %4
%41 = getelementptr inbounds i32, i32* %40, i64 8
store i32* %41, i32** %4
store i32 0, i32* %9
br label %42
42: ; preds = %105, %3
%43 = load i32, i32* %9
%44 = load i32, i32* %7
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %108
46: ; preds = %42
%47 = load i32*, i32** %4
%48 = call i32 @get_u32(i32* %47)
store i32 %48, i32* %12
%49 = load i32*, i32** %4
%50 = getelementptr inbounds i32, i32* %49, i64 4
%51 = call i32 @get_u16(i32* %50)
store i32 %51, i32* %13
%52 = load i32*, i32** %4
%53 = getelementptr inbounds i32, i32* %52, i64 6
store i32* %53, i32** %4
%54 = load i32, i32* %13
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %64
56: ; preds = %46
%57 = load i32, i32* %12
%58 = load i32, i32* %11
%59 = add nsw i32 %58, %57
store i32 %59, i32* %11
%60 = load i32, i32* %6
%61 = call i8* @indent(i32 %60, i32 0)
%62 = load i32, i32* %11
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %61, i32 %62)
br label %64
64: ; preds = %56, %46
store i32 0, i32* %10
br label %65
65: ; preds = %101, %64
%66 = load i32, i32* %10
%67 = load i32, i32* %13
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %104
69: ; preds = %65
%70 = load i32, i32* %6
%71 = call i8* @indent(i32 %70, i32 0)
%72 = load i32, i32* %10
%73 = add nsw i32 %72, 1
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %71, i32 %73)
%75 = load i32, i32* %8
%76 = icmp eq i32 %75, 1
br i1 %76, label %77, label %83
77: ; preds = %69
%78 = load i32*, i32** %4
%79 = call i32 @get_u32(i32* %78)
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %79)
%81 = load i32*, i32** %4
%82 = getelementptr inbounds i32, i32* %81, i64 4
store i32* %82, i32** %4
br label %89
83: ; preds = %69
%84 = load i32*, i32** %4
%85 = call i32 @get_u16(i32* %84)
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %85)
%87 = load i32*, i32** %4
%88 = getelementptr inbounds i32, i32* %87, i64 2
store i32* %88, i32** %4
br label %89
89: ; preds = %83, %77
%90 = load i32*, i32** %4
%91 = getelementptr inbounds i32, i32* %90, i64 0
%92 = load i32, i32* %91
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %92)
%94 = load i32*, i32** %4
%95 = getelementptr inbounds i32, i32* %94, i64 1
%96 = load i32, i32* %95
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %96)
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%99 = load i32*, i32** %4
%100 = getelementptr inbounds i32, i32* %99, i64 6
store i32* %100, i32** %4
br label %101
101: ; preds = %89
%102 = load i32, i32* %10
%103 = add nsw i32 %102, 1
store i32 %103, i32* %10
br label %65
104: ; preds = %65
br label %105
105: ; preds = %104
%106 = load i32, i32* %9
%107 = add nsw i32 %106, 1
store i32 %107, i32* %9
br label %42
108: ; preds = %42
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"%s Version: %u\0A\00"
@.str.1 = [33 x i8] c"%s Flags: 0x%.2x%.2x%.2x\0A\00"
@.str.2 = [21 x i8] c"%s Num Entries: %u\0A\00"
@.str.3 = [45 x i8] c"%s %3u Size Prio Discardable\0A\00"
@.str.4 = [13 x i8] c"%s %3d:\00"
@.str.5 = [7 x i8] c" %6u\00"
define void @mp4tree_box_subs_print(i32* %0, i64 %1, i32 %2) {
%4 = getelementptr inbounds i32, i32* %0, i64 4
%5 = tail call i32 @get_u32(i32* %4)
%6 = load i32, i32* %0
%7 = tail call i8* @indent(i32 %2, i32 0)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %6)
%9 = tail call i8* @indent(i32 %2, i32 0)
%10 = getelementptr inbounds i32, i32* %0, i64 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds i32, i32* %0, i64 2
%13 = load i32, i32* %12
%14 = getelementptr inbounds i32, i32* %0, i64 3
%15 = load i32, i32* %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32 %11, i32 %13, i32 %15)
%17 = tail call i8* @indent(i32 %2, i32 0)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %17, i32 %5)
%19 = icmp sgt i32 %5, 0
br i1 %19, label %20, label %68
20: ; preds = %3
%21 = getelementptr inbounds i32, i32* %0, i64 8
%22 = icmp eq i32 %6, 1
br label %23
23: ; preds = %20, %63
%24 = phi i32* [ %21, %20 ], [ %65, %63 ]
%25 = phi i32 [ 0, %20 ], [ %66, %63 ]
%26 = phi i32 [ 0, %20 ], [ %64, %63 ]
%27 = tail call i32 @get_u32(i32* %24)
%28 = getelementptr inbounds i32, i32* %24, i64 4
%29 = tail call i32 @get_u16(i32* %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = getelementptr inbounds i32, i32* %24, i64 6
br label %63
33: ; preds = %23
%34 = add nsw i32 %27, %26
%35 = tail call i8* @indent(i32 %2, i32 0)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %35, i32 %34)
%37 = getelementptr inbounds i32, i32* %24, i64 6
%38 = icmp sgt i32 %29, 0
br i1 %38, label %39, label %63
39: ; preds = %33, %50
%40 = phi i32* [ %61, %50 ], [ %37, %33 ]
%41 = phi i32* [ %54, %50 ], [ %24, %33 ]
%42 = phi i32 [ %44, %50 ], [ 0, %33 ]
%43 = tail call i8* @indent(i32 %2, i32 0)
%44 = add nuw nsw i32 %42, 1
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %43, i32 %44)
br i1 %22, label %46, label %48
46: ; preds = %39
%47 = tail call i32 @get_u32(i32* %40)
br label %50
48: ; preds = %39
%49 = tail call i32 @get_u16(i32* %40)
br label %50
50: ; preds = %48, %46
%51 = phi i32 [ %49, %48 ], [ %47, %46 ]
%52 = phi i64 [ 8, %48 ], [ 10, %46 ]
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %51)
%54 = getelementptr inbounds i32, i32* %41, i64 %52
%55 = load i32, i32* %54
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %55)
%57 = getelementptr inbounds i32, i32* %54, i64 1
%58 = load i32, i32* %57
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %58)
%60 = tail call i32 @putchar(i32 10)
%61 = getelementptr inbounds i32, i32* %54, i64 6
%62 = icmp eq i32 %44, %29
br i1 %62, label %63, label %39
63: ; preds = %50, %31, %33
%64 = phi i32 [ %34, %33 ], [ %26, %31 ], [ %34, %50 ]
%65 = phi i32* [ %37, %33 ], [ %32, %31 ], [ %61, %50 ]
%66 = add nuw nsw i32 %25, 1
%67 = icmp eq i32 %66, %5
br i1 %67, label %68, label %23
68: ; preds = %63, %3
ret void
}