#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_sei_h264_nal_print(int /*<<< orphan*/ const *, int,
                                              int);
int /*<<< orphan*/ printf(char *, char *, int);
void mp4tree_box_mdat_h264_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);
    printf("%s--- Length %u Type: H264 NAL\n", indent(depth, 1), nal_length);
    mp4tree_sei_h264_nal_print(p + 4, nal_length, depth + 1);
    p += nal_length + 4;
  }
}


x86 assembly (clang, -O0):
<mp4tree_box_mdat_h264_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    11d2 <mp4tree_box_mdat_h264_print+0x92>
mov    -0x8(%rbp),%rdi
call   1040 <get_u32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1050 <indent@plt>
mov    %rax,%rsi
mov    -0x24(%rbp),%edx
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0x10,%rdi
mov    -0x24(%rbp),%esi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
call   1060 <mp4tree_sei_h264_nal_print@plt>
mov    -0x24(%rbp),%ecx
add    $0x4,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1166 <mp4tree_box_mdat_h264_print+0x26>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mp4tree_box_mdat_h264_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
jle    11b2 <mp4tree_box_mdat_h264_print+0x72>
mov    %edx,%r14d
mov    %rdi,%rbx
lea    (%rdi,%rsi,4),%r13
lea    0x1(%r14),%r12d
lea    0xe9b(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1040 <get_u32@plt>
mov    %eax,%ebp
mov    %r14d,%edi
mov    $0x1,%esi
call   1050 <indent@plt>
mov    %r15,%rdi
mov    %rax,%rsi
mov    %ebp,%edx
call   1030 <printf@plt>
lea    0x10(%rbx),%rdi
mov    %ebp,%esi
mov    %r12d,%edx
call   1060 <mp4tree_sei_h264_nal_print@plt>
movslq %ebp,%rax
lea    (%rbx,%rax,4),%rbx
add    $0x10,%rbx
cmp    %r13,%rbx
jb     1170 <mp4tree_box_mdat_h264_print+0x30>
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: H264 NAL\0A\00"
define void @mp4tree_box_mdat_h264_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* %6
%20 = call i8* @indent(i32 %19, i32 1)
%21 = load i32, i32* %8
%22 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %20, i32 %21)
%23 = load i32*, i32** %4
%24 = getelementptr inbounds i32, i32* %23, i64 4
%25 = load i32, i32* %8
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
%28 = call i32 @mp4tree_sei_h264_nal_print(i32* %24, i32 %25, i32 %27)
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 4
%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: H264 NAL\0A\00"
define void @mp4tree_box_mdat_h264_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 %19
6: ; preds = %3
%7 = add nsw i32 %2, 1
br label %8
8: ; preds = %6, %8
%9 = phi i32* [ %0, %6 ], [ %17, %8 ]
%10 = tail call i32 @get_u32(i32* %9)
%11 = tail call i8* @indent(i32 %2, i32 1)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %10)
%13 = getelementptr inbounds i32, i32* %9, i64 4
%14 = tail call i32 @mp4tree_sei_h264_nal_print(i32* %13, i32 %10, i32 %7)
%15 = add nsw i32 %10, 4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %9, i64 %16
%18 = icmp ult i32* %17, %4
br i1 %18, label %8, label %19
19: ; preds = %8, %3
ret void
}