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

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_IGMP;
void *htons(int);
void ip_header_init(struct iphdr *iph, struct in_addr saddr,
                    struct in_addr daddr) {
  iph->version = 4;
  iph->ihl = 6;
  iph->tos = 0xc0;
  iph->id = htons(0);
  iph->frag_off = htons(0x4000);
  iph->ttl = 1;
  iph->protocol = IPPROTO_IGMP;
  iph->saddr = saddr.s_addr;
  iph->daddr = daddr.s_addr;
}


x86 assembly (clang, -O0):
<ip_header_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %esi,-0x8(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x6,0x4(%rax)
mov    -0x18(%rbp),%rax
movl   $0xc0,0x8(%rax)
xor    %edi,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    $0x4000,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    0x2e65(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x10(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_header_init>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
movabs $0x600000004,%rax
mov    %rax,(%rdi)
movl   $0xc0,0x8(%rdi)
xor    %edi,%edi
call   1030 <htons@plt>
mov    %rax,0x28(%rbx)
mov    $0x4000,%edi
call   1030 <htons@plt>
mov    %rax,0x20(%rbx)
movl   $0x1,0xc(%rbx)
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rbx)
mov    %ebp,0x14(%rbx)
mov    %r14d,0x10(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.iphdr = type { i32, i32, i32, i32, i32, i32, i32, i8*, i8* }
%struct.in_addr = type { i32 }
@IPPROTO_IGMP = global i32 0
define void @ip_header_init(%struct.iphdr* %0, i32 %1, i32 %2) {
%4 = alloca %struct.in_addr
%5 = alloca %struct.in_addr
%6 = alloca %struct.iphdr*
%7 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
store i32 %1, i32* %7
%8 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i32 0, i32 0
store i32 %2, i32* %8
store %struct.iphdr* %0, %struct.iphdr** %6
%9 = load %struct.iphdr*, %struct.iphdr** %6
%10 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %9, i32 0, i32 0
store i32 4, i32* %10
%11 = load %struct.iphdr*, %struct.iphdr** %6
%12 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %11, i32 0, i32 1
store i32 6, i32* %12
%13 = load %struct.iphdr*, %struct.iphdr** %6
%14 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %13, i32 0, i32 2
store i32 192, i32* %14
%15 = call i8* @htons(i32 0)
%16 = load %struct.iphdr*, %struct.iphdr** %6
%17 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %16, i32 0, i32 8
store i8* %15, i8** %17
%18 = call i8* @htons(i32 16384)
%19 = load %struct.iphdr*, %struct.iphdr** %6
%20 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %19, i32 0, i32 7
store i8* %18, i8** %20
%21 = load %struct.iphdr*, %struct.iphdr** %6
%22 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %21, i32 0, i32 3
store i32 1, i32* %22
%23 = load i32, i32* @IPPROTO_IGMP
%24 = load %struct.iphdr*, %struct.iphdr** %6
%25 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %24, i32 0, i32 6
store i32 %23, i32* %25
%26 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
%27 = load i32, i32* %26
%28 = load %struct.iphdr*, %struct.iphdr** %6
%29 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %28, i32 0, i32 5
store i32 %27, i32* %29
%30 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i32 0, i32 0
%31 = load i32, i32* %30
%32 = load %struct.iphdr*, %struct.iphdr** %6
%33 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %32, i32 0, i32 4
store i32 %31, i32* %33
ret void
}

LLVM IR (-O2):
%struct.iphdr = type { i32, i32, i32, i32, i32, i32, i32, i8*, i8* }
@IPPROTO_IGMP = global i32 0
define void @ip_header_init(%struct.iphdr* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 0
store i32 4, i32* %4
%5 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 1
store i32 6, i32* %5
%6 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 2
store i32 192, i32* %6
%7 = tail call i8* @htons(i32 0)
%8 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 8
store i8* %7, i8** %8
%9 = tail call i8* @htons(i32 16384)
%10 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 7
store i8* %9, i8** %10
%11 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 3
store i32 1, i32* %11
%12 = load i32, i32* @IPPROTO_IGMP
%13 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 6
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 5
store i32 %1, i32* %14
%15 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %0, i64 0, i32 4
store i32 %2, i32* %15
ret void
}