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

/* Variables and functions */
int get_u32(int /*<<< orphan*/ const *);
char *indent(int, int);
int /*<<< orphan*/ mp4tree_box_mdat_hevc_nal_print(int /*<<< orphan*/ const *,
                                                   int, int);
int /*<<< orphan*/ printf(char *, char *, int);
void mp4tree_box_mdat_hevc_print(const uint8_t *p, size_t len, int depth) {
  const uint8_t *p_end = p + len;
  while (p < p_end) {
    uint32_t nal_length = get_u32(p);
    p += 4;
    printf("%s--- Length %u Type: HEVC NAL\n", indent(depth, 1), nal_length);
    mp4tree_box_mdat_hevc_nal_print(p, nal_length, depth + 1);
    p += nal_length;
  }
}


x86 assembly (clang, -O0):
<mp4tree_box_mdat_hevc_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11d7 <mp4tree_box_mdat_hevc_print+0x97>
mov    -0x8(%rbp),%rdi
call   1050 <get_u32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1060 <indent@plt>
mov    %rax,%rsi
mov    -0x24(%rbp),%edx
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
call   1030 <mp4tree_box_mdat_hevc_nal_print@plt>
mov    -0x24(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1166 <mp4tree_box_mdat_hevc_print+0x26>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp4tree_box_mdat_hevc_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
jle    11a9 <mp4tree_box_mdat_hevc_print+0x69>
mov    %edx,%r14d
mov    %rdi,%rbx
lea    (%rdi,%rsi,4),%r15
lea    0x1(%r14),%r12d
xchg   %ax,%ax
mov    %rbx,%rdi
call   1050 <get_u32@plt>
mov    %eax,%ebp
lea    0x10(%rbx),%r13
mov    %r14d,%edi
mov    $0x1,%esi
call   1060 <indent@plt>
lea    0xe7e(%rip),%rdi
mov    %rax,%rsi
mov    %ebp,%edx
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
call   1030 <mp4tree_box_mdat_hevc_nal_print@plt>
movslq %ebp,%rax
lea    (%rbx,%rax,4),%rbx
add    $0x10,%rbx
cmp    %r15,%rbx
jb     1160 <mp4tree_box_mdat_hevc_print+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"%s--- Length %u Type: HEVC NAL\0A\00"
define void @mp4tree_box_mdat_hevc_print(i32* %0, i64 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%9 = load i32*, i32** %4
%10 = load i64, i64* %5
%11 = getelementptr inbounds i32, i32* %9, i64 %10
store i32* %11, i32** %7
br label %12
12: ; preds = %16, %3
%13 = load i32*, i32** %4
%14 = load i32*, i32** %7
%15 = icmp ult i32* %13, %14
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = load i32*, i32** %4
%18 = call i32 @get_u32(i32* %17)
store i32 %18, i32* %8
%19 = load i32*, i32** %4
%20 = getelementptr inbounds i32, i32* %19, i64 4
store i32* %20, i32** %4
%21 = load i32, i32* %6
%22 = call i8* @indent(i32 %21, i32 1)
%23 = load i32, i32* %8
%24 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %22, i32 %23)
%25 = load i32*, i32** %4
%26 = load i32, i32* %8
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
%29 = call i32 @mp4tree_box_mdat_hevc_nal_print(i32* %25, i32 %26, i32 %28)
%30 = load i32, i32* %8
%31 = load i32*, i32** %4
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i32, i32* %31, i64 %32
store i32* %33, i32** %4
br label %12
34: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"%s--- Length %u Type: HEVC NAL\0A\00"
define void @mp4tree_box_mdat_hevc_print(i32* %0, i64 %1, i32 %2) {
%4 = getelementptr inbounds i32, i32* %0, i64 %1
%5 = icmp sgt i64 %1, 0
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = add nsw i32 %2, 1
br label %8
8: ; preds = %6, %8
%9 = phi i32* [ %0, %6 ], [ %16, %8 ]
%10 = tail call i32 @get_u32(i32* %9)
%11 = getelementptr inbounds i32, i32* %9, i64 4
%12 = tail call i8* @indent(i32 %2, i32 1)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %10)
%14 = tail call i32 @mp4tree_box_mdat_hevc_nal_print(i32* %11, i32 %10, i32 %7)
%15 = sext i32 %10 to i64
%16 = getelementptr inbounds i32, i32* %11, i64 %15
%17 = icmp ult i32* %16, %4
br i1 %17, label %8, label %18
18: ; preds = %8, %3
ret void
}