#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 */

/* Variables and functions */
int /*<<< orphan*/ readH264NALUnit(unsigned char *, int);
void readFLVH264VideoPacket(const unsigned char *h264) {
  int avcpackettype = h264[0];
  int i, length, offset, nSPS;
  unsigned char *avcc;
  if (avcpackettype == 0) {
    avcc = (unsigned char *)&h264[4];
    nSPS = avcc[5] & 0x1f;
    offset = 6;
    for (i = 0; i < nSPS; i++) {
      length = (avcc[offset] << 8) + avcc[offset + 1];
      readH264NALUnit(&avcc[offset + 2], length);
      offset += (2 + length);
    }
  }
  return;
}


x86 assembly (clang, -O0):
<readFLVH264VideoPacket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11bf <readFLVH264VideoPacket+0xaf>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movzbl 0x5(%rax),%eax
and    $0x1f,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x6,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ba <readFLVH264VideoPacket+0xaa>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
shl    $0x8,%eax
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%eax
add    $0x2,%eax
cltq
add    %rax,%rdi
mov    -0x14(%rbp),%esi
call   1030 <readH264NALUnit@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1158 <readFLVH264VideoPacket+0x48>
jmp    11bf <readFLVH264VideoPacket+0xaf>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFLVH264VideoPacket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
jne    1164 <readFLVH264VideoPacket+0x54>
mov    %rdi,%r14
movzbl 0x9(%rdi),%r15d
and    $0x1f,%r15d
je     1164 <readFLVH264VideoPacket+0x54>
add    $0x4,%r14
mov    $0x6,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%eax
movzwl (%r14,%rax,1),%ebx
shl    $0x10,%ebx
bswap  %ebx
lea    0x2(%rbp),%edi
add    %r14,%rdi
mov    %ebx,%esi
call   1030 <readH264NALUnit@plt>
add    %ebx,%ebp
add    $0x2,%ebp
add    $0xffffffff,%r15d
jne    1140 <readFLVH264VideoPacket+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @readFLVH264VideoPacket(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %58
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 4
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = getelementptr inbounds i8, i8* %18, i64 5
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = and i32 %21, 31
store i32 %22, i32* %7
store i32 6, i32* %6
store i32 0, i32* %4
br label %23
23: ; preds = %54, %15
%24 = load i32, i32* %4
%25 = load i32, i32* %7
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %57
27: ; preds = %23
%28 = load i8*, i8** %8
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = shl i32 %33, 8
%35 = load i8*, i8** %8
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = add nsw i32 %34, %41
store i32 %42, i32* %5
%43 = load i8*, i8** %8
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 2
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
%48 = load i32, i32* %5
%49 = call i32 @readH264NALUnit(i8* %47, i32 %48)
%50 = load i32, i32* %5
%51 = add nsw i32 2, %50
%52 = load i32, i32* %6
%53 = add nsw i32 %52, %51
store i32 %53, i32* %6
br label %54
54: ; preds = %27
%55 = load i32, i32* %4
%56 = add nsw i32 %55, 1
store i32 %56, i32* %4
br label %23
57: ; preds = %23
br label %58
58: ; preds = %57, %1
ret void
}

LLVM IR (-O2):
define void @readFLVH264VideoPacket(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %4, label %32
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 4
%6 = getelementptr inbounds i8, i8* %0, i64 9
%7 = load i8, i8* %6
%8 = and i8 %7, 31
%9 = zext i8 %8 to i32
%10 = icmp eq i8 %8, 0
br i1 %10, label %32, label %11
11: ; preds = %4, %11
%12 = phi i32 [ %30, %11 ], [ 0, %4 ]
%13 = phi i32 [ %29, %11 ], [ 6, %4 ]
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %5, i64 %14
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = shl nuw nsw i32 %17, 8
%19 = add nuw nsw i32 %13, 1
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %5, i64 %20
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = or i32 %18, %23
%25 = add i32 %13, 2
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %5, i64 %26
%28 = tail call i32 @readH264NALUnit(i8* %27, i32 %24)
%29 = add i32 %25, %24
%30 = add nuw nsw i32 %12, 1
%31 = icmp eq i32 %30, %9
br i1 %31, label %32, label %11
32: ; preds = %11, %4, %1
ret void
}