#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 doff;
  int syn;
  scalar_t__ urg_ptr;
  scalar_t__ check;
  void *window;
  scalar_t__ res1;
  void *ack_seq;
  void *seq;
  void *dest;
  void *source;
};

/* Variables and functions */
void *htonl(int);
void *htons(int);
scalar_t__ malloc(int);
struct tcphdr *CreateTcpHeader() {
  struct tcphdr *tcp_header;
  tcp_header = (struct tcphdr *)malloc(sizeof(struct tcphdr));
  tcp_header->source = htons(80);
  tcp_header->dest = htons(10000);
  tcp_header->seq = htonl(111);
  tcp_header->ack_seq = htonl(111);
  tcp_header->res1 = 0;
  tcp_header->doff = (sizeof(struct tcphdr)) / 4;
  tcp_header->syn = 1;
  tcp_header->window = htons(100);
  tcp_header->check = 0;
  tcp_header->urg_ptr = 0;
  return (tcp_header);
}


x86 assembly (clang, -O0):
<CreateTcpHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x48,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    $0x50,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x40(%rax)
mov    $0x2710,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x38(%rax)
mov    $0x6f,%edi
call   1040 <htonl@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x30(%rax)
mov    $0x6f,%edi
call   1040 <htonl@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x20(%rax)
mov    -0x8(%rbp),%rax
movl   $0x12,(%rax)
mov    -0x8(%rbp),%rax
movl   $0x1,0x4(%rax)
mov    $0x64,%edi
call   1030 <htons@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CreateTcpHeader>:
push   %rbx
mov    $0x48,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x50,%edi
call   1030 <htons@plt>
mov    %rax,0x40(%rbx)
mov    $0x2710,%edi
call   1030 <htons@plt>
mov    %rax,0x38(%rbx)
mov    $0x6f,%edi
call   1040 <htonl@plt>
mov    %rax,0x30(%rbx)
mov    $0x6f,%edi
call   1040 <htonl@plt>
mov    %rax,0x28(%rbx)
movq   $0x0,0x20(%rbx)
movabs $0x100000012,%rax
mov    %rax,(%rbx)
mov    $0x64,%edi
call   1030 <htons@plt>
mov    %rax,0x18(%rbx)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rbx)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.tcphdr = type { i32, i32, i64, i64, i8*, i64, i8*, i8*, i8*, i8* }
define %struct.tcphdr* @CreateTcpHeader() {
%1 = alloca %struct.tcphdr*
%2 = call i64 @malloc(i32 72)
%3 = inttoptr i64 %2 to %struct.tcphdr*
store %struct.tcphdr* %3, %struct.tcphdr** %1
%4 = call i8* @htons(i32 80)
%5 = load %struct.tcphdr*, %struct.tcphdr** %1
%6 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %5, i32 0, i32 9
store i8* %4, i8** %6
%7 = call i8* @htons(i32 10000)
%8 = load %struct.tcphdr*, %struct.tcphdr** %1
%9 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %8, i32 0, i32 8
store i8* %7, i8** %9
%10 = call i8* @htonl(i32 111)
%11 = load %struct.tcphdr*, %struct.tcphdr** %1
%12 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %11, i32 0, i32 7
store i8* %10, i8** %12
%13 = call i8* @htonl(i32 111)
%14 = load %struct.tcphdr*, %struct.tcphdr** %1
%15 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %14, i32 0, i32 6
store i8* %13, i8** %15
%16 = load %struct.tcphdr*, %struct.tcphdr** %1
%17 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %16, i32 0, i32 5
store i64 0, i64* %17
%18 = load %struct.tcphdr*, %struct.tcphdr** %1
%19 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %18, i32 0, i32 0
store i32 18, i32* %19
%20 = load %struct.tcphdr*, %struct.tcphdr** %1
%21 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %20, i32 0, i32 1
store i32 1, i32* %21
%22 = call i8* @htons(i32 100)
%23 = load %struct.tcphdr*, %struct.tcphdr** %1
%24 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %23, i32 0, i32 4
store i8* %22, i8** %24
%25 = load %struct.tcphdr*, %struct.tcphdr** %1
%26 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %25, i32 0, i32 3
store i64 0, i64* %26
%27 = load %struct.tcphdr*, %struct.tcphdr** %1
%28 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %27, i32 0, i32 2
store i64 0, i64* %28
%29 = load %struct.tcphdr*, %struct.tcphdr** %1
ret %struct.tcphdr* %29
}

LLVM IR (-O2):
%struct.tcphdr = type { i32, i32, i64, i64, i8*, i64, i8*, i8*, i8*, i8* }
define %struct.tcphdr* @CreateTcpHeader() {
%1 = tail call i64 @malloc(i32 72)
%2 = inttoptr i64 %1 to %struct.tcphdr*
%3 = tail call i8* @htons(i32 80)
%4 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %2, i64 0, i32 9
store i8* %3, i8** %4
%5 = tail call i8* @htons(i32 10000)
%6 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %2, i64 0, i32 8
store i8* %5, i8** %6
%7 = tail call i8* @htonl(i32 111)
%8 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %2, i64 0, i32 7
store i8* %7, i8** %8
%9 = tail call i8* @htonl(i32 111)
%10 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %2, i64 0, i32 6
store i8* %9, i8** %10
%11 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %2, i64 0, i32 5
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %2, i64 0, i32 0
store i32 18, i32* %12
%13 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %2, i64 0, i32 1
store i32 1, i32* %13
%14 = tail call i8* @htons(i32 100)
%15 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %2, i64 0, i32 4
store i8* %14, i8** %15
%16 = getelementptr inbounds %struct.tcphdr, %struct.tcphdr* %2, i64 0, i32 2
%17 = bitcast i64* %16 to i8*
ret %struct.tcphdr* %2
}