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

/* Variables and functions */
scalar_t__ ComputeChecksum(unsigned char *, int);
int /*<<< orphan*/ IPPROTO_TCP;
void *htons(int);
void *inet_addr(char *);
scalar_t__ malloc(int);
struct iphdr *CreateIPHeader(char *src_ip, char *dst_ip) {
  struct iphdr *ip_header;
  ip_header = (struct iphdr *)malloc(sizeof(struct iphdr));
  ip_header->version = 4;
  ip_header->ihl = (sizeof(struct iphdr)) / 4;
  ip_header->tos = 0;
  ip_header->tot_len =
      htons(sizeof(struct iphdr) + sizeof(struct tcphdr) + 100);
  ip_header->id = htons(111);
  ip_header->frag_off = 0;
  ip_header->ttl = 111;
  ip_header->protocol = IPPROTO_TCP;
  ip_header->check = 0;
  ip_header->saddr = inet_addr(src_ip);
  ip_header->daddr = inet_addr(dst_ip);
  ip_header->check =
      ComputeChecksum((unsigned char *)ip_header, ip_header->ihl * 4);
  return (ip_header);
}


x86 assembly (clang, -O0):
<CreateIPHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x50,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x14,0x4(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,0x48(%rax)
mov    $0xb8,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x40(%rax)
mov    $0x6f,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x38(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,0x30(%rax)
mov    -0x18(%rbp),%rax
movl   $0x6f,0x8(%rax)
mov    0x2e21(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x28(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
shl    $0x2,%esi
call   1060 <ComputeChecksum@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CreateIPHeader>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x50,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movabs $0x1400000004,%rax
mov    %rax,(%rbx)
movq   $0x0,0x48(%rbx)
mov    $0xb8,%edi
call   1030 <htons@plt>
mov    %rax,0x40(%rbx)
mov    $0x6f,%edi
call   1030 <htons@plt>
mov    %rax,0x38(%rbx)
movq   $0x0,0x30(%rbx)
movl   $0x6f,0x8(%rbx)
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rbx)
movq   $0x0,0x10(%rbx)
mov    %r15,%rdi
call   1040 <inet_addr@plt>
mov    %rax,0x20(%rbx)
mov    %r14,%rdi
call   1040 <inet_addr@plt>
mov    %rax,0x18(%rbx)
mov    0x4(%rbx),%esi
shl    $0x2,%esi
mov    %rbx,%rdi
call   1060 <ComputeChecksum@plt>
mov    %rax,0x10(%rbx)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.iphdr = type { i32, i32, i32, i64, i8*, i8*, i32, i64, i8*, i8*, i64 }
@IPPROTO_TCP = global i32 0
define %struct.iphdr* @CreateIPHeader(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.iphdr*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = call i64 @malloc(i32 80)
%7 = inttoptr i64 %6 to %struct.iphdr*
store %struct.iphdr* %7, %struct.iphdr** %5
%8 = load %struct.iphdr*, %struct.iphdr** %5
%9 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %8, i32 0, i32 0
store i32 4, i32* %9
%10 = load %struct.iphdr*, %struct.iphdr** %5
%11 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %10, i32 0, i32 1
store i32 20, i32* %11
%12 = load %struct.iphdr*, %struct.iphdr** %5
%13 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %12, i32 0, i32 10
store i64 0, i64* %13
%14 = call i8* @htons(i32 184)
%15 = load %struct.iphdr*, %struct.iphdr** %5
%16 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %15, i32 0, i32 9
store i8* %14, i8** %16
%17 = call i8* @htons(i32 111)
%18 = load %struct.iphdr*, %struct.iphdr** %5
%19 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %18, i32 0, i32 8
store i8* %17, i8** %19
%20 = load %struct.iphdr*, %struct.iphdr** %5
%21 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %20, i32 0, i32 7
store i64 0, i64* %21
%22 = load %struct.iphdr*, %struct.iphdr** %5
%23 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %22, i32 0, i32 2
store i32 111, i32* %23
%24 = load i32, i32* @IPPROTO_TCP
%25 = load %struct.iphdr*, %struct.iphdr** %5
%26 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %25, i32 0, i32 6
store i32 %24, i32* %26
%27 = load %struct.iphdr*, %struct.iphdr** %5
%28 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %27, i32 0, i32 3
store i64 0, i64* %28
%29 = load i8*, i8** %3
%30 = call i8* @inet_addr(i8* %29)
%31 = load %struct.iphdr*, %struct.iphdr** %5
%32 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %31, i32 0, i32 5
store i8* %30, i8** %32
%33 = load i8*, i8** %4
%34 = call i8* @inet_addr(i8* %33)
%35 = load %struct.iphdr*, %struct.iphdr** %5
%36 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %35, i32 0, i32 4
store i8* %34, i8** %36
%37 = load %struct.iphdr*, %struct.iphdr** %5
%38 = bitcast %struct.iphdr* %37 to i8*
%39 = load %struct.iphdr*, %struct.iphdr** %5
%40 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %39, i32 0, i32 1
%41 = load i32, i32* %40
%42 = mul nsw i32 %41, 4
%43 = call i64 @ComputeChecksum(i8* %38, i32 %42)
%44 = load %struct.iphdr*, %struct.iphdr** %5
%45 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %44, i32 0, i32 3
store i64 %43, i64* %45
%46 = load %struct.iphdr*, %struct.iphdr** %5
ret %struct.iphdr* %46
}

LLVM IR (-O2):
%struct.iphdr = type { i32, i32, i32, i64, i8*, i8*, i32, i64, i8*, i8*, i64 }
@IPPROTO_TCP = global i32 0
define %struct.iphdr* @CreateIPHeader(i8* %0, i8* %1) {
%3 = tail call i64 @malloc(i32 80)
%4 = inttoptr i64 %3 to %struct.iphdr*
%5 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 0
store i32 4, i32* %5
%6 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 1
store i32 20, i32* %6
%7 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 10
store i64 0, i64* %7
%8 = tail call i8* @htons(i32 184)
%9 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 9
store i8* %8, i8** %9
%10 = tail call i8* @htons(i32 111)
%11 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 8
store i8* %10, i8** %11
%12 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 7
store i64 0, i64* %12
%13 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 2
store i32 111, i32* %13
%14 = load i32, i32* @IPPROTO_TCP
%15 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 6
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 3
store i64 0, i64* %16
%17 = tail call i8* @inet_addr(i8* %0)
%18 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 5
store i8* %17, i8** %18
%19 = tail call i8* @inet_addr(i8* %1)
%20 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 4
store i8* %19, i8** %20
%21 = inttoptr i64 %3 to i8*
%22 = load i32, i32* %6
%23 = shl nsw i32 %22, 2
%24 = tail call i64 @ComputeChecksum(i8* %21, i32 %23)
store i64 %24, i64* %16
ret %struct.iphdr* %4
}