#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 */

/* Variables and functions */
int /*<<< orphan*/ data_dump(unsigned char *, int, int);
int get16(unsigned char *);
int /*<<< orphan*/ lprintf(int, char *, ...);
int /*<<< orphan*/ rip_dump(unsigned char *, int);
int servname(int, char *);
void udp_dump(unsigned char *data, int length, int hexdump) {
  int hdr_length;
  int source;
  int dest;
  hdr_length = get16(data + 4);
  source = get16(data + 0);
  dest = get16(data + 2);
  lprintf(6, "UDP:");
  lprintf(10, " len %d %s->", hdr_length, servname(source, "udp"));
  lprintf(10, "%s", servname(dest, "udp"));
  if (hdr_length > 8) {
    length -= 8;
    data += 8;
    switch (dest) {
    case 520:
      lprintf(10, "\n");
      rip_dump(data, length);
      break;
    default:
      lprintf(10, " Data %d\n", length);
      data_dump(data, length, hexdump);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<udp_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1060 <get16@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <get16@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
call   1060 <get16@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x6,%edi
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1070 <lprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
lea    0xe61(%rip),%rsi
call   1040 <servname@plt>
mov    -0x20(%rbp),%edx
mov    %eax,%ecx
mov    $0xa,%edi
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1070 <lprintf@plt>
mov    -0x1c(%rbp),%edi
lea    0xe3a(%rip),%rsi
call   1040 <servname@plt>
mov    %eax,%edx
mov    $0xa,%edi
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1070 <lprintf@plt>
cmpl   $0x8,-0x14(%rbp)
jle    1272 <udp_dump+0x122>
mov    -0xc(%rbp),%eax
add    $0xfffffff8,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x208,%eax
jne    1248 <udp_dump+0xf8>
jmp    1224 <udp_dump+0xd4>
mov    $0xa,%edi
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1070 <lprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <rip_dump@plt>
jmp    126d <udp_dump+0x11d>
mov    -0xc(%rbp),%edx
mov    $0xa,%edi
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   1070 <lprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <data_dump@plt>
jmp    1272 <udp_dump+0x122>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,0x4(%rsp)
mov    %esi,%r15d
mov    %rdi,%rbx
add    $0x4,%rdi
call   1060 <get16@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
call   1060 <get16@plt>
mov    %eax,%ebp
lea    0x2(%rbx),%rdi
call   1060 <get16@plt>
mov    %eax,%r12d
lea    0xe72(%rip),%rsi
mov    $0x6,%edi
xor    %eax,%eax
call   1070 <lprintf@plt>
lea    0xe71(%rip),%r14
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <servname@plt>
lea    0xe53(%rip),%rsi
mov    $0xa,%edi
mov    %r13d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <lprintf@plt>
mov    %r12d,%edi
mov    %r14,%rsi
call   1040 <servname@plt>
lea    0xe41(%rip),%rsi
mov    $0xa,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <lprintf@plt>
cmp    $0x9,%r13d
jl     122a <udp_dump+0xda>
mov    0x4(%rsp),%ebp
add    $0xfffffff8,%r15d
add    $0x8,%rbx
cmp    $0x208,%r12d
jne    1239 <udp_dump+0xe9>
lea    0xe1c(%rip),%rsi
mov    $0xa,%edi
xor    %eax,%eax
call   1070 <lprintf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <rip_dump@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd9(%rip),%rsi
mov    $0xa,%edi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <lprintf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <data_dump@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"UDP:\00"
@.str.1 = [13 x i8] c" len %d %s->\00"
@.str.2 = [4 x i8] c"udp\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [10 x i8] c" Data %d\0A\00"
define void @udp_dump(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 4
%12 = call i32 @get16(i8* %11)
store i32 %12, i32* %7
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = call i32 @get16(i8* %14)
store i32 %15, i32* %8
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 2
%18 = call i32 @get16(i8* %17)
store i32 %18, i32* %9
%19 = call i32 (i32, i8*, ...) @lprintf(i32 6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = call i32 @servname(i32 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 (i32, i8*, ...) @lprintf(i32 10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %22)
%24 = load i32, i32* %9
%25 = call i32 @servname(i32 %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 (i32, i8*, ...) @lprintf(i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %7
%28 = icmp sgt i32 %27, 8
br i1 %28, label %29, label %48
29: ; preds = %3
%30 = load i32, i32* %5
%31 = sub nsw i32 %30, 8
store i32 %31, i32* %5
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 8
store i8* %33, i8** %4
%34 = load i32, i32* %9
switch i32 %34, label %40 [
i32 520, label %35
]
35: ; preds = %29
%36 = call i32 (i32, i8*, ...) @lprintf(i32 10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%37 = load i8*, i8** %4
%38 = load i32, i32* %5
%39 = call i32 @rip_dump(i8* %37, i32 %38)
br label %47
40: ; preds = %29
%41 = load i32, i32* %5
%42 = call i32 (i32, i8*, ...) @lprintf(i32 10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = load i8*, i8** %4
%44 = load i32, i32* %5
%45 = load i32, i32* %6
%46 = call i32 @data_dump(i8* %43, i32 %44, i32 %45)
br label %47
47: ; preds = %40, %35
br label %48
48: ; preds = %47, %3
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"UDP:\00"
@.str.1 = [13 x i8] c" len %d %s->\00"
@.str.2 = [4 x i8] c"udp\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [10 x i8] c" Data %d\0A\00"
define void @udp_dump(i8* %0, i32 %1, i32 %2) {
%4 = getelementptr inbounds i8, i8* %0, i64 4
%5 = tail call i32 @get16(i8* %4)
%6 = tail call i32 @get16(i8* %0)
%7 = getelementptr inbounds i8, i8* %0, i64 2
%8 = tail call i32 @get16(i8* %7)
%9 = tail call i32 (i32, i8*, ...) @lprintf(i32 6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @servname(i32 %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 (i32, i8*, ...) @lprintf(i32 10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %10)
%12 = tail call i32 @servname(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 (i32, i8*, ...) @lprintf(i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = icmp sgt i32 %5, 8
br i1 %14, label %15, label %25
15: ; preds = %3
%16 = add nsw i32 %1, -8
%17 = getelementptr inbounds i8, i8* %0, i64 8
%18 = icmp eq i32 %8, 520
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = tail call i32 (i32, i8*, ...) @lprintf(i32 10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%21 = tail call i32 @rip_dump(i8* %17, i32 %16)
br label %25
22: ; preds = %15
%23 = tail call i32 (i32, i8*, ...) @lprintf(i32 10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%24 = tail call i32 @data_dump(i8* %17, i32 %16, i32 %2)
br label %25
25: ; preds = %19, %22, %3
ret void
}