#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 doff;
  int urg_ptr;
  int /*<<< orphan*/ window;
  int /*<<< orphan*/ check;
  int /*<<< orphan*/ ack_seq;
  int /*<<< orphan*/ seq;
  int /*<<< orphan*/ dest;
  int /*<<< orphan*/ source;
};
struct iphdr {
  int dummy;
};
struct ethhdr {
  int dummy;
};

/* Variables and functions */
int ntohl(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ print_data(char *, int);
int /*<<< orphan*/ printf(char *, ...);
void ip_tcp_packet_callback(char *packet_content, int size) {
  struct tcphdr *tcpst;
  int header_size;
  tcpst = (struct tcphdr *)(packet_content + sizeof(struct ethhdr) +
                            sizeof(struct iphdr));
  header_size = sizeof(struct ethhdr) + sizeof(struct iphdr) + tcpst->doff * 4;
  printf("TCP Header\n");
  printf("   |-Source Port            :%d\n", ntohs(tcpst->source));
  printf("   |-Destination Port       :%d\n", ntohs(tcpst->dest));
  printf("   |-Sequence Number        :%u\n", ntohl(tcpst->seq));
  printf("   |-Acknowledgement Number :%u\n", ntohl(tcpst->ack_seq));
  printf("   |-Header Length          :%d DWORDS or %d BYTES\n",
         (unsigned int)tcpst->doff, (unsigned int)tcpst->doff * 4);
  printf("   |-Check Sum              :%d\n", ntohs(tcpst->check));
  printf("   |-Window Size            :%d\n", ntohs(tcpst->window));
  printf("   |-Urgent Pointer         :%d\n", tcpst->urg_ptr);
  printf("[Ethner Header]\n");
  print_data(packet_content, sizeof(struct ethhdr));
  printf("[IP Header]\n");
  print_data(packet_content + sizeof(struct ethhdr), sizeof(struct iphdr));
  printf("[TCP Header]\n");
  print_data(packet_content + sizeof(struct ethhdr) + sizeof(struct iphdr),
             tcpst->doff * 4);
  printf("[Data Payload]\n");
  print_data(packet_content + header_size, size - header_size);
}


x86 assembly (clang, -O0):
<ip_tcp_packet_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%eax
cltq
add    $0x8,%rax
mov    %eax,-0x1c(%rbp)
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x1c(%rax),%edi
call   1050 <ntohs@plt>
mov    %eax,%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%edi
call   1050 <ntohs@plt>
mov    %eax,%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%edi
call   1060 <ntohl@plt>
mov    %eax,%esi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%edi
call   1060 <ntohl@plt>
mov    %eax,%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
shl    $0x2,%edx
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%edi
call   1050 <ntohs@plt>
mov    %eax,%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
call   1050 <ntohs@plt>
mov    %eax,%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x4,%esi
call   1040 <print_data@plt>
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
mov    $0x4,%esi
call   1040 <print_data@plt>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
add    $0x4,%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
shl    $0x2,%esi
call   1040 <print_data@plt>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
sub    -0x1c(%rbp),%esi
call   1040 <print_data@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_tcp_packet_callback>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x4(%rdi),%r15
lea    0x8(%rdi),%r14
mov    0x8(%rdi),%eax
lea    0x8(,%rax,4),%r12d
lea    0xfa4(%rip),%rdi
call   1030 <puts@plt>
mov    0x24(%rbx),%edi
call   1060 <ntohs@plt>
lea    0xe75(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rbx),%edi
call   1060 <ntohs@plt>
lea    0xe7e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rbx),%edi
call   1070 <ntohl@plt>
lea    0xe87(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rbx),%edi
call   1070 <ntohl@plt>
lea    0xe90(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%esi
lea    0x0(,%rsi,4),%edx
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rbx),%edi
call   1060 <ntohs@plt>
lea    0xeb5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%edi
call   1060 <ntohs@plt>
lea    0xebe(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rbx),%esi
lea    0xecc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1050 <print_data@plt>
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    $0x4,%esi
call   1050 <print_data@plt>
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%esi
shl    $0x2,%esi
mov    %r14,%rdi
call   1050 <print_data@plt>
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
movslq %r12d,%rax
add    %rax,%rbx
sub    %eax,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <print_data@plt>

LLVM IR (-O0):
%struct.tcphdr = type { i32, i32, i32, i32, i32, i32, i32, i32 }
@.str = [12 x i8] c"TCP Header\0A\00"
@.str.1 = [33 x i8] c" |-Source Port :%d\0A\00"
@.str.2 = [33 x i8] c" |-Destination Port :%d\0A\00"
@.str.3 = [33 x i8] c" |-Sequence Number :%u\0A\00"
@.str.4 = [33 x i8] c" |-Acknowledgement Number :%u\0A\00"
@.str.5 = [52 x i8] c" |-Header Length :%d DWORDS or %d BYTES\0A\00"
@.str.6 = [33 x i8] c" |-Check Sum :%d\0A\00"
@.str.7 = [33 x i8] c" |-Window Size :%d\0A\00"
@.str.8 = [33 x i8] c" |-Urgent Pointer :%d\0A\00"
@.str.9 = [17 x i8] c"[Ethner Header]\0A\00"
@.str.10 = [13 x i8] c"[IP Header]\0A\00"
@.str.11 = [14 x i8] c"[TCP Header]\0A\00"
@.str.12 = [16 x i8] c"[Data Payload]\0A\00"
define void @ip_tcp_packet_callback(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.tcphdr*
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 4
%9 = getelementptr inbounds i8, i8* %8, i64 4
%10 = bitcast i8* %9 to %struct.tcphdr*
store %struct.tcphdr* %10, %struct.tcphdr** %5
%11 = load %struct.tcphdr*, %struct.tcphdr** %5
%12 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = mul nsw i32 %13, 4
%15 = sext i32 %14 to i64
%16 = add i64 8, %15
%17 = trunc i64 %16 to i32
store i32 %17, i32* %6
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%19 = load %struct.tcphdr*, %struct.tcphdr** %5
%20 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %19, i32 0, i32 7
%21 = load i32, i32* %20
%22 = call i32 @ntohs(i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load %struct.tcphdr*, %struct.tcphdr** %5
%25 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %24, i32 0, i32 6
%26 = load i32, i32* %25
%27 = call i32 @ntohs(i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load %struct.tcphdr*, %struct.tcphdr** %5
%30 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %29, i32 0, i32 5
%31 = load i32, i32* %30
%32 = call i32 @ntohl(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = load %struct.tcphdr*, %struct.tcphdr** %5
%35 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %34, i32 0, i32 4
%36 = load i32, i32* %35
%37 = call i32 @ntohl(i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = load %struct.tcphdr*, %struct.tcphdr** %5
%40 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %39, i32 0, i32 0
%41 = load i32, i32* %40
%42 = load %struct.tcphdr*, %struct.tcphdr** %5
%43 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = mul i32 %44, 4
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i32 %41, i32 %45)
%47 = load %struct.tcphdr*, %struct.tcphdr** %5
%48 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %47, i32 0, i32 3
%49 = load i32, i32* %48
%50 = call i32 @ntohs(i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %50)
%52 = load %struct.tcphdr*, %struct.tcphdr** %5
%53 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %52, i32 0, i32 2
%54 = load i32, i32* %53
%55 = call i32 @ntohs(i32 %54)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %55)
%57 = load %struct.tcphdr*, %struct.tcphdr** %5
%58 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %57, i32 0, i32 1
%59 = load i32, i32* %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %59)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
%62 = load i8*, i8** %3
%63 = call i32 @print_data(i8* %62, i32 4)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%65 = load i8*, i8** %3
%66 = getelementptr inbounds i8, i8* %65, i64 4
%67 = call i32 @print_data(i8* %66, i32 4)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
%69 = load i8*, i8** %3
%70 = getelementptr inbounds i8, i8* %69, i64 4
%71 = getelementptr inbounds i8, i8* %70, i64 4
%72 = load %struct.tcphdr*, %struct.tcphdr** %5
%73 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = mul nsw i32 %74, 4
%76 = call i32 @print_data(i8* %71, i32 %75)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0))
%78 = load i8*, i8** %3
%79 = load i32, i32* %6
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
%82 = load i32, i32* %4
%83 = load i32, i32* %6
%84 = sub nsw i32 %82, %83
%85 = call i32 @print_data(i8* %81, i32 %84)
ret void
}

LLVM IR (-O2):
@.str.1 = [33 x i8] c" |-Source Port :%d\0A\00"
@.str.2 = [33 x i8] c" |-Destination Port :%d\0A\00"
@.str.3 = [33 x i8] c" |-Sequence Number :%u\0A\00"
@.str.4 = [33 x i8] c" |-Acknowledgement Number :%u\0A\00"
@.str.5 = [52 x i8] c" |-Header Length :%d DWORDS or %d BYTES\0A\00"
@.str.6 = [33 x i8] c" |-Check Sum :%d\0A\00"
@.str.7 = [33 x i8] c" |-Window Size :%d\0A\00"
@.str.8 = [33 x i8] c" |-Urgent Pointer :%d\0A\00"
@str = [11 x i8] c"TCP Header\00"
@str.13 = [16 x i8] c"[Ethner Header]\00"
@str.14 = [12 x i8] c"[IP Header]\00"
@str.15 = [13 x i8] c"[TCP Header]\00"
@str.16 = [15 x i8] c"[Data Payload]\00"
define void @ip_tcp_packet_callback(i8* %0, i32 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 4
%4 = getelementptr inbounds i8, i8* %0, i64 8
%5 = bitcast i8* %4 to i32*
%6 = load i32, i32* %5
%7 = shl nsw i32 %6, 2
%8 = add i32 %7, 8
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%10 = getelementptr inbounds i8, i8* %0, i64 36
%11 = bitcast i8* %10 to i32*
%12 = load i32, i32* %11
%13 = tail call i32 @ntohs(i32 %12)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds i8, i8* %0, i64 32
%16 = bitcast i8* %15 to i32*
%17 = load i32, i32* %16
%18 = tail call i32 @ntohs(i32 %17)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds i8, i8* %0, i64 28
%21 = bitcast i8* %20 to i32*
%22 = load i32, i32* %21
%23 = tail call i32 @ntohl(i32 %22)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds i8, i8* %0, i64 24
%26 = bitcast i8* %25 to i32*
%27 = load i32, i32* %26
%28 = tail call i32 @ntohl(i32 %27)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %5
%31 = shl i32 %30, 2
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i32 %30, i32 %31)
%33 = getelementptr inbounds i8, i8* %0, i64 20
%34 = bitcast i8* %33 to i32*
%35 = load i32, i32* %34
%36 = tail call i32 @ntohs(i32 %35)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds i8, i8* %0, i64 16
%39 = bitcast i8* %38 to i32*
%40 = load i32, i32* %39
%41 = tail call i32 @ntohs(i32 %40)
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds i8, i8* %0, i64 12
%44 = bitcast i8* %43 to i32*
%45 = load i32, i32* %44
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %45)
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.13, i64 0, i64 0))
%48 = tail call i32 @print_data(i8* %0, i32 4)
%49 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.14, i64 0, i64 0))
%50 = tail call i32 @print_data(i8* %3, i32 4)
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.15, i64 0, i64 0))
%52 = load i32, i32* %5
%53 = shl nsw i32 %52, 2
%54 = tail call i32 @print_data(i8* %4, i32 %53)
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.16, i64 0, i64 0))
%56 = sext i32 %8 to i64
%57 = getelementptr inbounds i8, i8* %0, i64 %56
%58 = sub nsw i32 %1, %8
%59 = tail call i32 @print_data(i8* %57, i32 %58)
ret void
}