#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 check;
  int /*<<< orphan*/ dest;
  int /*<<< orphan*/ source;
  int /*<<< orphan*/ len;
};

/* Variables and functions */
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void printUDPHeader(struct udphdr *udph) {
  printf("------------UDP Header\n");
  printf("udp total length : %d\n", ntohs(udph->len));
  printf("source port: \t%d\n", ntohs(udph->source));
  printf("dest port: \t%d\n", ntohs(udph->dest));
  printf("check: %d\n", udph->check);
  printf("----------------------\n\n");
}


x86 assembly (clang, -O0):
<printUDPHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%edi
call   1040 <ntohs@plt>
mov    %eax,%esi
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
call   1040 <ntohs@plt>
mov    %eax,%esi
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <ntohs@plt>
mov    %eax,%esi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printUDPHeader>:
push   %rbx
mov    %rdi,%rbx
lea    0xf09(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rbx),%edi
call   1050 <ntohs@plt>
lea    0xeb1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%edi
call   1050 <ntohs@plt>
lea    0xeb0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rbx),%edi
call   1050 <ntohs@plt>
lea    0xeaa(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%esi
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebc(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
%struct.udphdr = type { i32, i32, i32, i32 }
@.str = [24 x i8] c"------------UDP Header\0A\00"
@.str.1 = [23 x i8] c"udp total length : %d\0A\00"
@.str.2 = [18 x i8] c"source port: \09%d\0A\00"
@.str.3 = [16 x i8] c"dest port: \09%d\0A\00"
@.str.4 = [11 x i8] c"check: %d\0A\00"
@.str.5 = [25 x i8] c"----------------------\0A\0A\00"
define void @printUDPHeader(%struct.udphdr* %0) {
%2 = alloca %struct.udphdr*
store %struct.udphdr* %0, %struct.udphdr** %2
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 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 @ntohs(i32 %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 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 @ntohs(i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 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 @ntohs(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 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.udphdr = type { i32, i32, i32, i32 }
@.str.1 = [23 x i8] c"udp total length : %d\0A\00"
@.str.2 = [18 x i8] c"source port: \09%d\0A\00"
@.str.3 = [16 x i8] c"dest port: \09%d\0A\00"
@.str.4 = [11 x i8] c"check: %d\0A\00"
@str = [23 x i8] c"------------UDP Header\00"
@str.6 = [24 x i8] c"----------------------\0A\00"
define void @printUDPHeader(%struct.udphdr* nocapture %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 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 @ntohs(i32 %4)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 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 @ntohs(i32 %8)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 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 @ntohs(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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.6, i64 0, i64 0))
ret void
}