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

/* Variables and functions */
int /*<<< orphan*/ MAXTTL;
int /*<<< orphan*/ rand_cmwc();
void makeIPPacket(struct iphdr *iph, uint32_t dest, uint32_t source,
                  uint8_t protocol, int packetSize) {
  iph->ihl = 5;
  iph->version = 4;
  iph->tos = 0;
  iph->tot_len = sizeof(struct iphdr) + packetSize;
  iph->id = rand_cmwc();
  iph->frag_off = 0;
  iph->ttl = MAXTTL;
  iph->protocol = protocol;
  iph->check = 0;
  iph->saddr = source;
  iph->daddr = dest;
}


x86 assembly (clang, -O0):
<makeIPPacket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-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)
movslq -0x20(%rbp),%rax
add    $0x48,%rax
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    $0x0,%al
call   1030 <rand_cmwc@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x38(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x30(%rax)
mov    0x2e68(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x2c(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x28(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x20(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x10(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeIPPacket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movabs $0x400000005,%rax
mov    %rax,(%rdi)
movq   $0x0,0x40(%rdi)
add    $0x48,%r8d
mov    %r8d,0x8(%rdi)
xor    %eax,%eax
call   1030 <rand_cmwc@plt>
mov    %eax,0x38(%rbx)
movq   $0x0,0x30(%rbx)
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rbx)
mov    %ebp,0x28(%rbx)
movq   $0x0,0x20(%rbx)
mov    %r14,0x18(%rbx)
mov    %r15,0x10(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iphdr = type { i32, i32, i32, i8*, i8*, i64, i32, i32, i64, i32, i64 }
@MAXTTL = global i32 0
define void @makeIPPacket(%struct.iphdr* %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca %struct.iphdr*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store %struct.iphdr* %0, %struct.iphdr** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%11 = load %struct.iphdr*, %struct.iphdr** %6
%12 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %11, i32 0, i32 0
store i32 5, i32* %12
%13 = load %struct.iphdr*, %struct.iphdr** %6
%14 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %13, i32 0, i32 1
store i32 4, i32* %14
%15 = load %struct.iphdr*, %struct.iphdr** %6
%16 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i32 0, i32 10
store i64 0, i64* %16
%17 = load i32, i32* %10
%18 = sext i32 %17 to i64
%19 = add i64 72, %18
%20 = trunc i64 %19 to i32
%21 = load %struct.iphdr*, %struct.iphdr** %6
%22 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %21, i32 0, i32 2
store i32 %20, i32* %22
%23 = call i32 (...) @rand_cmwc()
%24 = load %struct.iphdr*, %struct.iphdr** %6
%25 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %24, i32 0, i32 9
store i32 %23, i32* %25
%26 = load %struct.iphdr*, %struct.iphdr** %6
%27 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %26, i32 0, i32 8
store i64 0, i64* %27
%28 = load i32, i32* @MAXTTL
%29 = load %struct.iphdr*, %struct.iphdr** %6
%30 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %29, i32 0, i32 7
store i32 %28, i32* %30
%31 = load i32, i32* %9
%32 = load %struct.iphdr*, %struct.iphdr** %6
%33 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %32, i32 0, i32 6
store i32 %31, i32* %33
%34 = load %struct.iphdr*, %struct.iphdr** %6
%35 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %34, i32 0, i32 5
store i64 0, i64* %35
%36 = load i8*, i8** %8
%37 = load %struct.iphdr*, %struct.iphdr** %6
%38 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %37, i32 0, i32 4
store i8* %36, i8** %38
%39 = load i8*, i8** %7
%40 = load %struct.iphdr*, %struct.iphdr** %6
%41 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %40, i32 0, i32 3
store i8* %39, i8** %41
ret void
}

LLVM IR (-O2):
%struct.iphdr = type { i32, i32, i32, i8*, i8*, i64, i32, i32, i64, i32, i64 }
@MAXTTL = global i32 0
define void @makeIPPacket(%struct.iphdr* nocapture writeonly %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 0
store i32 5, i32* %6
%7 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 1
store i32 4, i32* %7
%8 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 10
store i64 0, i64* %8
%9 = add i32 %4, 72
%10 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 2
store i32 %9, i32* %10
%11 = tail call i32 (...) @rand_cmwc()
%12 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 9
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 8
store i64 0, i64* %13
%14 = load i32, i32* @MAXTTL
%15 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 7
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 6
store i32 %3, i32* %16
%17 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 5
store i64 0, i64* %17
%18 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 4
store i8* %2, i8** %18
%19 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 3
store i8* %1, i8** %19
ret void
}