#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 /*<<< orphan*/ uint32_t;

/* Variables and functions */
int ntohl(int /*<<< orphan*/);
int /*<<< orphan*/ validate_cookie(int /*<<< orphan*/ *);
void parse_dp_header(uint8_t *buf, uint8_t *addr_type, int *packet_len) {
  if (!validate_cookie(buf)) {
    *packet_len = -1;
    return;
  }
  if (addr_type)
    *addr_type = buf[8];
  *packet_len = ntohl(*(uint32_t *)(buf + 8 + 1));
}


x86 assembly (clang, -O0):
<parse_dp_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <validate_cookie@plt>
cmp    $0x0,%eax
jne    1155 <parse_dp_header+0x35>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
jmp    1181 <parse_dp_header+0x61>
cmpq   $0x0,-0x10(%rbp)
je     116d <parse_dp_header+0x4d>
mov    -0x8(%rbp),%rax
mov    0x20(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x24(%rax),%edi
call   1040 <ntohl@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_dp_header>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <validate_cookie@plt>
test   %eax,%eax
je     114c <parse_dp_header+0x2c>
test   %r15,%r15
je     1142 <parse_dp_header+0x22>
mov    0x20(%rbx),%eax
mov    %eax,(%r15)
mov    0x24(%rbx),%edi
call   1040 <ntohl@plt>
jmp    1151 <parse_dp_header+0x31>
mov    $0xffffffff,%eax
mov    %eax,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @parse_dp_header(i32* %0, i32* writeonly %1, i32* nocapture writeonly %2) {
%4 = tail call i32 @validate_cookie(i32* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %3
%7 = icmp eq i32* %1, null
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = getelementptr inbounds i32, i32* %0, i64 8
%10 = load i32, i32* %9
store i32 %10, i32* %1
br label %11
11: ; preds = %8, %6
%12 = getelementptr inbounds i32, i32* %0, i64 9
%13 = load i32, i32* %12
%14 = tail call i32 @ntohl(i32 %13)
br label %15
15: ; preds = %3, %11
%16 = phi i32 [ %14, %11 ], [ -1, %3 ]
store i32 %16, i32* %2
ret void
}