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

/* Variables and functions */
int read_v2gtpHeader(uint8_t *inStream, uint32_t *payloadLength) {
  uint16_t payloadType = 0;
  if (inStream[0] != 0x01 || inStream[1] != 0xFE)
    return -1;
  payloadType = inStream[2];
  payloadType = (payloadType << 8 | inStream[3]);
  if (payloadType != 0x8001)
    return -1;
  *payloadLength = inStream[4];
  *payloadLength = (*payloadLength << 8 | inStream[5]);
  *payloadLength = (*payloadLength << 8 | inStream[6]);
  *payloadLength = (*payloadLength << 8 | inStream[7]);
  return 0;
}


x86 assembly (clang, -O0):
<read_v2gtpHeader>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jne    1131 <read_v2gtpHeader+0x31>
mov    -0x10(%rbp),%rax
cmpl   $0xfe,0x4(%rax)
je     113d <read_v2gtpHeader+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <read_v2gtpHeader+0xc6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x8,%eax
mov    -0x10(%rbp),%rcx
or     0xc(%rcx),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x8001,-0x1c(%rbp)
je     1170 <read_v2gtpHeader+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <read_v2gtpHeader+0xc6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
shl    $0x8,%ecx
mov    -0x10(%rbp),%rax
or     0x14(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
shl    $0x8,%ecx
mov    -0x10(%rbp),%rax
or     0x18(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
shl    $0x8,%ecx
mov    -0x10(%rbp),%rax
or     0x1c(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_v2gtpHeader>:
mov    $0xffffffff,%eax
cmpl   $0x1,(%rdi)
jne    1143 <read_v2gtpHeader+0x43>
cmpl   $0xfe,0x4(%rdi)
jne    1143 <read_v2gtpHeader+0x43>
mov    0x8(%rdi),%ecx
shl    $0x8,%ecx
or     0xc(%rdi),%ecx
cmp    $0x8001,%ecx
jne    1143 <read_v2gtpHeader+0x43>
mov    0x10(%rdi),%eax
mov    %eax,(%rsi)
shl    $0x8,%eax
or     0x14(%rdi),%eax
mov    %eax,(%rsi)
shl    $0x8,%eax
or     0x18(%rdi),%eax
mov    %eax,(%rsi)
shl    $0x8,%eax
or     0x1c(%rdi),%eax
mov    %eax,(%rsi)
xor    %eax,%eax
ret

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

LLVM IR (-O2):
define i32 @read_v2gtpHeader(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = load i32, i32* %0
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %32
5: ; preds = %2
%6 = getelementptr inbounds i32, i32* %0, i64 1
%7 = load i32, i32* %6
%8 = icmp eq i32 %7, 254
br i1 %8, label %9, label %32
9: ; preds = %5
%10 = getelementptr inbounds i32, i32* %0, i64 2
%11 = load i32, i32* %10
%12 = shl i32 %11, 8
%13 = getelementptr inbounds i32, i32* %0, i64 3
%14 = load i32, i32* %13
%15 = or i32 %12, %14
%16 = icmp eq i32 %15, 32769
br i1 %16, label %17, label %32
17: ; preds = %9
%18 = getelementptr inbounds i32, i32* %0, i64 4
%19 = load i32, i32* %18
store i32 %19, i32* %1
%20 = shl i32 %19, 8
%21 = getelementptr inbounds i32, i32* %0, i64 5
%22 = load i32, i32* %21
%23 = or i32 %22, %20
store i32 %23, i32* %1
%24 = shl i32 %23, 8
%25 = getelementptr inbounds i32, i32* %0, i64 6
%26 = load i32, i32* %25
%27 = or i32 %24, %26
store i32 %27, i32* %1
%28 = shl i32 %27, 8
%29 = getelementptr inbounds i32, i32* %0, i64 7
%30 = load i32, i32* %29
%31 = or i32 %28, %30
store i32 %31, i32* %1
br label %32
32: ; preds = %9, %2, %5, %17
%33 = phi i32 [ 0, %17 ], [ -1, %5 ], [ -1, %2 ], [ -1, %9 ]
ret i32 %33
}