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

/* Variables and functions */
int /*<<< orphan*/ htons(int);
void *inet_addr(char *);
int /*<<< orphan*/ memset(struct iphdr *, int /*<<< orphan*/, int);
int rand();
void init_iphdr(struct iphdr *ip, char *src, char *dest, int proto, int len) {
  memset(ip, 0, sizeof(struct iphdr));
  ip->ihl = 0x5;
  ip->version = 0x4;
  ip->tos = 0x0;
  ip->tot_len = len;
  ip->id = htons(rand() % 255);
  ip->frag_off = 0x0;
  ip->ttl = 64;
  ip->protocol = proto;
  ip->check = 0x0;
  ip->saddr = inet_addr(src);
  ip->daddr = inet_addr(dest);
}


x86 assembly (clang, -O0):
<init_iphdr>:
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),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
movl   $0x5,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x4,0x4(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x20(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x30(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x10(%rax)
mov    -0x8(%rbp),%rax
movl   $0x40,0x14(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x1c(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <inet_addr@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    -0x18(%rbp),%rdi
call   1050 <inet_addr@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x20(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_iphdr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%ebp
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
movabs $0x400000005,%rax
mov    %rax,(%rbx)
movl   $0x0,0x8(%rbx)
mov    %ebp,0xc(%rbx)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rdi
shr    $0x20,%rdi
add    %eax,%edi
mov    %edi,%ecx
shr    $0x1f,%ecx
sar    $0x7,%edi
add    %ecx,%edi
mov    %edi,%ecx
shl    $0x8,%ecx
sub    %ecx,%edi
add    %eax,%edi
call   1030 <htons@plt>
mov    %eax,0x30(%rbx)
movabs $0x4000000000,%rax
mov    %rax,0x10(%rbx)
mov    %r12d,0x18(%rbx)
movl   $0x0,0x1c(%rbx)
mov    %r15,%rdi
call   1050 <inet_addr@plt>
mov    %rax,0x28(%rbx)
mov    %r14,%rdi
call   1050 <inet_addr@plt>
mov    %rax,0x20(%rbx)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iphdr = type { i32, i32, i32, i32, i32, i32, i32, i32, i8*, i8*, i32 }
define void @init_iphdr(%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 = call i32 @memset(%struct.iphdr* %11, i32 0, i32 56)
%13 = load %struct.iphdr*, %struct.iphdr** %6
%14 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %13, i32 0, i32 0
store i32 5, i32* %14
%15 = load %struct.iphdr*, %struct.iphdr** %6
%16 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i32 0, i32 1
store i32 4, i32* %16
%17 = load %struct.iphdr*, %struct.iphdr** %6
%18 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %17, i32 0, i32 2
store i32 0, i32* %18
%19 = load i32, i32* %10
%20 = load %struct.iphdr*, %struct.iphdr** %6
%21 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %20, i32 0, i32 3
store i32 %19, i32* %21
%22 = call i32 (...) @rand()
%23 = srem i32 %22, 255
%24 = call i32 @htons(i32 %23)
%25 = load %struct.iphdr*, %struct.iphdr** %6
%26 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %25, i32 0, i32 10
store i32 %24, i32* %26
%27 = load %struct.iphdr*, %struct.iphdr** %6
%28 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %27, i32 0, i32 4
store i32 0, i32* %28
%29 = load %struct.iphdr*, %struct.iphdr** %6
%30 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %29, i32 0, i32 5
store i32 64, 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 7
store i32 0, i32* %35
%36 = load i8*, i8** %7
%37 = call i8* @inet_addr(i8* %36)
%38 = load %struct.iphdr*, %struct.iphdr** %6
%39 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %38, i32 0, i32 9
store i8* %37, i8** %39
%40 = load i8*, i8** %8
%41 = call i8* @inet_addr(i8* %40)
%42 = load %struct.iphdr*, %struct.iphdr** %6
%43 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %42, i32 0, i32 8
store i8* %41, i8** %43
ret void
}

LLVM IR (-O2):
%struct.iphdr = type { i32, i32, i32, i32, i32, i32, i32, i32, i8*, i8*, i32 }
define void @init_iphdr(%struct.iphdr* %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = tail call i32 @memset(%struct.iphdr* %0, i32 0, i32 56)
%7 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 0
store i32 5, i32* %7
%8 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 1
store i32 4, i32* %8
%9 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 2
store i32 0, i32* %9
%10 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 3
store i32 %4, i32* %10
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 255
%13 = tail call i32 @htons(i32 %12)
%14 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 10
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 4
store i32 0, i32* %15
%16 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 5
store i32 64, i32* %16
%17 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 6
store i32 %3, i32* %17
%18 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 7
store i32 0, i32* %18
%19 = tail call i8* @inet_addr(i8* %1)
%20 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 9
store i8* %19, i8** %20
%21 = tail call i8* @inet_addr(i8* %2)
%22 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 8
store i8* %21, i8** %22
ret void
}