#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 u_char;
struct iphdr {
  int ihl;
  int protocol;
};

/* Variables and functions */
int /*<<< orphan*/ pr_iph(struct iphdr *);
int /*<<< orphan*/ printf(char *, int, int);
void pr_retip(struct iphdr *ip) {
  int hlen;
  u_char *cp;
  pr_iph(ip);
  hlen = ip->ihl << 2;
  cp = (u_char *)ip + hlen;
  if (ip->protocol == 6)
    (void)printf("TCP: from port %u, to port %u (decimal)\n",
                 (*cp * 256 + *(cp + 1)), (*(cp + 2) * 256 + *(cp + 3)));
  else if (ip->protocol == 17)
    (void)printf("UDP: from port %u, to port %u (decimal)\n",
                 (*cp * 256 + *(cp + 1)), (*(cp + 2) * 256 + *(cp + 3)));
}


x86 assembly (clang, -O0):
<pr_retip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <pr_iph@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x6,0x4(%rax)
jne    1194 <pr_retip+0x74>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
shl    $0x8,%esi
mov    -0x18(%rbp),%rax
add    0x4(%rax),%esi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edx
shl    $0x8,%edx
mov    -0x18(%rbp),%rax
add    0xc(%rax),%edx
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
jmp    11d4 <pr_retip+0xb4>
mov    -0x8(%rbp),%rax
cmpl   $0x11,0x4(%rax)
jne    11cf <pr_retip+0xaf>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
shl    $0x8,%esi
mov    -0x18(%rbp),%rax
add    0x4(%rax),%esi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edx
shl    $0x8,%edx
mov    -0x18(%rbp),%rax
add    0xc(%rax),%edx
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
jmp    11d4 <pr_retip+0xb4>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pr_retip>:
push   %rbx
mov    %rdi,%rbx
call   1030 <pr_iph@plt>
mov    (%rbx),%eax
mov    0x4(%rbx),%ecx
cmp    $0x6,%ecx
je     1141 <pr_retip+0x21>
cmp    $0x11,%ecx
jne    1168 <pr_retip+0x48>
lea    0xeea(%rip),%rdi
jmp    1148 <pr_retip+0x28>
lea    0xeb8(%rip),%rdi
shl    $0x2,%eax
cltq
mov    (%rbx,%rax,4),%esi
shl    $0x8,%esi
add    0x4(%rbx,%rax,4),%esi
mov    0x8(%rbx,%rax,4),%edx
shl    $0x8,%edx
add    0xc(%rbx,%rax,4),%edx
pop    %rbx
jmp    1040 <printf@plt>
pop    %rbx
ret

LLVM IR (-O0):
%struct.iphdr = type { i32, i32 }
@.str = [41 x i8] c"TCP: from port %u, to port %u (decimal)\0A\00"
@.str.1 = [41 x i8] c"UDP: from port %u, to port %u (decimal)\0A\00"
define void @pr_retip(%struct.iphdr* %0) {
%2 = alloca %struct.iphdr*
%3 = alloca i32
%4 = alloca i32*
store %struct.iphdr* %0, %struct.iphdr** %2
%5 = load %struct.iphdr*, %struct.iphdr** %2
%6 = call i32 @pr_iph(%struct.iphdr* %5)
%7 = load %struct.iphdr*, %struct.iphdr** %2
%8 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = shl i32 %9, 2
store i32 %10, i32* %3
%11 = load %struct.iphdr*, %struct.iphdr** %2
%12 = bitcast %struct.iphdr* %11 to i32*
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
store i32* %15, i32** %4
%16 = load %struct.iphdr*, %struct.iphdr** %2
%17 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 6
br i1 %19, label %20, label %37
20: ; preds = %1
%21 = load i32*, i32** %4
%22 = load i32, i32* %21
%23 = mul nsw i32 %22, 256
%24 = load i32*, i32** %4
%25 = getelementptr inbounds i32, i32* %24, i64 1
%26 = load i32, i32* %25
%27 = add nsw i32 %23, %26
%28 = load i32*, i32** %4
%29 = getelementptr inbounds i32, i32* %28, i64 2
%30 = load i32, i32* %29
%31 = mul nsw i32 %30, 256
%32 = load i32*, i32** %4
%33 = getelementptr inbounds i32, i32* %32, i64 3
%34 = load i32, i32* %33
%35 = add nsw i32 %31, %34
%36 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %35)
br label %60
37: ; preds = %1
%38 = load %struct.iphdr*, %struct.iphdr** %2
%39 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %38, i32 0, i32 1
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, 17
br i1 %41, label %42, label %59
42: ; preds = %37
%43 = load i32*, i32** %4
%44 = load i32, i32* %43
%45 = mul nsw i32 %44, 256
%46 = load i32*, i32** %4
%47 = getelementptr inbounds i32, i32* %46, i64 1
%48 = load i32, i32* %47
%49 = add nsw i32 %45, %48
%50 = load i32*, i32** %4
%51 = getelementptr inbounds i32, i32* %50, i64 2
%52 = load i32, i32* %51
%53 = mul nsw i32 %52, 256
%54 = load i32*, i32** %4
%55 = getelementptr inbounds i32, i32* %54, i64 3
%56 = load i32, i32* %55
%57 = add nsw i32 %53, %56
%58 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %49, i32 %57)
br label %59
59: ; preds = %42, %37
br label %60
60: ; preds = %59, %20
ret void
}

LLVM IR (-O2):
%struct.iphdr = type { i32, i32 }
@.str = [41 x i8] c"TCP: from port %u, to port %u (decimal)\0A\00"
@.str.1 = [41 x i8] c"UDP: from port %u, to port %u (decimal)\0A\00"
define void @pr_retip(%struct.iphdr* %0) {
%2 = tail call i32 @pr_iph(%struct.iphdr* %0)
%3 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = shl i32 %4, 2
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i32, i32* %3, i64 %6
%8 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 1
%9 = load i32, i32* %8
switch i32 %9, label %25 [
i32 6, label %11
i32 17, label %10
]
10: ; preds = %1
br label %11
11: ; preds = %1, %10
%12 = phi i8* [ getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), %10 ], [ getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), %1 ]
%13 = load i32, i32* %7
%14 = shl nsw i32 %13, 8
%15 = getelementptr inbounds i32, i32* %7, i64 1
%16 = load i32, i32* %15
%17 = add nsw i32 %14, %16
%18 = getelementptr inbounds i32, i32* %7, i64 2
%19 = load i32, i32* %18
%20 = shl nsw i32 %19, 8
%21 = getelementptr inbounds i32, i32* %7, i64 3
%22 = load i32, i32* %21
%23 = add nsw i32 %20, %22
%24 = tail call i32 @printf(i8* %12, i32 %17, i32 %23)
br label %25
25: ; preds = %11, %1
ret void
}