#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 */
struct tcphdr {
  int dummy;
};
struct ip {
  scalar_t__ ip_p;
  int ip_hl;
};
struct ether_header {
  int /*<<< orphan*/ ether_type;
};

/* Variables and functions */
scalar_t__ ETHERTYPE_IP;
scalar_t__ IPPROTO_TCP;
scalar_t__ ntohs(int /*<<< orphan*/);
void breakupPacket(void *buf, struct ether_header **e, struct ip **i,
                   struct tcphdr **t) {
  int ip_hl;
  *e = (struct ether_header *)buf;
  *i = NULL;
  *t = NULL;
  if (ETHERTYPE_IP != ntohs((*e)->ether_type))
    return;
  *i = (struct ip *)(*e + 1);
  if (IPPROTO_TCP != (*i)->ip_p)
    return;
  ip_hl = (*i)->ip_hl << 2;
  *t = (struct tcphdr *)((char *)*i + ip_hl);
}


x86 assembly (clang, -O0):
<breakupPacket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    0x2e98(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <ntohs@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
je     117a <breakupPacket+0x6a>
jmp    11d0 <breakupPacket+0xc0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x4,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2e4d(%rip),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rcx
cmp    (%rcx),%rax
je     11ab <breakupPacket+0x9b>
jmp    11d0 <breakupPacket+0xc0>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x8(%rax),%eax
shl    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
movslq -0x24(%rbp),%rax
add    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<breakupPacket>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,(%rsi)
movq   $0x0,(%rdx)
movq   $0x0,(%rcx)
mov    0x2eaf(%rip),%rax
mov    (%rax),%r12
mov    (%rsi),%rax
mov    (%rax),%edi
call   1030 <ntohs@plt>
cmp    %rax,%r12
jne    1174 <breakupPacket+0x64>
mov    (%rbx),%rcx
lea    0x4(%rcx),%rax
mov    %rax,(%r15)
mov    0x2e84(%rip),%rdx
mov    (%rdx),%rdx
cmp    0x4(%rcx),%rdx
jne    1174 <breakupPacket+0x64>
mov    0xc(%rcx),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ether_header = type { i32 }
%struct.ip = type { i64, i32 }
%struct.tcphdr = type { i32 }
@ETHERTYPE_IP = global i64 0
@IPPROTO_TCP = global i64 0
define void @breakupPacket(i8* %0, %struct.ether_header** %1, %struct.ip** %2, %struct.tcphdr** %3) {
%5 = alloca i8*
%6 = alloca %struct.ether_header**
%7 = alloca %struct.ip**
%8 = alloca %struct.tcphdr**
%9 = alloca i32
store i8* %0, i8** %5
store %struct.ether_header** %1, %struct.ether_header*** %6
store %struct.ip** %2, %struct.ip*** %7
store %struct.tcphdr** %3, %struct.tcphdr*** %8
%10 = load i8*, i8** %5
%11 = bitcast i8* %10 to %struct.ether_header*
%12 = load %struct.ether_header**, %struct.ether_header*** %6
store %struct.ether_header* %11, %struct.ether_header** %12
%13 = load %struct.ip**, %struct.ip*** %7
store %struct.ip* null, %struct.ip** %13
%14 = load %struct.tcphdr**, %struct.tcphdr*** %8
store %struct.tcphdr* null, %struct.tcphdr** %14
%15 = load i64, i64* @ETHERTYPE_IP
%16 = load %struct.ether_header**, %struct.ether_header*** %6
%17 = load %struct.ether_header*, %struct.ether_header** %16
%18 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i64 @ntohs(i32 %19)
%21 = icmp ne i64 %15, %20
br i1 %21, label %22, label %23
22: ; preds = %4
br label %50
23: ; preds = %4
%24 = load %struct.ether_header**, %struct.ether_header*** %6
%25 = load %struct.ether_header*, %struct.ether_header** %24
%26 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %25, i64 1
%27 = bitcast %struct.ether_header* %26 to %struct.ip*
%28 = load %struct.ip**, %struct.ip*** %7
store %struct.ip* %27, %struct.ip** %28
%29 = load i64, i64* @IPPROTO_TCP
%30 = load %struct.ip**, %struct.ip*** %7
%31 = load %struct.ip*, %struct.ip** %30
%32 = getelementptr inbounds %struct.ip, %struct.ip* %31, i32 0, i32 0
%33 = load i64, i64* %32
%34 = icmp ne i64 %29, %33
br i1 %34, label %35, label %36
35: ; preds = %23
br label %50
36: ; preds = %23
%37 = load %struct.ip**, %struct.ip*** %7
%38 = load %struct.ip*, %struct.ip** %37
%39 = getelementptr inbounds %struct.ip, %struct.ip* %38, i32 0, i32 1
%40 = load i32, i32* %39
%41 = shl i32 %40, 2
store i32 %41, i32* %9
%42 = load %struct.ip**, %struct.ip*** %7
%43 = load %struct.ip*, %struct.ip** %42
%44 = bitcast %struct.ip* %43 to i8*
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = bitcast i8* %47 to %struct.tcphdr*
%49 = load %struct.tcphdr**, %struct.tcphdr*** %8
store %struct.tcphdr* %48, %struct.tcphdr** %49
br label %50
50: ; preds = %36, %35, %22
ret void
}

LLVM IR (-O2):
%struct.ether_header = type { i32 }
%struct.ip = type { i64, i32 }
%struct.tcphdr = type { i32 }
@ETHERTYPE_IP = global i64 0
@IPPROTO_TCP = global i64 0
define void @breakupPacket(i8* %0, %struct.ether_header** nocapture %1, %struct.ip** nocapture writeonly %2, %struct.tcphdr** nocapture writeonly %3) {
%5 = bitcast %struct.ether_header** %1 to i8**
store i8* %0, i8** %5
store %struct.ip* null, %struct.ip** %2
store %struct.tcphdr* null, %struct.tcphdr** %3
%6 = load i64, i64* @ETHERTYPE_IP
%7 = load %struct.ether_header*, %struct.ether_header** %1
%8 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %7, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i64 @ntohs(i32 %9)
%11 = icmp eq i64 %6, %10
br i1 %11, label %12, label %28
12: ; preds = %4
%13 = load %struct.ether_header*, %struct.ether_header** %1
%14 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %13, i64 1
%15 = bitcast %struct.ip** %2 to %struct.ether_header**
store %struct.ether_header* %14, %struct.ether_header** %15
%16 = load i64, i64* @IPPROTO_TCP
%17 = bitcast %struct.ether_header* %14 to i64*
%18 = load i64, i64* %17
%19 = icmp eq i64 %16, %18
br i1 %19, label %20, label %28
20: ; preds = %12
%21 = getelementptr inbounds %struct.ether_header, %struct.ether_header* %13, i64 3, i32 0
%22 = load i32, i32* %21
%23 = shl i32 %22, 2
%24 = bitcast %struct.ether_header* %14 to i8*
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = bitcast %struct.tcphdr** %3 to i8**
store i8* %26, i8** %27
br label %28
28: ; preds = %12, %4, %20
ret void
}