#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 /*<<< orphan*/ uint32_t;
struct tcphdr {
  int th_flags;
  int /*<<< orphan*/ th_dport;
  int /*<<< orphan*/ th_sport;
};

/* Variables and functions */
int ETHER_HDR_LEN;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void tcp_succinct_analysis(const unsigned char *packet, uint8_t ihl,
                           const uint32_t len) {
  const struct tcphdr *tcp_header;
  tcp_header = (const struct tcphdr *)(packet + ETHER_HDR_LEN + (ihl * 4));
  fprintf(stdout, " %u ", ntohs(tcp_header->th_sport));
  fprintf(stdout, "-> %u ", ntohs(tcp_header->th_dport));
  fprintf(stdout, "(flags: 0x%x)", tcp_header->th_flags);
}


x86 assembly (clang, -O0):
<tcp_succinct_analysis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2e9b(%rip),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
call   1040 <ntohs@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%edx
lea    0xe8b(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <ntohs@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%edx
lea    0xe60(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xe4c(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp_succinct_analysis>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2eaa(%rip),%rax
movslq (%rax),%rbx
add    %rdi,%rbx
movslq %esi,%rbp
mov    0x2ea2(%rip),%r15
mov    (%r15),%r14d
mov    0x8(%rbx,%rbp,4),%edi
call   1040 <ntohs@plt>
lea    0xeb1(%rip),%rsi
mov    %r14d,%edi
mov    %eax,%edx
call   1030 <fprintf@plt>
mov    (%r15),%r14d
mov    0x4(%rbx,%rbp,4),%edi
call   1040 <ntohs@plt>
lea    0xe92(%rip),%rsi
mov    %r14d,%edi
mov    %eax,%edx
call   1030 <fprintf@plt>
mov    (%r15),%edi
mov    (%rbx,%rbp,4),%edx
lea    0xe82(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
%struct.tcphdr = type { i32, i32, i32 }
@ETHER_HDR_LEN = global i32 0
@stdout = global i32 0
@.str = [5 x i8] c" %u \00"
@.str.1 = [7 x i8] c"-> %u \00"
@.str.2 = [14 x i8] c"(flags: 0x%x)\00"
define void @tcp_succinct_analysis(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.tcphdr*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = load i32, i32* @ETHER_HDR_LEN
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i32, i32* %5
%13 = mul nsw i32 %12, 4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = bitcast i8* %15 to %struct.tcphdr*
store %struct.tcphdr* %16, %struct.tcphdr** %7
%17 = load i32, i32* @stdout
%18 = load %struct.tcphdr*, %struct.tcphdr** %7
%19 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %18, i32 0, i32 2
%20 = load i32, i32* %19
%21 = call i32 @ntohs(i32 %20)
%22 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @stdout
%24 = load %struct.tcphdr*, %struct.tcphdr** %7
%25 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = call i32 @ntohs(i32 %26)
%28 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @stdout
%30 = load %struct.tcphdr*, %struct.tcphdr** %7
%31 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %32)
ret void
}

LLVM IR (-O2):
@ETHER_HDR_LEN = global i32 0
@stdout = global i32 0
@.str = [5 x i8] c" %u \00"
@.str.1 = [7 x i8] c"-> %u \00"
@.str.2 = [14 x i8] c"(flags: 0x%x)\00"
define void @tcp_succinct_analysis(i8* nocapture %0, i32 %1, i32 %2) {
%4 = load i32, i32* @ETHER_HDR_LEN
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = shl nsw i32 %1, 2
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i32, i32* @stdout
%11 = getelementptr inbounds i8, i8* %9, i64 8
%12 = bitcast i8* %11 to i32*
%13 = load i32, i32* %12
%14 = tail call i32 @ntohs(i32 %13)
%15 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @stdout
%17 = getelementptr inbounds i8, i8* %9, i64 4
%18 = bitcast i8* %17 to i32*
%19 = load i32, i32* %18
%20 = tail call i32 @ntohs(i32 %19)
%21 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* @stdout
%23 = bitcast i8* %9 to i32*
%24 = load i32, i32* %23
%25 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %24)
ret void
}