#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 {
  scalar_t__ uh_sum;
  void *uh_ulen;
  void *uh_dport;
  void *uh_sport;
};

/* Variables and functions */
void *htons(size_t);
void udp_setup(struct udphdr *udp_header, size_t *len) {
  *len += sizeof(struct udphdr);
  udp_header->uh_sport = htons(68);
  udp_header->uh_dport = htons(67);
  udp_header->uh_ulen = htons(*len);
  udp_header->uh_sum = 0;
}


x86 assembly (clang, -O0):
<udp_setup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x20,%rcx
mov    %rcx,(%rax)
mov    $0x44,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    $0x43,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_setup>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
addq   $0x20,(%rsi)
mov    $0x44,%edi
call   1030 <htons@plt>
mov    %rax,0x18(%rbx)
mov    $0x43,%edi
call   1030 <htons@plt>
mov    %rax,0x10(%rbx)
mov    (%r14),%rdi
call   1030 <htons@plt>
mov    %rax,0x8(%rbx)
movq   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.udphdr = type { i64, i8*, i8*, i8* }
define void @udp_setup(%struct.udphdr* %0, i64* %1) {
%3 = alloca %struct.udphdr*
%4 = alloca i64*
store %struct.udphdr* %0, %struct.udphdr** %3
store i64* %1, i64** %4
%5 = load i64*, i64** %4
%6 = load i64, i64* %5
%7 = add i64 %6, 32
store i64 %7, i64* %5
%8 = call i8* @htons(i64 68)
%9 = load %struct.udphdr*, %struct.udphdr** %3
%10 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %9, i32 0, i32 3
store i8* %8, i8** %10
%11 = call i8* @htons(i64 67)
%12 = load %struct.udphdr*, %struct.udphdr** %3
%13 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %12, i32 0, i32 2
store i8* %11, i8** %13
%14 = load i64*, i64** %4
%15 = load i64, i64* %14
%16 = call i8* @htons(i64 %15)
%17 = load %struct.udphdr*, %struct.udphdr** %3
%18 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %17, i32 0, i32 1
store i8* %16, i8** %18
%19 = load %struct.udphdr*, %struct.udphdr** %3
%20 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %19, i32 0, i32 0
store i64 0, i64* %20
ret void
}

LLVM IR (-O2):
%struct.udphdr = type { i64, i8*, i8*, i8* }
define void @udp_setup(%struct.udphdr* nocapture writeonly %0, i64* nocapture %1) {
%3 = load i64, i64* %1
%4 = add i64 %3, 32
store i64 %4, i64* %1
%5 = tail call i8* @htons(i64 68)
%6 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %0, i64 0, i32 3
store i8* %5, i8** %6
%7 = tail call i8* @htons(i64 67)
%8 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %0, i64 0, i32 2
store i8* %7, i8** %8
%9 = load i64, i64* %1
%10 = tail call i8* @htons(i64 %9)
%11 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %0, i64 0, i32 1
store i8* %10, i8** %11
%12 = getelementptr inbounds %struct.udphdr, %struct.udphdr* %0, i64 0, i32 0
store i64 0, i64* %12
ret void
}