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

/* Variables and functions */
int htons(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void dump_udp_header(struct udphdr *udph) {
  printf("[UDP Header]\n");
  printf("\t- Source port : %d\n", htons(udph->uh_sport));
  printf("\t- Destination port : %d\n", htons(udph->uh_dport));
  printf("\t- Length : %d\n", htons(udph->uh_ulen));
  printf("\t- Checksum : %x\n", htons(udph->uh_sum));
}


x86 assembly (clang, -O0):
<dump_udp_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%edi
call   1030 <htons@plt>
mov    %eax,%esi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
call   1030 <htons@plt>
mov    %eax,%esi
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <htons@plt>
mov    %eax,%esi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <htons@plt>
mov    %eax,%esi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_udp_header>:
push   %rbx
mov    %rdi,%rbx
lea    0xf16(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rbx),%edi
call   1040 <htons@plt>
lea    0xeb1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%edi
call   1040 <htons@plt>
lea    0xeae(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%edi
call   1040 <htons@plt>
lea    0xeb0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%edi
call   1040 <htons@plt>
lea    0xea9(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
pop    %rbx
jmp    1050 <printf@plt>

LLVM IR (-O0):
%struct.udphdr = type { i32, i32, i32, i32 }
@.str = [14 x i8] c"[UDP Header]\0A\00"
@.str.1 = [21 x i8] c"\09- Source port : %d\0A\00"
@.str.2 = [26 x i8] c"\09- Destination port : %d\0A\00"
@.str.3 = [16 x i8] c"\09- Length : %d\0A\00"
@.str.4 = [18 x i8] c"\09- Checksum : %x\0A\00"
define void @dump_udp_header(%struct.udphdr* %0) {
%2 = alloca %struct.udphdr*
store %struct.udphdr* %0, %struct.udphdr** %2
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = load %struct.udphdr*, %struct.udphdr** %2
%5 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %4, i32 0, i32 3
%6 = load i32, i32* %5
%7 = call i32 @htons(i32 %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = load %struct.udphdr*, %struct.udphdr** %2
%10 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %9, i32 0, i32 2
%11 = load i32, i32* %10
%12 = call i32 @htons(i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = load %struct.udphdr*, %struct.udphdr** %2
%15 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %14, i32 0, i32 1
%16 = load i32, i32* %15
%17 = call i32 @htons(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = load %struct.udphdr*, %struct.udphdr** %2
%20 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @htons(i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %22)
ret void
}

LLVM IR (-O2):
%struct.udphdr = type { i32, i32, i32, i32 }
@.str.1 = [21 x i8] c"\09- Source port : %d\0A\00"
@.str.2 = [26 x i8] c"\09- Destination port : %d\0A\00"
@.str.3 = [16 x i8] c"\09- Length : %d\0A\00"
@.str.4 = [18 x i8] c"\09- Checksum : %x\0A\00"
@str = [13 x i8] c"[UDP Header]\00"
define void @dump_udp_header(%struct.udphdr* nocapture %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%3 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %0, i64 0, i32 3
%4 = load i32, i32* %3
%5 = tail call i32 @htons(i32 %4)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %0, i64 0, i32 2
%8 = load i32, i32* %7
%9 = tail call i32 @htons(i32 %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %0, i64 0, i32 1
%12 = load i32, i32* %11
%13 = tail call i32 @htons(i32 %12)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %0, i64 0, i32 0
%16 = load i32, i32* %15
%17 = tail call i32 @htons(i32 %16)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %17)
ret void
}