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

/* Variables and functions */
scalar_t__ *h265hvcc_array_get_nalu(scalar_t__ const *, int /*<<< orphan*/);
int /*<<< orphan*/ h265hvcc_array_get_num_nalus(scalar_t__ const *);
uint8_t *h265hvcc_get_array(const uint8_t *p, uint8_t n) {
  p += 23;
  while (n) {
    uint16_t num_nalus = h265hvcc_array_get_num_nalus(p);
    p = h265hvcc_array_get_nalu(p, num_nalus);
    n--;
  }
  return (uint8_t *)p;
}


x86 assembly (clang, -O0):
<h265hvcc_get_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0xb8,%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1176 <h265hvcc_get_array+0x56>
mov    -0x8(%rbp),%rdi
call   1040 <h265hvcc_array_get_num_nalus@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <h265hvcc_array_get_nalu@plt>
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    113e <h265hvcc_get_array+0x1e>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<h265hvcc_get_array>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
add    $0xb8,%r14
test   %rsi,%rsi
je     115b <h265hvcc_get_array+0x3b>
mov    %rsi,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <h265hvcc_array_get_num_nalus@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <h265hvcc_array_get_nalu@plt>
mov    %rax,%r14
add    $0xffffffffffffffff,%rbx
jne    1140 <h265hvcc_get_array+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64* @h265hvcc_get_array(i64* %0, i64 %1) {
%3 = alloca i64*
%4 = alloca i64
%5 = alloca i32
store i64* %0, i64** %3
store i64 %1, i64* %4
%6 = load i64*, i64** %3
%7 = getelementptr inbounds i64, i64* %6, i64 23
store i64* %7, i64** %3
br label %8
8: ; preds = %11, %2
%9 = load i64, i64* %4
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i64*, i64** %3
%13 = call i32 @h265hvcc_array_get_num_nalus(i64* %12)
store i32 %13, i32* %5
%14 = load i64*, i64** %3
%15 = load i32, i32* %5
%16 = call i64* @h265hvcc_array_get_nalu(i64* %14, i32 %15)
store i64* %16, i64** %3
%17 = load i64, i64* %4
%18 = add nsw i64 %17, -1
store i64 %18, i64* %4
br label %8
19: ; preds = %8
%20 = load i64*, i64** %3
ret i64* %20
}

LLVM IR (-O2):
define i64* @h265hvcc_get_array(i64* %0, i64 %1) {
%3 = getelementptr inbounds i64, i64* %0, i64 23
%4 = icmp eq i64 %1, 0
br i1 %4, label %12, label %5
5: ; preds = %2, %5
%6 = phi i64* [ %9, %5 ], [ %3, %2 ]
%7 = phi i64 [ %10, %5 ], [ %1, %2 ]
%8 = tail call i32 @h265hvcc_array_get_num_nalus(i64* %6)
%9 = tail call i64* @h265hvcc_array_get_nalu(i64* %6, i32 %8)
%10 = add nsw i64 %7, -1
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %5
12: ; preds = %5, %2
%13 = phi i64* [ %3, %2 ], [ %9, %5 ]
ret i64* %13
}