#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 u_int16_t;
struct udphdr {
  int /*<<< orphan*/ dest;
  int /*<<< orphan*/ source;
  int /*<<< orphan*/ len;
};
struct ip {
  int /*<<< orphan*/ ip_dst;
  int /*<<< orphan*/ ip_src;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
char *inet_ntoa(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
void print_udp(FILE *dst, const struct ip *ip, const struct udphdr *udp) {
  fprintf(dst, "UDP(HDR[8]DATA[%d]):\t %s:%d ",
          (u_int16_t)(ntohs(udp->len) - 8), inet_ntoa(ip->ip_src),
          (u_int16_t)ntohs(udp->source));
  fprintf(dst, " --> %s:%d", inet_ntoa(ip->ip_dst),
          (u_int16_t)ntohs(udp->dest));
  fprintf(dst, "\n");
}


x86 assembly (clang, -O0):
<print_udp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
call   1050 <ntohs@plt>
sub    $0x8,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <ntohs@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    %eax,%r8d
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <ntohs@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    %eax,%ecx
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_udp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x8(%rdx),%edi
call   1060 <ntohs@plt>
lea    -0x8(%rax),%r12d
mov    0x4(%r15),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rbp
mov    0x4(%rbx),%edi
call   1060 <ntohs@plt>
lea    0xe88(%rip),%rsi
mov    %r14,%rdi
mov    %r12d,%edx
mov    %rbp,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r15),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rbp
mov    (%rbx),%edi
call   1060 <ntohs@plt>
lea    0xe79(%rip),%rsi
mov    %r14,%rdi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xa,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fputc@plt>

LLVM IR (-O0):
%struct.ip = type { i32, i32 }
%struct.udphdr = type { i32, i32, i32 }
@.str = [29 x i8] c"UDP(HDR[8]DATA[%d]):\09 %s:%d \00"
@.str.1 = [11 x i8] c" --> %s:%d\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @print_udp(i32* %0, %struct.ip* %1, %struct.udphdr* %2) {
%4 = alloca i32*
%5 = alloca %struct.ip*
%6 = alloca %struct.udphdr*
store i32* %0, i32** %4
store %struct.ip* %1, %struct.ip** %5
store %struct.udphdr* %2, %struct.udphdr** %6
%7 = load i32*, i32** %4
%8 = load %struct.udphdr*, %struct.udphdr** %6
%9 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %8, i32 0, i32 2
%10 = load i32, i32* %9
%11 = call i32 @ntohs(i32 %10)
%12 = sub nsw i32 %11, 8
%13 = load %struct.ip*, %struct.ip** %5
%14 = getelementptr inbounds %struct.ip, %struct.ip* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = call i8* @inet_ntoa(i32 %15)
%17 = load %struct.udphdr*, %struct.udphdr** %6
%18 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = call i32 @ntohs(i32 %19)
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %16, i32 %20)
%22 = load i32*, i32** %4
%23 = load %struct.ip*, %struct.ip** %5
%24 = getelementptr inbounds %struct.ip, %struct.ip* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i8* @inet_ntoa(i32 %25)
%27 = load %struct.udphdr*, %struct.udphdr** %6
%28 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @ntohs(i32 %29)
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %30)
%32 = load i32*, i32** %4
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.ip = type { i32, i32 }
%struct.udphdr = type { i32, i32, i32 }
@.str = [29 x i8] c"UDP(HDR[8]DATA[%d]):\09 %s:%d \00"
@.str.1 = [11 x i8] c" --> %s:%d\00"
define void @print_udp(i32* nocapture %0, %struct.ip* nocapture %1, %struct.udphdr* nocapture %2) {
%4 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %2, i64 0, i32 2
%5 = load i32, i32* %4
%6 = tail call i32 @ntohs(i32 %5)
%7 = add nsw i32 %6, -8
%8 = getelementptr inbounds %struct.ip, %struct.ip* %1, i64 0, i32 1
%9 = load i32, i32* %8
%10 = tail call i8* @inet_ntoa(i32 %9)
%11 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %2, i64 0, i32 1
%12 = load i32, i32* %11
%13 = tail call i32 @ntohs(i32 %12)
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %7, i8* %10, i32 %13)
%15 = getelementptr inbounds %struct.ip, %struct.ip* %1, i64 0, i32 0
%16 = load i32, i32* %15
%17 = tail call i8* @inet_ntoa(i32 %16)
%18 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %2, i64 0, i32 0
%19 = load i32, i32* %18
%20 = tail call i32 @ntohs(i32 %19)
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %17, i32 %20)
%22 = tail call i32 @fputc(i32 10, i32* %0)
ret void
}