#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*/ u_char;
struct udphdr {
  int /*<<< orphan*/ dest;
  int /*<<< orphan*/ source;
};
struct tcphdr {
  int /*<<< orphan*/ dest;
  int /*<<< orphan*/ source;
};
struct ip {
  int ip_hl;
};

/* Variables and functions */
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int isFrequentPortDst(int /*<<< orphan*/);
int isFrequentPortSrc(int /*<<< orphan*/);
scalar_t__ isTCP(int /*<<< orphan*/ const *, int);
int isFrequentPort(const u_char *p, int source) {
  return source
             ? isFrequentPortSrc(htons(
                   isTCP(p, source)
                       ? ((struct tcphdr *)(p + 14 +
                                            ((struct ip *)(p + 14))->ip_hl * 4))
                             ->source
                       : ((struct udphdr *)(p + 14 +
                                            ((struct ip *)(p + 14))->ip_hl * 4))
                             ->source))
             : isFrequentPortDst(htons(
                   isTCP(p, source)
                       ? ((struct tcphdr *)(p + 14 +
                                            ((struct ip *)(p + 14))->ip_hl * 4))
                             ->dest
                       : ((struct udphdr *)(p + 14 +
                                            ((struct ip *)(p + 14))->ip_hl * 4))
                             ->dest));
}


x86 assembly (clang, -O0):
<isFrequentPort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11bb <isFrequentPort+0x7b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <isTCP@plt>
cmp    $0x0,%rax
je     118c <isFrequentPort+0x4c>
mov    -0x8(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    0x38(%rcx),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    0x3c(%rax,%rcx,4),%eax
mov    %eax,-0x10(%rbp)
jmp    11a4 <isFrequentPort+0x64>
mov    -0x8(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    0x38(%rcx),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    0x3c(%rax,%rcx,4),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%edi
call   1040 <isFrequentPortSrc@plt>
mov    %eax,-0x14(%rbp)
jmp    1218 <isFrequentPort+0xd8>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <isTCP@plt>
cmp    $0x0,%rax
je     11ee <isFrequentPort+0xae>
mov    -0x8(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    0x38(%rcx),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    0x38(%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
jmp    1206 <isFrequentPort+0xc6>
mov    -0x8(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    0x38(%rcx),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
mov    0x38(%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%edi
call   1050 <isFrequentPortDst@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isFrequentPort>:
push   %rbx
mov    %rdi,%rbx
test   %esi,%esi
je     1166 <isFrequentPort+0x26>
call   1060 <isTCP@plt>
movslq 0x38(%rbx),%rax
shl    $0x4,%rax
mov    0x3c(%rbx,%rax,1),%edi
call   1030 <htons@plt>
mov    %eax,%edi
pop    %rbx
jmp    1040 <isFrequentPortSrc@plt>
xor    %esi,%esi
call   1060 <isTCP@plt>
movslq 0x38(%rbx),%rax
shl    $0x4,%rax
mov    0x38(%rbx,%rax,1),%edi
call   1030 <htons@plt>
mov    %eax,%edi
pop    %rbx
jmp    1050 <isFrequentPortDst@plt>

LLVM IR (-O0):
%struct.ip = type { i32 }
%struct.tcphdr = type { i32, i32 }
%struct.udphdr = type { i32, i32 }
define i32 @isFrequentPort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %44
7: ; preds = %2
%8 = load i32*, i32** %3
%9 = load i32, i32* %4
%10 = call i64 @isTCP(i32* %8, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %7
%13 = load i32*, i32** %3
%14 = getelementptr inbounds i32, i32* %13, i64 14
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 14
%17 = bitcast i32* %16 to %struct.ip*
%18 = getelementptr inbounds %struct.ip, %struct.ip* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = mul nsw i32 %19, 4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %14, i64 %21
%23 = bitcast i32* %22 to %struct.tcphdr*
%24 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %23, i32 0, i32 1
%25 = load i32, i32* %24
br label %40
26: ; preds = %7
%27 = load i32*, i32** %3
%28 = getelementptr inbounds i32, i32* %27, i64 14
%29 = load i32*, i32** %3
%30 = getelementptr inbounds i32, i32* %29, i64 14
%31 = bitcast i32* %30 to %struct.ip*
%32 = getelementptr inbounds %struct.ip, %struct.ip* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = mul nsw i32 %33, 4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %28, i64 %35
%37 = bitcast i32* %36 to %struct.udphdr*
%38 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %37, i32 0, i32 1
%39 = load i32, i32* %38
br label %40
40: ; preds = %26, %12
%41 = phi i32 [ %25, %12 ], [ %39, %26 ]
%42 = call i32 @htons(i32 %41)
%43 = call i32 @isFrequentPortSrc(i32 %42)
br label %81
44: ; preds = %2
%45 = load i32*, i32** %3
%46 = load i32, i32* %4
%47 = call i64 @isTCP(i32* %45, i32 %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %63
49: ; preds = %44
%50 = load i32*, i32** %3
%51 = getelementptr inbounds i32, i32* %50, i64 14
%52 = load i32*, i32** %3
%53 = getelementptr inbounds i32, i32* %52, i64 14
%54 = bitcast i32* %53 to %struct.ip*
%55 = getelementptr inbounds %struct.ip, %struct.ip* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = mul nsw i32 %56, 4
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %51, i64 %58
%60 = bitcast i32* %59 to %struct.tcphdr*
%61 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %60, i32 0, i32 0
%62 = load i32, i32* %61
br label %77
63: ; preds = %44
%64 = load i32*, i32** %3
%65 = getelementptr inbounds i32, i32* %64, i64 14
%66 = load i32*, i32** %3
%67 = getelementptr inbounds i32, i32* %66, i64 14
%68 = bitcast i32* %67 to %struct.ip*
%69 = getelementptr inbounds %struct.ip, %struct.ip* %68, i32 0, i32 0
%70 = load i32, i32* %69
%71 = mul nsw i32 %70, 4
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %65, i64 %72
%74 = bitcast i32* %73 to %struct.udphdr*
%75 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %74, i32 0, i32 0
%76 = load i32, i32* %75
br label %77
77: ; preds = %63, %49
%78 = phi i32 [ %62, %49 ], [ %76, %63 ]
%79 = call i32 @htons(i32 %78)
%80 = call i32 @isFrequentPortDst(i32 %79)
br label %81
81: ; preds = %77, %40
%82 = phi i32 [ %43, %40 ], [ %80, %77 ]
ret i32 %82
}

LLVM IR (-O2):
define i32 @isFrequentPort(i32* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = tail call i64 @isTCP(i32* %0, i32 %1)
%6 = getelementptr inbounds i32, i32* %0, i64 14
%7 = load i32, i32* %6
%8 = shl nsw i32 %7, 2
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %6, i64 %9
%11 = getelementptr inbounds i32, i32* %10, i64 1
%12 = load i32, i32* %11
%13 = tail call i32 @htons(i32 %12)
%14 = tail call i32 @isFrequentPortSrc(i32 %13)
br label %25
15: ; preds = %2
%16 = tail call i64 @isTCP(i32* %0, i32 0)
%17 = getelementptr inbounds i32, i32* %0, i64 14
%18 = load i32, i32* %17
%19 = shl nsw i32 %18, 2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %17, i64 %20
%22 = load i32, i32* %21
%23 = tail call i32 @htons(i32 %22)
%24 = tail call i32 @isFrequentPortDst(i32 %23)
br label %25
25: ; preds = %15, %4
%26 = phi i32 [ %14, %4 ], [ %24, %15 ]
ret i32 %26
}