#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_sport;
};

/* Variables and functions */
int ETHER_HDR_LEN;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void udp_short_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, " - %u ", ntohs(udp_header->uh_sport));
  fprintf(stdout, "-> %u", ntohs(udp_header->uh_dport));
  switch (ntohs(udp_header->uh_dport)) {
  case 68:
    fprintf(stdout, " DHCP");
    break;
  case 67:
    fprintf(stdout, " DHCP");
    break;
  default:
    break;
  }
}


x86 assembly (clang, -O0):
<udp_short_analysis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2e9e(%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    0x2e89(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <ntohs@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%edx
lea    0xe88(%rip),%rsi
xor    %eax,%eax
mov    %al,-0x1d(%rbp)
call   1030 <fprintf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <ntohs@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
mov    -0x1d(%rbp),%al
lea    0xe62(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <ntohs@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0x43,%eax
je     11f5 <udp_short_analysis+0xd5>
jmp    11c8 <udp_short_analysis+0xa8>
mov    -0x1c(%rbp),%eax
sub    $0x44,%eax
jne    1211 <udp_short_analysis+0xf1>
jmp    11d9 <udp_short_analysis+0xb9>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1216 <udp_short_analysis+0xf6>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1216 <udp_short_analysis+0xf6>
jmp    1216 <udp_short_analysis+0xf6>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_short_analysis>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2eaa(%rip),%rax
movslq (%rax),%rbx
add    %rdi,%rbx
movslq %esi,%rbp
mov    0x2ea2(%rip),%r14
mov    (%r14),%r15d
mov    0x4(%rbx,%rbp,4),%edi
call   1040 <ntohs@plt>
lea    0xeaf(%rip),%rsi
mov    %r15d,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%r15d
mov    (%rbx,%rbp,4),%edi
call   1040 <ntohs@plt>
lea    0xe98(%rip),%rsi
mov    %r15d,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%rbx,%rbp,4),%edi
call   1040 <ntohs@plt>
add    $0xffffffbd,%eax
cmp    $0x1,%eax
ja     11a6 <udp_short_analysis+0x86>
mov    (%r14),%edi
lea    0xe78(%rip),%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.udphdr = type { i32, i32 }
@ETHER_HDR_LEN = global i32 0
@stdout = global i32 0
@.str = [7 x i8] c" - %u \00"
@.str.1 = [6 x i8] c"-> %u\00"
@.str.2 = [6 x i8] c" DHCP\00"
define void @udp_short_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 = load %struct.udphdr*, %struct.udphdr** %5
%17 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = call i32 @ntohs(i32 %18)
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @stdout
%22 = load %struct.udphdr*, %struct.udphdr** %5
%23 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @ntohs(i32 %24)
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load %struct.udphdr*, %struct.udphdr** %5
%28 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @ntohs(i32 %29)
switch i32 %30, label %37 [
i32 68, label %31
i32 67, label %34
]
31: ; preds = %2
%32 = load i32, i32* @stdout
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %38
34: ; preds = %2
%35 = load i32, i32* @stdout
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %38
37: ; preds = %2
br label %38
38: ; preds = %37, %34, %31
ret void
}

LLVM IR (-O2):
@ETHER_HDR_LEN = global i32 0
@stdout = global i32 0
@.str = [7 x i8] c" - %u \00"
@.str.1 = [6 x i8] c"-> %u\00"
@.str.2 = [6 x i8] c" DHCP\00"
define void @udp_short_analysis(i8* nocapture %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 = getelementptr inbounds i8, i8* %8, i64 4
%11 = bitcast i8* %10 to i32*
%12 = load i32, i32* %11
%13 = tail call i32 @ntohs(i32 %12)
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @stdout
%16 = bitcast i8* %8 to i32*
%17 = load i32, i32* %16
%18 = tail call i32 @ntohs(i32 %17)
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %16
%21 = tail call i32 @ntohs(i32 %20)
%22 = add i32 %21, -67
%23 = icmp ult i32 %22, 2
br i1 %23, label %24, label %27
24: ; preds = %2
%25 = load i32, i32* @stdout
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %2, %24
ret void
}