#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;
  int /*<<< orphan*/ ip_dst;
  int /*<<< orphan*/ ip_src;
};

/* Variables and functions */
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int isAttachedDst(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                  int /*<<< orphan*/);
int isAttachedSrc(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                  int /*<<< orphan*/);
scalar_t__ isTCP(int /*<<< orphan*/ const *, int);
int isAttached(const u_char *p, int source) {
  return source
             ? isAttachedSrc(
                   ((struct ip *)(p + 14))->ip_src,
                   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),
                   ((struct ip *)(p + 14))->ip_dst,
                   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))
             : isAttachedDst(
                   ((struct ip *)(p + 14))->ip_src,
                   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),
                   ((struct ip *)(p + 14))->ip_dst,
                   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):
<isAttached>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     122e <isAttached+0xee>
mov    -0x8(%rbp),%rax
mov    0x40(%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <isTCP@plt>
cmp    $0x0,%rax
je     1196 <isAttached+0x56>
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,-0x14(%rbp)
jmp    11ae <isAttached+0x6e>
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,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    0x3c(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <isTCP@plt>
cmp    $0x0,%rax
je     11f6 <isAttached+0xb6>
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,-0x20(%rbp)
jmp    120e <isAttached+0xce>
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,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <htons@plt>
mov    -0x10(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    %eax,%ecx
call   1040 <isAttachedSrc@plt>
mov    %eax,-0x24(%rbp)
jmp    12fe <isAttached+0x1be>
mov    -0x8(%rbp),%rax
mov    0x40(%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <isTCP@plt>
cmp    $0x0,%rax
je     126b <isAttached+0x12b>
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,-0x2c(%rbp)
jmp    1283 <isAttached+0x143>
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,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
mov    0x3c(%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <isTCP@plt>
cmp    $0x0,%rax
je     12cb <isAttached+0x18b>
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,-0x38(%rbp)
jmp    12e3 <isAttached+0x1a3>
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,-0x38(%rbp)
mov    -0x38(%rbp),%edi
call   1030 <htons@plt>
mov    -0x28(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    %eax,%ecx
call   1050 <isAttachedDst@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isAttached>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    0x40(%rdi),%r14d
test   %esi,%esi
je     11a8 <isAttached+0x68>
mov    %esi,%ebp
mov    %rbx,%rdi
call   1060 <isTCP@plt>
movslq 0x38(%rbx),%rax
shl    $0x4,%rax
mov    0x3c(%rbx,%rax,1),%edi
call   1030 <htons@plt>
mov    %eax,%r15d
mov    0x3c(%rbx),%r12d
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <isTCP@plt>
movslq 0x38(%rbx),%rax
shl    $0x4,%rax
mov    0x38(%rbx,%rax,1),%edi
call   1030 <htons@plt>
mov    %r14d,%edi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %eax,%ecx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <isAttachedSrc@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <isTCP@plt>
movslq 0x38(%rbx),%rax
shl    $0x4,%rax
mov    0x3c(%rbx,%rax,1),%edi
call   1030 <htons@plt>
mov    %eax,%ebp
mov    0x3c(%rbx),%r15d
mov    %rbx,%rdi
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    %r14d,%edi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %eax,%ecx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <isAttachedDst@plt>

LLVM IR (-O0):
%struct.ip = type { i32, i32, i32 }
%struct.tcphdr = type { i32, i32 }
%struct.udphdr = type { i32, i32 }
define i32 @isAttached(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 %89
7: ; preds = %2
%8 = load i32*, i32** %3
%9 = getelementptr inbounds i32, i32* %8, i64 14
%10 = bitcast i32* %9 to %struct.ip*
%11 = getelementptr inbounds %struct.ip, %struct.ip* %10, i32 0, i32 2
%12 = load i32, i32* %11
%13 = load i32*, i32** %3
%14 = load i32, i32* %4
%15 = call i64 @isTCP(i32* %13, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %31
17: ; preds = %7
%18 = load i32*, i32** %3
%19 = getelementptr inbounds i32, i32* %18, i64 14
%20 = load i32*, i32** %3
%21 = getelementptr inbounds i32, i32* %20, i64 14
%22 = bitcast i32* %21 to %struct.ip*
%23 = getelementptr inbounds %struct.ip, %struct.ip* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = mul nsw i32 %24, 4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %19, i64 %26
%28 = bitcast i32* %27 to %struct.tcphdr*
%29 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %28, i32 0, i32 1
%30 = load i32, i32* %29
br label %45
31: ; preds = %7
%32 = load i32*, i32** %3
%33 = getelementptr inbounds i32, i32* %32, i64 14
%34 = load i32*, i32** %3
%35 = getelementptr inbounds i32, i32* %34, i64 14
%36 = bitcast i32* %35 to %struct.ip*
%37 = getelementptr inbounds %struct.ip, %struct.ip* %36, i32 0, i32 0
%38 = load i32, i32* %37
%39 = mul nsw i32 %38, 4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %33, i64 %40
%42 = bitcast i32* %41 to %struct.udphdr*
%43 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %42, i32 0, i32 1
%44 = load i32, i32* %43
br label %45
45: ; preds = %31, %17
%46 = phi i32 [ %30, %17 ], [ %44, %31 ]
%47 = call i32 @htons(i32 %46)
%48 = load i32*, i32** %3
%49 = getelementptr inbounds i32, i32* %48, i64 14
%50 = bitcast i32* %49 to %struct.ip*
%51 = getelementptr inbounds %struct.ip, %struct.ip* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = load i32*, i32** %3
%54 = load i32, i32* %4
%55 = call i64 @isTCP(i32* %53, i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %71
57: ; preds = %45
%58 = load i32*, i32** %3
%59 = getelementptr inbounds i32, i32* %58, i64 14
%60 = load i32*, i32** %3
%61 = getelementptr inbounds i32, i32* %60, i64 14
%62 = bitcast i32* %61 to %struct.ip*
%63 = getelementptr inbounds %struct.ip, %struct.ip* %62, i32 0, i32 0
%64 = load i32, i32* %63
%65 = mul nsw i32 %64, 4
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %59, i64 %66
%68 = bitcast i32* %67 to %struct.tcphdr*
%69 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %68, i32 0, i32 0
%70 = load i32, i32* %69
br label %85
71: ; preds = %45
%72 = load i32*, i32** %3
%73 = getelementptr inbounds i32, i32* %72, i64 14
%74 = load i32*, i32** %3
%75 = getelementptr inbounds i32, i32* %74, i64 14
%76 = bitcast i32* %75 to %struct.ip*
%77 = getelementptr inbounds %struct.ip, %struct.ip* %76, i32 0, i32 0
%78 = load i32, i32* %77
%79 = mul nsw i32 %78, 4
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32, i32* %73, i64 %80
%82 = bitcast i32* %81 to %struct.udphdr*
%83 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %82, i32 0, i32 0
%84 = load i32, i32* %83
br label %85
85: ; preds = %71, %57
%86 = phi i32 [ %70, %57 ], [ %84, %71 ]
%87 = call i32 @htons(i32 %86)
%88 = call i32 @isAttachedSrc(i32 %12, i32 %47, i32 %52, i32 %87)
br label %171
89: ; preds = %2
%90 = load i32*, i32** %3
%91 = getelementptr inbounds i32, i32* %90, i64 14
%92 = bitcast i32* %91 to %struct.ip*
%93 = getelementptr inbounds %struct.ip, %struct.ip* %92, i32 0, i32 2
%94 = load i32, i32* %93
%95 = load i32*, i32** %3
%96 = load i32, i32* %4
%97 = call i64 @isTCP(i32* %95, i32 %96)
%98 = icmp ne i64 %97, 0
br i1 %98, label %99, label %113
99: ; preds = %89
%100 = load i32*, i32** %3
%101 = getelementptr inbounds i32, i32* %100, i64 14
%102 = load i32*, i32** %3
%103 = getelementptr inbounds i32, i32* %102, i64 14
%104 = bitcast i32* %103 to %struct.ip*
%105 = getelementptr inbounds %struct.ip, %struct.ip* %104, i32 0, i32 0
%106 = load i32, i32* %105
%107 = mul nsw i32 %106, 4
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i32, i32* %101, i64 %108
%110 = bitcast i32* %109 to %struct.tcphdr*
%111 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %110, i32 0, i32 1
%112 = load i32, i32* %111
br label %127
113: ; preds = %89
%114 = load i32*, i32** %3
%115 = getelementptr inbounds i32, i32* %114, i64 14
%116 = load i32*, i32** %3
%117 = getelementptr inbounds i32, i32* %116, i64 14
%118 = bitcast i32* %117 to %struct.ip*
%119 = getelementptr inbounds %struct.ip, %struct.ip* %118, i32 0, i32 0
%120 = load i32, i32* %119
%121 = mul nsw i32 %120, 4
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i32, i32* %115, i64 %122
%124 = bitcast i32* %123 to %struct.udphdr*
%125 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %124, i32 0, i32 1
%126 = load i32, i32* %125
br label %127
127: ; preds = %113, %99
%128 = phi i32 [ %112, %99 ], [ %126, %113 ]
%129 = call i32 @htons(i32 %128)
%130 = load i32*, i32** %3
%131 = getelementptr inbounds i32, i32* %130, i64 14
%132 = bitcast i32* %131 to %struct.ip*
%133 = getelementptr inbounds %struct.ip, %struct.ip* %132, i32 0, i32 1
%134 = load i32, i32* %133
%135 = load i32*, i32** %3
%136 = load i32, i32* %4
%137 = call i64 @isTCP(i32* %135, i32 %136)
%138 = icmp ne i64 %137, 0
br i1 %138, label %139, label %153
139: ; preds = %127
%140 = load i32*, i32** %3
%141 = getelementptr inbounds i32, i32* %140, i64 14
%142 = load i32*, i32** %3
%143 = getelementptr inbounds i32, i32* %142, i64 14
%144 = bitcast i32* %143 to %struct.ip*
%145 = getelementptr inbounds %struct.ip, %struct.ip* %144, i32 0, i32 0
%146 = load i32, i32* %145
%147 = mul nsw i32 %146, 4
%148 = sext i32 %147 to i64
%149 = getelementptr inbounds i32, i32* %141, i64 %148
%150 = bitcast i32* %149 to %struct.tcphdr*
%151 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %150, i32 0, i32 0
%152 = load i32, i32* %151
br label %167
153: ; preds = %127
%154 = load i32*, i32** %3
%155 = getelementptr inbounds i32, i32* %154, i64 14
%156 = load i32*, i32** %3
%157 = getelementptr inbounds i32, i32* %156, i64 14
%158 = bitcast i32* %157 to %struct.ip*
%159 = getelementptr inbounds %struct.ip, %struct.ip* %158, i32 0, i32 0
%160 = load i32, i32* %159
%161 = mul nsw i32 %160, 4
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds i32, i32* %155, i64 %162
%164 = bitcast i32* %163 to %struct.udphdr*
%165 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %164, i32 0, i32 0
%166 = load i32, i32* %165
br label %167
167: ; preds = %153, %139
%168 = phi i32 [ %152, %139 ], [ %166, %153 ]
%169 = call i32 @htons(i32 %168)
%170 = call i32 @isAttachedDst(i32 %94, i32 %129, i32 %134, i32 %169)
br label %171
171: ; preds = %167, %85
%172 = phi i32 [ %88, %85 ], [ %170, %167 ]
ret i32 %172
}

LLVM IR (-O2):
define i32 @isAttached(i32* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
%4 = getelementptr inbounds i32, i32* %0, i64 14
%5 = getelementptr inbounds i32, i32* %0, i64 16
%6 = load i32, i32* %5
br i1 %3, label %26, label %7
7: ; preds = %2
%8 = tail call i64 @isTCP(i32* %0, i32 %1)
%9 = load i32, i32* %4
%10 = shl nsw i32 %9, 2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %4, i64 %11
%13 = getelementptr inbounds i32, i32* %12, i64 1
%14 = load i32, i32* %13
%15 = tail call i32 @htons(i32 %14)
%16 = getelementptr inbounds i32, i32* %0, i64 15
%17 = load i32, i32* %16
%18 = tail call i64 @isTCP(i32* %0, i32 %1)
%19 = load i32, i32* %4
%20 = shl nsw i32 %19, 2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %4, i64 %21
%23 = load i32, i32* %22
%24 = tail call i32 @htons(i32 %23)
%25 = tail call i32 @isAttachedSrc(i32 %6, i32 %15, i32 %17, i32 %24)
br label %45
26: ; preds = %2
%27 = tail call i64 @isTCP(i32* %0, i32 0)
%28 = load i32, i32* %4
%29 = shl nsw i32 %28, 2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %4, i64 %30
%32 = getelementptr inbounds i32, i32* %31, i64 1
%33 = load i32, i32* %32
%34 = tail call i32 @htons(i32 %33)
%35 = getelementptr inbounds i32, i32* %0, i64 15
%36 = load i32, i32* %35
%37 = tail call i64 @isTCP(i32* %0, i32 0)
%38 = load i32, i32* %4
%39 = shl nsw i32 %38, 2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %4, i64 %40
%42 = load i32, i32* %41
%43 = tail call i32 @htons(i32 %42)
%44 = tail call i32 @isAttachedDst(i32 %6, i32 %34, i32 %36, i32 %43)
br label %45
45: ; preds = %26, %7
%46 = phi i32 [ %25, %7 ], [ %44, %26 ]
ret i32 %46
}