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

/* Variables and functions */
int get_u24(int const *);
int get_u32(int const *);
char *indent(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
void mp4tree_box_nals_print(const uint8_t *p, size_t len, int depth) {
  uint32_t flags = get_u24(p + 1);
  const uint32_t samples = get_u32(p + 4);
  uint32_t i = 0;
  printf("%s  Version:      %u\n", indent(depth, 0), p[0]);
  printf("%s  Flags:        0x%.6x\n", indent(depth, 0), flags);
  printf("%s  Sample Count: %u\n", indent(depth, 0), samples);
  printf("%s  Samples:\n", indent(depth, 0));
  p += 8;
  for (i = 0; i < samples; i++) {
    uint8_t nal_count = p[0];
    printf("%s    Sample:    %u\n", indent(depth, 0), i + 1);
    printf("%s    NAL Count: %u\n", indent(depth, 0), nal_count);
    printf("%s    NALs:\n", indent(depth, 0));
    p++;
    if (nal_count) {
      uint32_t j;
      printf("%s      Type  Size\n", indent(depth, 0));
      for (j = 0; j < nal_count; j++) {
        printf("%s      %2u %6u\n", indent(depth, 0), p[0], get_u32(p + 1));
        p += 5;
      }
    }
  }
}


x86 assembly (clang, -O0):
<mp4tree_box_nals_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    0xe6c(%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    0xe64(%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    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
lea    0xe5b(%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    1325 <mp4tree_box_nals_print+0x1e5>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
mov    -0x24(%rbp),%edx
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1312 <mp4tree_box_nals_print+0x1d2>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    130d <mp4tree_box_nals_print+0x1cd>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1040 <get_u32@plt>
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x14,%rax
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12ac <mp4tree_box_nals_print+0x16c>
jmp    1312 <mp4tree_box_nals_print+0x1d2>
jmp    1317 <mp4tree_box_nals_print+0x1d7>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1205 <mp4tree_box_nals_print+0xc5>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp4tree_box_nals_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rdi,%rbx
add    $0x4,%rdi
call   1060 <get_u24@plt>
mov    %eax,%r15d
lea    0x10(%rbx),%rdi
call   1040 <get_u32@plt>
mov    %eax,%r12d
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    (%rbx),%edx
lea    0xe86(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <indent@plt>
lea    0xe82(%rip),%rdi
mov    %rax,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <indent@plt>
lea    0xe7f(%rip),%rdi
mov    %rax,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <indent@plt>
lea    0xe78(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
test   %r12d,%r12d
jle    12de <mp4tree_box_nals_print+0x19e>
add    $0x20,%rbx
lea    0xeb3(%rip),%r15
xor    %r14d,%r14d
mov    %r12d,0x4(%rsp)
jmp    120d <mp4tree_box_nals_print+0xcd>
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp),%r14d
cmp    %r12d,%r14d
je     12de <mp4tree_box_nals_print+0x19e>
mov    (%rbx),%r13d
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <indent@plt>
add    $0x1,%r14d
lea    0xe30(%rip),%rdi
mov    %rax,%rsi
mov    %r14d,(%rsp)
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <indent@plt>
lea    0xe24(%rip),%rdi
mov    %rax,%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <indent@plt>
lea    0xe1c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x4,%rbx
test   %r13d,%r13d
je     1200 <mp4tree_box_nals_print+0xc0>
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <indent@plt>
lea    0xe06(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
test   %r13d,%r13d
jle    1200 <mp4tree_box_nals_print+0xc0>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <indent@plt>
mov    %rax,%r14
mov    (%rbx),%r12d
lea    0x4(%rbx),%rdi
call   1040 <get_u32@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x14,%rbx
add    $0xffffffff,%r13d
jne    12a0 <mp4tree_box_nals_print+0x160>
mov    0x4(%rsp),%r12d
jmp    1200 <mp4tree_box_nals_print+0xc0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [22 x i8] c"%s Version: %u\0A\00"
@.str.1 = [26 x i8] c"%s Flags: 0x%.6x\0A\00"
@.str.2 = [22 x i8] c"%s Sample Count: %u\0A\00"
@.str.3 = [14 x i8] c"%s Samples:\0A\00"
@.str.4 = [21 x i8] c"%s Sample: %u\0A\00"
@.str.5 = [21 x i8] c"%s NAL Count: %u\0A\00"
@.str.6 = [13 x i8] c"%s NALs:\0A\00"
@.str.7 = [20 x i8] c"%s Type Size\0A\00"
@.str.8 = [17 x i8] c"%s %2u %6u\0A\00"
define void @mp4tree_box_nals_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 i32 @get_u32(i32* %6)
%8 = tail call i8* @indent(i32 %2, i32 0)
%9 = load i32, i32* %0
%10 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %9)
%11 = tail call i8* @indent(i32 %2, i32 0)
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %5)
%13 = tail call i8* @indent(i32 %2, i32 0)
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %13, i32 %7)
%15 = tail call i8* @indent(i32 %2, i32 0)
%16 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = icmp sgt i32 %7, 0
br i1 %17, label %18, label %51
18: ; preds = %3
%19 = getelementptr inbounds i32, i32* %0, i64 8
br label %20
20: ; preds = %18, %48
%21 = phi i32* [ %49, %48 ], [ %19, %18 ]
%22 = phi i32 [ %25, %48 ], [ 0, %18 ]
%23 = load i32, i32* %21
%24 = tail call i8* @indent(i32 %2, i32 0)
%25 = add nuw nsw i32 %22, 1
%26 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %24, i32 %25)
%27 = tail call i8* @indent(i32 %2, i32 0)
%28 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %27, i32 %23)
%29 = tail call i8* @indent(i32 %2, i32 0)
%30 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds i32, i32* %21, i64 1
%32 = icmp eq i32 %23, 0
br i1 %32, label %48, label %33
33: ; preds = %20
%34 = tail call i8* @indent(i32 %2, i32 0)
%35 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %34)
%36 = icmp sgt i32 %23, 0
br i1 %36, label %37, label %48
37: ; preds = %33, %37
%38 = phi i32 [ %46, %37 ], [ 0, %33 ]
%39 = phi i32* [ %45, %37 ], [ %31, %33 ]
%40 = tail call i8* @indent(i32 %2, i32 0)
%41 = load i32, i32* %39
%42 = getelementptr inbounds i32, i32* %39, i64 1
%43 = tail call i32 @get_u32(i32* %42)
%44 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %40, i32 %41, i32 %43)
%45 = getelementptr inbounds i32, i32* %39, i64 5
%46 = add nuw nsw i32 %38, 1
%47 = icmp eq i32 %46, %23
br i1 %47, label %48, label %37
48: ; preds = %37, %33, %20
%49 = phi i32* [ %31, %20 ], [ %31, %33 ], [ %45, %37 ]
%50 = icmp eq i32 %25, %7
br i1 %50, label %51, label %20
51: ; preds = %48, %3
ret void
}