#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct msghdr {
  int msg_namelen;
  int msg_iovlen;
  scalar_t__ msg_flags;
  scalar_t__ msg_controllen;
  scalar_t__ msg_control;
  struct iovec *msg_iov;
  struct sockaddr_in *msg_name;
};
struct iovec {
  char *iov_base;
  int iov_len;
};
typedef int /*<<< orphan*/ receiver_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int sendmsg(int, struct msghdr *, int /*<<< orphan*/);
int send_sock_msg(int sock_fd) {
  struct sockaddr_in receiver_addr;
  char line[15] = "Hello World!";
  struct msghdr msg;
  struct iovec iov;
  receiver_addr.sin_family = AF_INET;
  receiver_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  receiver_addr.sin_port = htons(8000);
  msg.msg_name = &receiver_addr;
  msg.msg_namelen = sizeof(receiver_addr);
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  msg.msg_iov->iov_base = line;
  msg.msg_iov->iov_len = 13;
  msg.msg_control = 0;
  msg.msg_controllen = 0;
  msg.msg_flags = 0;
  return sendmsg(sock_fd, &msg, 0);
}


x86 assembly (clang, -O0):
<send_sock_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x1f(%rbp)
mov    0xebc(%rip),%eax
mov    %eax,-0x17(%rbp)
mov    0xeb6(%rip),%ax
mov    %ax,-0x13(%rbp)
mov    0xeae(%rip),%al
mov    %al,-0x11(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0xc(%rbp)
mov    $0x1f40,%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0xc,-0x50(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x4c(%rbp)
lea    -0x1f(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
movl   $0xd,0x8(%rax)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
xor    %edx,%edx
call   1030 <sendmsg@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_sock_msg>:
push   %rbx
sub    $0x60,%rsp
mov    %edi,%ebx
movabs $0x21646c726f,%rax
mov    %rax,0x17(%rsp)
movabs $0x6f57206f6c6c6548,%rax
20 57 6f
mov    %rax,0x10(%rsp)
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    $0x1f40,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rax
mov    %rax,0x58(%rsp)
movabs $0x10000000c,%rax
mov    %rax,0x30(%rsp)
lea    0x20(%rsp),%rax
mov    %rax,0x50(%rsp)
lea    0x10(%rsp),%rax
mov    %rax,0x20(%rsp)
movl   $0xd,0x28(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x38(%rsp)
movq   $0x0,0x48(%rsp)
lea    0x30(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sendmsg@plt>
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.msghdr = type { i32, i32, i64, i64, i64, %struct.iovec*, %struct.sockaddr_in* }
%struct.iovec = type { i8*, i32 }
@__const.send_sock_msg.line = [15 x i8] c"Hello World!\00\00\00"
@AF_INET = global i32 0
@INADDR_LOOPBACK = global i32 0
define i32 @send_sock_msg(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [15 x i8]
%5 = alloca %struct.msghdr
%6 = alloca %struct.iovec
store i32 %0, i32* %2
%7 = bitcast [15 x i8]* %4 to i8*
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %8, i32* %9
%10 = load i32, i32* @INADDR_LOOPBACK
%11 = call i32 @htonl(i32 %10)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
store i32 %11, i32* %13
%14 = call i32 @htons(i32 8000)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 6
store %struct.sockaddr_in* %3, %struct.sockaddr_in** %16
%17 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 0
store i32 12, i32* %17
%18 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 5
store %struct.iovec* %6, %struct.iovec** %18
%19 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 1
store i32 1, i32* %19
%20 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%21 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 5
%22 = load %struct.iovec*, %struct.iovec** %21
%23 = getelementptr inbounds %struct.iovec, %struct.iovec* %22, i32 0, i32 0
store i8* %20, i8** %23
%24 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 5
%25 = load %struct.iovec*, %struct.iovec** %24
%26 = getelementptr inbounds %struct.iovec, %struct.iovec* %25, i32 0, i32 1
store i32 13, i32* %26
%27 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 4
store i64 0, i64* %27
%28 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 3
store i64 0, i64* %28
%29 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 2
store i64 0, i64* %29
%30 = load i32, i32* %2
%31 = call i32 @sendmsg(i32 %30, %struct.msghdr* %5, i32 0)
ret i32 %31
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.msghdr = type { i32, i32, i64, i64, i64, %struct.iovec*, %struct.sockaddr_in* }
%struct.iovec = type { i8*, i32 }
@__const.send_sock_msg.line = [15 x i8] c"Hello World!\00\00\00"
@AF_INET = global i32 0
@INADDR_LOOPBACK = global i32 0
define i32 @send_sock_msg(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca [15 x i8]
%4 = alloca %struct.msghdr
%5 = alloca %struct.iovec
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%8 = bitcast %struct.msghdr* %4 to i8*
%9 = bitcast %struct.iovec* %5 to i8*
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %10, i32* %11
%12 = load i32, i32* @INADDR_LOOPBACK
%13 = tail call i32 @htonl(i32 %12)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %13, i32* %14
%15 = tail call i32 @htons(i32 8000)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 6
store %struct.sockaddr_in* %2, %struct.sockaddr_in** %17
%18 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 0
store i32 12, i32* %18
%19 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 5
store %struct.iovec* %5, %struct.iovec** %19
%20 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 1
store i32 1, i32* %20
%21 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i64 0, i32 0
store i8* %7, i8** %21
%22 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i64 0, i32 1
store i32 13, i32* %22
%23 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 2
%24 = bitcast i64* %23 to i8*
%25 = call i32 @sendmsg(i32 %0, %struct.msghdr* %4, i32 0)
ret i32 %25
}