#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int s_addr;
};
struct TYPE_3__ {
  scalar_t__ s_addr;
};
struct ip {
  int ip_hl;
  int ip_tos;
  int ip_ttl;
  scalar_t__ ip_sum;
  TYPE_2__ ip_dst;
  TYPE_1__ ip_src;
  int /*<<< orphan*/ ip_p;
  scalar_t__ ip_off;
  int /*<<< orphan*/ ip_id;
  int /*<<< orphan*/ ip_len;
  int /*<<< orphan*/ ip_v;
};

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ IPVERSION;
int /*<<< orphan*/ htonl(int);
int /*<<< orphan*/ htons(size_t);
scalar_t__ in_cksum(unsigned short *, int);
void ip_setup(struct ip *ip_header, size_t *len) {
  *len += sizeof(struct ip);
  ip_header->ip_hl = 5;
  ip_header->ip_v = IPVERSION;
  ip_header->ip_tos = 0x10;
  ip_header->ip_len = htons(*len);
  ip_header->ip_id = htonl(0xffff);
  ip_header->ip_off = 0;
  ip_header->ip_ttl = 16;
  ip_header->ip_p = IPPROTO_UDP;
  ip_header->ip_sum = 0;
  ip_header->ip_src.s_addr = 0;
  ip_header->ip_dst.s_addr = 0xffffffff;
  ip_header->ip_sum = in_cksum((unsigned short *)ip_header, sizeof(struct ip));
}


x86 assembly (clang, -O0):
<ip_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    $0x48,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x5,(%rax)
mov    0x2e89(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x40(%rax)
mov    -0x8(%rbp),%rax
movl   $0x10,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <htons@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x3c(%rax)
mov    $0xffff,%edi
call   1050 <htonl@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x38(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x30(%rax)
mov    -0x8(%rbp),%rax
movl   $0x10,0x8(%rax)
mov    0x2e17(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x28(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x20(%rax)
mov    -0x8(%rbp),%rax
movl   $0xffffffff,0x18(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x48,%esi
call   1030 <in_cksum@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x10(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_setup>:
push   %rbx
mov    %rdi,%rbx
mov    (%rsi),%rdi
add    $0x48,%rdi
mov    %rdi,(%rsi)
movl   $0x5,(%rbx)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rbx)
movl   $0x10,0x4(%rbx)
call   1040 <htons@plt>
mov    %eax,0x3c(%rbx)
mov    $0xffff,%edi
call   1050 <htonl@plt>
mov    %eax,0x38(%rbx)
movq   $0x0,0x30(%rbx)
movl   $0x10,0x8(%rbx)
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rbx)
movq   $0x0,0x10(%rbx)
movq   $0x0,0x20(%rbx)
movl   $0xffffffff,0x18(%rbx)
mov    %rbx,%rdi
mov    $0x48,%esi
call   1030 <in_cksum@plt>
mov    %rax,0x10(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
%struct.ip = type { i32, i32, i32, i64, %struct.TYPE_4__, %struct.TYPE_3__, i32, i64, i32, i32, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.TYPE_3__ = type { i64 }
@IPVERSION = global i32 0
@IPPROTO_UDP = global i32 0
define void @ip_setup(%struct.ip* %0, i64* %1) {
%3 = alloca %struct.ip*
%4 = alloca i64*
store %struct.ip* %0, %struct.ip** %3
store i64* %1, i64** %4
%5 = load i64*, i64** %4
%6 = load i64, i64* %5
%7 = add i64 %6, 72
store i64 %7, i64* %5
%8 = load %struct.ip*, %struct.ip** %3
%9 = getelementptr inbounds %struct.ip, %struct.ip* %8, i32 0, i32 0
store i32 5, i32* %9
%10 = load i32, i32* @IPVERSION
%11 = load %struct.ip*, %struct.ip** %3
%12 = getelementptr inbounds %struct.ip, %struct.ip* %11, i32 0, i32 10
store i32 %10, i32* %12
%13 = load %struct.ip*, %struct.ip** %3
%14 = getelementptr inbounds %struct.ip, %struct.ip* %13, i32 0, i32 1
store i32 16, i32* %14
%15 = load i64*, i64** %4
%16 = load i64, i64* %15
%17 = call i32 @htons(i64 %16)
%18 = load %struct.ip*, %struct.ip** %3
%19 = getelementptr inbounds %struct.ip, %struct.ip* %18, i32 0, i32 9
store i32 %17, i32* %19
%20 = call i32 @htonl(i32 65535)
%21 = load %struct.ip*, %struct.ip** %3
%22 = getelementptr inbounds %struct.ip, %struct.ip* %21, i32 0, i32 8
store i32 %20, i32* %22
%23 = load %struct.ip*, %struct.ip** %3
%24 = getelementptr inbounds %struct.ip, %struct.ip* %23, i32 0, i32 7
store i64 0, i64* %24
%25 = load %struct.ip*, %struct.ip** %3
%26 = getelementptr inbounds %struct.ip, %struct.ip* %25, i32 0, i32 2
store i32 16, i32* %26
%27 = load i32, i32* @IPPROTO_UDP
%28 = load %struct.ip*, %struct.ip** %3
%29 = getelementptr inbounds %struct.ip, %struct.ip* %28, i32 0, i32 6
store i32 %27, i32* %29
%30 = load %struct.ip*, %struct.ip** %3
%31 = getelementptr inbounds %struct.ip, %struct.ip* %30, i32 0, i32 3
store i64 0, i64* %31
%32 = load %struct.ip*, %struct.ip** %3
%33 = getelementptr inbounds %struct.ip, %struct.ip* %32, i32 0, i32 5
%34 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %33, i32 0, i32 0
store i64 0, i64* %34
%35 = load %struct.ip*, %struct.ip** %3
%36 = getelementptr inbounds %struct.ip, %struct.ip* %35, i32 0, i32 4
%37 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %36, i32 0, i32 0
store i32 -1, i32* %37
%38 = load %struct.ip*, %struct.ip** %3
%39 = bitcast %struct.ip* %38 to i16*
%40 = call i64 @in_cksum(i16* %39, i32 72)
%41 = load %struct.ip*, %struct.ip** %3
%42 = getelementptr inbounds %struct.ip, %struct.ip* %41, i32 0, i32 3
store i64 %40, i64* %42
ret void
}

LLVM IR (-O2):
%struct.ip = type { i32, i32, i32, i64, %struct.TYPE_4__, %struct.TYPE_3__, i32, i64, i32, i32, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.TYPE_3__ = type { i64 }
@IPVERSION = global i32 0
@IPPROTO_UDP = global i32 0
define void @ip_setup(%struct.ip* %0, i64* nocapture %1) {
%3 = load i64, i64* %1
%4 = add i64 %3, 72
store i64 %4, i64* %1
%5 = getelementptr inbounds %struct.ip, %struct.ip* %0, i64 0, i32 0
store i32 5, i32* %5
%6 = load i32, i32* @IPVERSION
%7 = getelementptr inbounds %struct.ip, %struct.ip* %0, i64 0, i32 10
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.ip, %struct.ip* %0, i64 0, i32 1
store i32 16, i32* %8
%9 = tail call i32 @htons(i64 %4)
%10 = getelementptr inbounds %struct.ip, %struct.ip* %0, i64 0, i32 9
store i32 %9, i32* %10
%11 = tail call i32 @htonl(i32 65535)
%12 = getelementptr inbounds %struct.ip, %struct.ip* %0, i64 0, i32 8
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.ip, %struct.ip* %0, i64 0, i32 7
store i64 0, i64* %13
%14 = getelementptr inbounds %struct.ip, %struct.ip* %0, i64 0, i32 2
store i32 16, i32* %14
%15 = load i32, i32* @IPPROTO_UDP
%16 = getelementptr inbounds %struct.ip, %struct.ip* %0, i64 0, i32 6
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.ip, %struct.ip* %0, i64 0, i32 3
store i64 0, i64* %17
%18 = getelementptr inbounds %struct.ip, %struct.ip* %0, i64 0, i32 5, i32 0
store i64 0, i64* %18
%19 = getelementptr inbounds %struct.ip, %struct.ip* %0, i64 0, i32 4, i32 0
store i32 -1, i32* %19
%20 = bitcast %struct.ip* %0 to i16*
%21 = tail call i64 @in_cksum(i16* %20, i32 72)
store i64 %21, i64* %17
ret void
}