#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 {
  scalar_t__ rst;
  scalar_t__ ack;
  scalar_t__ psh;
  scalar_t__ fin;
  scalar_t__ syn;
  int /*<<< orphan*/ dest;
  int /*<<< orphan*/ source;
};
struct ip {
  int /*<<< orphan*/ ip_dst;
  int /*<<< orphan*/ ip_src;
};
struct ether_header {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ breakupPacket(void *, struct ether_header **, struct ip **,
                                 struct tcphdr **);
char *inet_ntoa(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void printPacket(void *buf) {
  struct ether_header *e;
  struct ip *i;
  struct tcphdr *t;
  breakupPacket(buf, &e, &i, &t);
  if (NULL == e) {
    printf("Not an Ethernet Packet\n");
    return;
  }
  if (NULL == i) {
    printf("Not an IP Packet\n");
    return;
  }
  if (NULL == t) {
    printf("Not a TCP Packet\n");
    return;
  }
  if (80 != ntohs((t->source)) && 80 != ntohs((t->dest)))
    return;
  printf("%s.%d > ", inet_ntoa(i->ip_src), ntohs((t->source)));
  printf("%s.%d\t", inet_ntoa(i->ip_dst), ntohs((t->dest)));
  if ((t->syn))
    printf("SYN ");
  if ((t->fin))
    printf("FIN ");
  if ((t->psh))
    printf("PUSH ");
  if ((t->ack))
    printf("ACK ");
  if ((t->rst))
    printf("RST ");
  printf("\n");
}


x86 assembly (clang, -O0):
<printPacket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1060 <breakupPacket@plt>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1180 <printPacket+0x40>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12f6 <printPacket+0x1b6>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    119f <printPacket+0x5f>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12f6 <printPacket+0x1b6>
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    11be <printPacket+0x7e>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12f6 <printPacket+0x1b6>
mov    -0x20(%rbp),%rax
mov    0x2c(%rax),%edi
call   1050 <ntohs@plt>
mov    %eax,%ecx
mov    $0x50,%eax
cmp    %ecx,%eax
je     11f9 <printPacket+0xb9>
mov    -0x20(%rbp),%rax
mov    0x28(%rax),%edi
call   1050 <ntohs@plt>
mov    %eax,%ecx
mov    $0x50,%eax
cmp    %ecx,%eax
je     11f9 <printPacket+0xb9>
jmp    12f6 <printPacket+0x1b6>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2c(%rax),%edi
call   1050 <ntohs@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x28(%rax),%edi
call   1050 <ntohs@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x20(%rax)
je     1275 <printPacket+0x135>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     1292 <printPacket+0x152>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     12af <printPacket+0x16f>
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     12cc <printPacket+0x18c>
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     12e8 <printPacket+0x1a8>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printPacket>:
push   %rbx
sub    $0x20,%rsp
lea    0x18(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1080 <breakupPacket@plt>
cmpq   $0x0,0x18(%rsp)
je     12ae <printPacket+0x14e>
cmpq   $0x0,0x10(%rsp)
je     12b7 <printPacket+0x157>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     12c0 <printPacket+0x160>
mov    0x2c(%rax),%edi
call   1070 <ntohs@plt>
cmp    $0x50,%eax
je     11c2 <printPacket+0x62>
mov    0x8(%rsp),%rax
mov    0x28(%rax),%edi
call   1070 <ntohs@plt>
cmp    $0x50,%eax
jne    12cc <printPacket+0x16c>
mov    0x10(%rsp),%rax
mov    0x4(%rax),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rax
mov    0x2c(%rax),%edi
call   1070 <ntohs@plt>
lea    0xe1a(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%rax
mov    (%rax),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rax
mov    0x28(%rax),%edi
call   1070 <ntohs@plt>
lea    0xdf4(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%rax
cmpq   $0x0,0x20(%rax)
je     1240 <printPacket+0xe0>
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%rax
cmpq   $0x0,0x18(%rax)
je     125a <printPacket+0xfa>
lea    0xdc7(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%rax
cmpq   $0x0,0x10(%rax)
je     1274 <printPacket+0x114>
lea    0xdb2(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%rax
cmpq   $0x0,0x8(%rax)
je     128e <printPacket+0x12e>
lea    0xd9e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%rax
cmpq   $0x0,(%rax)
je     12a2 <printPacket+0x142>
lea    0xd8a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    12cc <printPacket+0x16c>
lea    0xd97(%rip),%rdi
jmp    12c7 <printPacket+0x167>
lea    0xd7d(%rip),%rdi
jmp    12c7 <printPacket+0x167>
lea    0xd63(%rip),%rdi
call   1040 <puts@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.ether_header = type { i32 }
%struct.ip = type { i32, i32 }
%struct.tcphdr = type { i64, i64, i64, i64, i64, i32, i32 }
@.str = [24 x i8] c"Not an Ethernet Packet\0A\00"
@.str.1 = [18 x i8] c"Not an IP Packet\0A\00"
@.str.2 = [18 x i8] c"Not a TCP Packet\0A\00"
@.str.3 = [9 x i8] c"%s.%d > \00"
@.str.4 = [7 x i8] c"%s.%d\09\00"
@.str.5 = [5 x i8] c"SYN \00"
@.str.6 = [5 x i8] c"FIN \00"
@.str.7 = [6 x i8] c"PUSH \00"
@.str.8 = [5 x i8] c"ACK \00"
@.str.9 = [5 x i8] c"RST \00"
@.str.10 = [2 x i8] c"\0A\00"
define void @printPacket(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.ether_header*
%4 = alloca %struct.ip*
%5 = alloca %struct.tcphdr*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @breakupPacket(i8* %6, %struct.ether_header** %3, %struct.ip** %4, %struct.tcphdr** %5)
%8 = load %struct.ether_header*, %struct.ether_header** %3
%9 = icmp eq %struct.ether_header* null, %8
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %90
12: ; preds = %1
%13 = load %struct.ip*, %struct.ip** %4
%14 = icmp eq %struct.ip* null, %13
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %90
17: ; preds = %12
%18 = load %struct.tcphdr*, %struct.tcphdr** %5
%19 = icmp eq %struct.tcphdr* null, %18
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %90
22: ; preds = %17
%23 = load %struct.tcphdr*, %struct.tcphdr** %5
%24 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %23, i32 0, i32 6
%25 = load i32, i32* %24
%26 = call i32 @ntohs(i32 %25)
%27 = icmp ne i32 80, %26
br i1 %27, label %28, label %35
28: ; preds = %22
%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 @ntohs(i32 %31)
%33 = icmp ne i32 80, %32
br i1 %33, label %34, label %35
34: ; preds = %28
br label %90
35: ; preds = %28, %22
%36 = load %struct.ip*, %struct.ip** %4
%37 = getelementptr inbounds %struct.ip, %struct.ip* %36, i32 0, i32 1
%38 = load i32, i32* %37
%39 = call i8* @inet_ntoa(i32 %38)
%40 = load %struct.tcphdr*, %struct.tcphdr** %5
%41 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %40, i32 0, i32 6
%42 = load i32, i32* %41
%43 = call i32 @ntohs(i32 %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %39, i32 %43)
%45 = load %struct.ip*, %struct.ip** %4
%46 = getelementptr inbounds %struct.ip, %struct.ip* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i8* @inet_ntoa(i32 %47)
%49 = load %struct.tcphdr*, %struct.tcphdr** %5
%50 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %49, i32 0, i32 5
%51 = load i32, i32* %50
%52 = call i32 @ntohs(i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %48, i32 %52)
%54 = load %struct.tcphdr*, %struct.tcphdr** %5
%55 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %54, i32 0, i32 4
%56 = load i64, i64* %55
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %35
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %60
60: ; preds = %58, %35
%61 = load %struct.tcphdr*, %struct.tcphdr** %5
%62 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %61, i32 0, i32 3
%63 = load i64, i64* %62
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %60
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %67
67: ; preds = %65, %60
%68 = load %struct.tcphdr*, %struct.tcphdr** %5
%69 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %68, i32 0, i32 2
%70 = load i64, i64* %69
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %67
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %74
74: ; preds = %72, %67
%75 = load %struct.tcphdr*, %struct.tcphdr** %5
%76 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %75, i32 0, i32 1
%77 = load i64, i64* %76
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %74
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %81
81: ; preds = %79, %74
%82 = load %struct.tcphdr*, %struct.tcphdr** %5
%83 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %82, i32 0, i32 0
%84 = load i64, i64* %83
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %81
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %88
88: ; preds = %86, %81
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %90
90: ; preds = %88, %34, %20, %15, %10
ret void
}

LLVM IR (-O2):
%struct.ether_header = type { i32 }
%struct.ip = type { i32, i32 }
%struct.tcphdr = type { i64, i64, i64, i64, i64, i32, i32 }
@.str.3 = [9 x i8] c"%s.%d > \00"
@.str.4 = [7 x i8] c"%s.%d\09\00"
@.str.5 = [5 x i8] c"SYN \00"
@.str.6 = [5 x i8] c"FIN \00"
@.str.7 = [6 x i8] c"PUSH \00"
@.str.8 = [5 x i8] c"ACK \00"
@.str.9 = [5 x i8] c"RST \00"
@str = [17 x i8] c"Not a TCP Packet\00"
@str.11 = [17 x i8] c"Not an IP Packet\00"
@str.12 = [23 x i8] c"Not an Ethernet Packet\00"
define void @printPacket(i8* %0) {
%2 = alloca %struct.ether_header*
%3 = alloca %struct.ip*
%4 = alloca %struct.tcphdr*
%5 = bitcast %struct.ether_header** %2 to i8*
%6 = bitcast %struct.ip** %3 to i8*
%7 = bitcast %struct.tcphdr** %4 to i8*
%8 = call i32 @breakupPacket(i8* %0, %struct.ether_header** %2, %struct.ip** %3, %struct.tcphdr** %4)
%9 = load %struct.ether_header*, %struct.ether_header** %2
%10 = icmp eq %struct.ether_header* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.12, i64 0, i64 0))
br label %93
13: ; preds = %1
%14 = load %struct.ip*, %struct.ip** %3
%15 = icmp eq %struct.ip* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.11, i64 0, i64 0))
br label %93
18: ; preds = %13
%19 = load %struct.tcphdr*, %struct.tcphdr** %4
%20 = icmp eq %struct.tcphdr* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %93
23: ; preds = %18
%24 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %19, i64 0, i32 6
%25 = load i32, i32* %24
%26 = call i32 @ntohs(i32 %25)
%27 = icmp eq i32 %26, 80
br i1 %27, label %34, label %28
28: ; preds = %23
%29 = load %struct.tcphdr*, %struct.tcphdr** %4
%30 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %29, i64 0, i32 5
%31 = load i32, i32* %30
%32 = call i32 @ntohs(i32 %31)
%33 = icmp eq i32 %32, 80
br i1 %33, label %34, label %93
34: ; preds = %28, %23
%35 = load %struct.ip*, %struct.ip** %3
%36 = getelementptr inbounds %struct.ip, %struct.ip* %35, i64 0, i32 1
%37 = load i32, i32* %36
%38 = call i8* @inet_ntoa(i32 %37)
%39 = load %struct.tcphdr*, %struct.tcphdr** %4
%40 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %39, i64 0, i32 6
%41 = load i32, i32* %40
%42 = call i32 @ntohs(i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %38, i32 %42)
%44 = load %struct.ip*, %struct.ip** %3
%45 = getelementptr inbounds %struct.ip, %struct.ip* %44, i64 0, i32 0
%46 = load i32, i32* %45
%47 = call i8* @inet_ntoa(i32 %46)
%48 = load %struct.tcphdr*, %struct.tcphdr** %4
%49 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %48, i64 0, i32 5
%50 = load i32, i32* %49
%51 = call i32 @ntohs(i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %47, i32 %51)
%53 = load %struct.tcphdr*, %struct.tcphdr** %4
%54 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %53, i64 0, i32 4
%55 = load i64, i64* %54
%56 = icmp eq i64 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %34
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%59 = load %struct.tcphdr*, %struct.tcphdr** %4
br label %60
60: ; preds = %57, %34
%61 = phi %struct.tcphdr* [ %59, %57 ], [ %53, %34 ]
%62 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %61, i64 0, i32 3
%63 = load i64, i64* %62
%64 = icmp eq i64 %63, 0
br i1 %64, label %68, label %65
65: ; preds = %60
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%67 = load %struct.tcphdr*, %struct.tcphdr** %4
br label %68
68: ; preds = %65, %60
%69 = phi %struct.tcphdr* [ %67, %65 ], [ %61, %60 ]
%70 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %69, i64 0, i32 2
%71 = load i64, i64* %70
%72 = icmp eq i64 %71, 0
br i1 %72, label %76, label %73
73: ; preds = %68
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%75 = load %struct.tcphdr*, %struct.tcphdr** %4
br label %76
76: ; preds = %73, %68
%77 = phi %struct.tcphdr* [ %75, %73 ], [ %69, %68 ]
%78 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %77, i64 0, i32 1
%79 = load i64, i64* %78
%80 = icmp eq i64 %79, 0
br i1 %80, label %84, label %81
81: ; preds = %76
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%83 = load %struct.tcphdr*, %struct.tcphdr** %4
br label %84
84: ; preds = %81, %76
%85 = phi %struct.tcphdr* [ %83, %81 ], [ %77, %76 ]
%86 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %85, i64 0, i32 0
%87 = load i64, i64* %86
%88 = icmp eq i64 %87, 0
br i1 %88, label %91, label %89
89: ; preds = %84
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %91
91: ; preds = %89, %84
%92 = call i32 @putchar(i32 10)
br label %93
93: ; preds = %28, %91, %21, %16, %11
ret void
}