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

/* Variables and functions */
int /*<<< orphan*/ h264avcc_get_nb_sps(scalar_t__ const *);
scalar_t__ *h264avcc_get_spsh(scalar_t__ const *, int /*<<< orphan*/);
scalar_t__ h264avcc_ppsh_get_length(scalar_t__ const *);
uint8_t *h264avcc_get_ppsh(const uint8_t *p, uint8_t n) {
  p = h264avcc_get_spsh(p, h264avcc_get_nb_sps(p));
  p += 1;
  while (n) {
    uint16_t length = h264avcc_ppsh_get_length(p);
    p += 2 + length;
    n--;
  }
  return (uint8_t *)p;
}


x86 assembly (clang, -O0):
<h264avcc_get_ppsh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <h264avcc_get_nb_sps@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1030 <h264avcc_get_spsh@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a9 <h264avcc_get_ppsh+0x79>
mov    -0x8(%rbp),%rdi
call   1040 <h264avcc_ppsh_get_length@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x2,%rax
shl    $0x3,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    116c <h264avcc_get_ppsh+0x3c>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<h264avcc_get_ppsh>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <h264avcc_get_nb_sps@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <h264avcc_get_spsh@plt>
mov    %rax,%rbx
add    $0x8,%rbx
test   %r14,%r14
je     1176 <h264avcc_get_ppsh+0x46>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1040 <h264avcc_ppsh_get_length@plt>
lea    (%rbx,%rax,8),%rbx
add    $0x10,%rbx
add    $0xffffffffffffffff,%r14
jne    1160 <h264avcc_get_ppsh+0x30>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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