#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;
struct udphdr {
  int /*<<< orphan*/ uh_dport;
  int /*<<< orphan*/ uh_sum;
  int /*<<< orphan*/ uh_ulen;
  int /*<<< orphan*/ uh_sport;
};

/* Variables and functions */
int ETHER_HDR_LEN;
int /*<<< orphan*/ bootp_complete_analysis(unsigned char const *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void udp_analysis(const unsigned char *packet, uint8_t ihl) {
  const struct udphdr *udp_header;
  udp_header = (const struct udphdr *)(packet + ETHER_HDR_LEN + (ihl * 4));
  fprintf(stdout, "\t+------------------------+\n");
  fprintf(stdout, "\t| User datagram protocol |\n");
  fprintf(stdout, "\t+------------------------+\n");
  fprintf(stdout, "\tSource port: %u\n", ntohs(udp_header->uh_sport));
  fprintf(stdout, "\tDestination port: %u\n", ntohs(udp_header->uh_dport));
  fprintf(stdout, "\tLength: %u\n", ntohs(udp_header->uh_ulen));
  fprintf(stdout, "\tChecksum: %u\n", ntohs(udp_header->uh_sum));
  switch (ntohs(udp_header->uh_dport)) {
  case 68:
    bootp_complete_analysis(packet, ihl);
    break;
  case 67:
    bootp_complete_analysis(packet, ihl);
    break;
  default:
    break;
  }
}


x86 assembly (clang, -O0):
<udp_analysis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2e8e(%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    0x2e79(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
mov    %rsi,-0x48(%rbp)
xor    %eax,%eax
mov    %al,-0x1d(%rbp)
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%rcx
mov    -0x1d(%rbp),%al
mov    (%rcx),%edi
lea    0xe8b(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x48(%rbp),%rsi
mov    -0x30(%rbp),%rcx
mov    -0x1d(%rbp),%al
mov    (%rcx),%edi
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%edi
call   1050 <ntohs@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%edx
mov    -0x1d(%rbp),%al
lea    0xe6d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <ntohs@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%edx
mov    -0x1d(%rbp),%al
lea    0xe57(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
call   1050 <ntohs@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%edx
mov    -0x1d(%rbp),%al
lea    0xe45(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <ntohs@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
mov    -0x1d(%rbp),%al
lea    0xe29(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <ntohs@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0x43,%eax
je     128c <udp_analysis+0x15c>
jmp    126a <udp_analysis+0x13a>
mov    -0x1c(%rbp),%eax
sub    $0x44,%eax
jne    129d <udp_analysis+0x16d>
jmp    127b <udp_analysis+0x14b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <bootp_complete_analysis@plt>
jmp    12a2 <udp_analysis+0x172>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <bootp_complete_analysis@plt>
jmp    12a2 <udp_analysis+0x172>
jmp    12a2 <udp_analysis+0x172>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_analysis>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
mov    0x2e90(%rip),%rax
movslq (%rax),%rbx
add    %rdi,%rbx
movslq %esi,%r12
mov    0x2e88(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe9d(%rip),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xea5(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%r13),%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%r13),%ebp
mov    0xc(%rbx,%r12,4),%edi
call   1050 <ntohs@plt>
lea    0xe98(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%r13),%ebp
mov    (%rbx,%r12,4),%edi
call   1050 <ntohs@plt>
lea    0xe8b(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%r13),%ebp
mov    0x8(%rbx,%r12,4),%edi
call   1050 <ntohs@plt>
lea    0xe82(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%r13),%ebp
mov    0x4(%rbx,%r12,4),%edi
call   1050 <ntohs@plt>
lea    0xe6f(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx,%r12,4),%edi
call   1050 <ntohs@plt>
add    $0xffffffbd,%eax
cmp    $0x1,%eax
ja     1236 <udp_analysis+0x106>
mov    %r15,%rdi
mov    %r14d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <bootp_complete_analysis@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.udphdr = type { i32, i32, i32, i32 }
@ETHER_HDR_LEN = global i32 0
@stdout = global i32 0
@.str = [29 x i8] c"\09+------------------------+\0A\00"
@.str.1 = [29 x i8] c"\09| User datagram protocol |\0A\00"
@.str.2 = [18 x i8] c"\09Source port: %u\0A\00"
@.str.3 = [23 x i8] c"\09Destination port: %u\0A\00"
@.str.4 = [13 x i8] c"\09Length: %u\0A\00"
@.str.5 = [15 x i8] c"\09Checksum: %u\0A\00"
define void @udp_analysis(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.udphdr*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = load i32, i32* @ETHER_HDR_LEN
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i32, i32* %4
%11 = mul nsw i32 %10, 4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = bitcast i8* %13 to %struct.udphdr*
store %struct.udphdr* %14, %struct.udphdr** %5
%15 = load i32, i32* @stdout
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @stdout
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @stdout
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @stdout
%22 = load %struct.udphdr*, %struct.udphdr** %5
%23 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %22, i32 0, i32 3
%24 = load i32, i32* %23
%25 = call i32 @ntohs(i32 %24)
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @stdout
%28 = load %struct.udphdr*, %struct.udphdr** %5
%29 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @ntohs(i32 %30)
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = load i32, i32* @stdout
%34 = load %struct.udphdr*, %struct.udphdr** %5
%35 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %34, i32 0, i32 2
%36 = load i32, i32* %35
%37 = call i32 @ntohs(i32 %36)
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = load i32, i32* @stdout
%40 = load %struct.udphdr*, %struct.udphdr** %5
%41 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %40, i32 0, i32 1
%42 = load i32, i32* %41
%43 = call i32 @ntohs(i32 %42)
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %43)
%45 = load %struct.udphdr*, %struct.udphdr** %5
%46 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @ntohs(i32 %47)
switch i32 %48, label %57 [
i32 68, label %49
i32 67, label %53
]
49: ; preds = %2
%50 = load i8*, i8** %3
%51 = load i32, i32* %4
%52 = call i32 @bootp_complete_analysis(i8* %50, i32 %51)
br label %58
53: ; preds = %2
%54 = load i8*, i8** %3
%55 = load i32, i32* %4
%56 = call i32 @bootp_complete_analysis(i8* %54, i32 %55)
br label %58
57: ; preds = %2
br label %58
58: ; preds = %57, %53, %49
ret void
}

LLVM IR (-O2):
@ETHER_HDR_LEN = global i32 0
@stdout = global i32 0
@.str = [29 x i8] c"\09+------------------------+\0A\00"
@.str.1 = [29 x i8] c"\09| User datagram protocol |\0A\00"
@.str.2 = [18 x i8] c"\09Source port: %u\0A\00"
@.str.3 = [23 x i8] c"\09Destination port: %u\0A\00"
@.str.4 = [13 x i8] c"\09Length: %u\0A\00"
@.str.5 = [15 x i8] c"\09Checksum: %u\0A\00"
define void @udp_analysis(i8* %0, i32 %1) {
%3 = load i32, i32* @ETHER_HDR_LEN
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = shl nsw i32 %1, 2
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
%9 = load i32, i32* @stdout
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stdout
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @stdout
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stdout
%16 = getelementptr inbounds i8, i8* %8, i64 12
%17 = bitcast i8* %16 to i32*
%18 = load i32, i32* %17
%19 = tail call i32 @ntohs(i32 %18)
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @stdout
%22 = bitcast i8* %8 to i32*
%23 = load i32, i32* %22
%24 = tail call i32 @ntohs(i32 %23)
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32, i32* @stdout
%27 = getelementptr inbounds i8, i8* %8, i64 8
%28 = bitcast i8* %27 to i32*
%29 = load i32, i32* %28
%30 = tail call i32 @ntohs(i32 %29)
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @stdout
%33 = getelementptr inbounds i8, i8* %8, i64 4
%34 = bitcast i8* %33 to i32*
%35 = load i32, i32* %34
%36 = tail call i32 @ntohs(i32 %35)
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %22
%39 = tail call i32 @ntohs(i32 %38)
%40 = add i32 %39, -67
%41 = icmp ult i32 %40, 2
br i1 %41, label %42, label %44
42: ; preds = %2
%43 = tail call i32 @bootp_complete_analysis(i8* %0, i32 %1)
br label %44
44: ; preds = %2, %42
ret void
}