#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 dummy;
};
struct iphdr {
  int ihl;
  int version;
  int /*<<< orphan*/ saddr;
  scalar_t__ check;
  int /*<<< orphan*/ protocol;
  void *ttl;
  scalar_t__ frag_off;
  int /*<<< orphan*/ id;
  void *tot_len;
  scalar_t__ tos;
};
typedef int /*<<< orphan*/ incoming;

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ htonl(int);
void *htons(int);
int /*<<< orphan*/ inet_addr(char *);
int random();
void setup_ip_header(struct iphdr *iph) {
  char incoming[] = {0x53, 0x41, 0x4d, 0x50, 0x9e, 0x45,
                     0x3a, 0xc0, 0x61, 0x1e, 0x69};
  int sizedata5 = sizeof(incoming);
  int sizeudpdata5 = sizeof(struct udphdr) + sizedata5;
  int sizepacket5 = sizeof(struct iphdr) + sizeudpdata5;
  iph->ihl = 5;
  iph->version = 4;
  iph->tos = 0;
  iph->tot_len = htons(sizeof(struct iphdr) + sizeof(struct udphdr) + 11);
  iph->id = htonl(random());
  iph->frag_off = 0;
  iph->ttl = htons(random());
  iph->protocol = IPPROTO_UDP;
  iph->check = 0;
  iph->saddr = inet_addr("192.168.3.100");
}


x86 assembly (clang, -O0):
<setup_ip_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xead(%rip),%rax
mov    %rax,-0x13(%rbp)
mov    0xeaa(%rip),%ax
mov    %ax,-0xb(%rbp)
mov    0xea2(%rip),%al
mov    %al,-0x9(%rbp)
movl   $0xb,-0x18(%rbp)
movslq -0x18(%rbp),%rax
add    $0x4,%rax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
add    $0x48,%rax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x5,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x4,0x4(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x40(%rax)
mov    $0x57,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x38(%rax)
mov    $0x0,%al
call   1060 <random@plt>
mov    %eax,%edi
call   1040 <htonl@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x30(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x28(%rax)
mov    $0x0,%al
call   1060 <random@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    0x2dd7(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x10(%rax)
lea    0xdee(%rip),%rdi
call   1050 <inet_addr@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_ip_header>:
push   %rbx
mov    %rdi,%rbx
movabs $0x400000005,%rax
mov    %rax,(%rdi)
movq   $0x0,0x40(%rdi)
mov    $0x57,%edi
call   1030 <htons@plt>
mov    %rax,0x38(%rbx)
xor    %eax,%eax
call   1060 <random@plt>
mov    %eax,%edi
call   1040 <htonl@plt>
mov    %eax,0x30(%rbx)
movq   $0x0,0x28(%rbx)
xor    %eax,%eax
call   1060 <random@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %rax,0x20(%rbx)
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rbx)
movq   $0x0,0x10(%rbx)
lea    0xe53(%rip),%rdi
call   1050 <inet_addr@plt>
mov    %eax,0x8(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
%struct.iphdr = type { i32, i32, i32, i64, i32, i8*, i64, i32, i8*, i64 }
@__const.setup_ip_header.incoming = [11 x i8] c"SAMP\9EE:\C0a\1Ei"
@IPPROTO_UDP = global i32 0
@.str = [14 x i8] c"192.168.3.100\00"
define void @setup_ip_header(%struct.iphdr* %0) {
%2 = alloca %struct.iphdr*
%3 = alloca [11 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store %struct.iphdr* %0, %struct.iphdr** %2
%7 = bitcast [11 x i8]* %3 to i8*
store i32 11, i32* %4
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = add i64 4, %9
%11 = trunc i64 %10 to i32
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = add i64 72, %13
%15 = trunc i64 %14 to i32
store i32 %15, i32* %6
%16 = load %struct.iphdr*, %struct.iphdr** %2
%17 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %16, i32 0, i32 0
store i32 5, i32* %17
%18 = load %struct.iphdr*, %struct.iphdr** %2
%19 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %18, i32 0, i32 1
store i32 4, i32* %19
%20 = load %struct.iphdr*, %struct.iphdr** %2
%21 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %20, i32 0, i32 9
store i64 0, i64* %21
%22 = call i8* @htons(i32 87)
%23 = load %struct.iphdr*, %struct.iphdr** %2
%24 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %23, i32 0, i32 8
store i8* %22, i8** %24
%25 = call i32 (...) @random()
%26 = call i32 @htonl(i32 %25)
%27 = load %struct.iphdr*, %struct.iphdr** %2
%28 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %27, i32 0, i32 7
store i32 %26, i32* %28
%29 = load %struct.iphdr*, %struct.iphdr** %2
%30 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %29, i32 0, i32 6
store i64 0, i64* %30
%31 = call i32 (...) @random()
%32 = call i8* @htons(i32 %31)
%33 = load %struct.iphdr*, %struct.iphdr** %2
%34 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %33, i32 0, i32 5
store i8* %32, i8** %34
%35 = load i32, i32* @IPPROTO_UDP
%36 = load %struct.iphdr*, %struct.iphdr** %2
%37 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %36, i32 0, i32 4
store i32 %35, i32* %37
%38 = load %struct.iphdr*, %struct.iphdr** %2
%39 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %38, i32 0, i32 3
store i64 0, i64* %39
%40 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%41 = load %struct.iphdr*, %struct.iphdr** %2
%42 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %41, i32 0, i32 2
store i32 %40, i32* %42
ret void
}

LLVM IR (-O2):
%struct.iphdr = type { i32, i32, i32, i64, i32, i8*, i64, i32, i8*, i64 }
@IPPROTO_UDP = global i32 0
@.str = [14 x i8] c"192.168.3.100\00"
define void @setup_ip_header(%struct.iphdr* nocapture writeonly %0) {
%2 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 0
store i32 5, i32* %2
%3 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 1
store i32 4, i32* %3
%4 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 9
store i64 0, i64* %4
%5 = tail call i8* @htons(i32 87)
%6 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 8
store i8* %5, i8** %6
%7 = tail call i32 (...) @random()
%8 = tail call i32 @htonl(i32 %7)
%9 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 7
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 6
store i64 0, i64* %10
%11 = tail call i32 (...) @random()
%12 = tail call i8* @htons(i32 %11)
%13 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 5
store i8* %12, i8** %13
%14 = load i32, i32* @IPPROTO_UDP
%15 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 4
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 3
store i64 0, i64* %16
%17 = tail call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%18 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 2
store i32 %17, i32* %18
ret void
}