#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 msghdr {
  int msg_iovlen;
  scalar_t__ msg_flags;
  scalar_t__ msg_controllen;
  int /*<<< orphan*/ *msg_control;
  struct iovec *msg_iov;
  scalar_t__ msg_namelen;
  int /*<<< orphan*/ *msg_name;
};
struct iovec {
  char *iov_base;
  scalar_t__ iov_len;
};

/* Variables and functions */
int sendmsg(int, struct msghdr *, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int sendmsg_to_client(int s, char *ms) {
  struct msghdr msg;
  struct iovec iov;
  int sl;
  iov.iov_base = ms;
  iov.iov_len = strlen(ms) + 1;
  msg.msg_name = NULL;
  msg.msg_namelen = 0;
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  msg.msg_control = NULL;
  msg.msg_controllen = 0;
  msg.msg_flags = 0;
  sl = sendmsg(s, &msg, 0);
  return sl;
}


x86 assembly (clang, -O0):
<sendmsg_to_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x58(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x48(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x48(%rbp),%rsi
xor    %edx,%edx
call   1030 <sendmsg@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendmsg_to_client>:
push   %rbx
sub    $0x50,%rsp
mov    %edi,%ebx
mov    %rsi,0x8(%rsp)
mov    %rsi,%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,0x10(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x40(%rsp)
lea    0x8(%rsp),%rax
mov    %rax,0x38(%rsp)
movl   $0x1,0x18(%rsp)
movups %xmm0,0x20(%rsp)
movq   $0x0,0x30(%rsp)
lea    0x18(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sendmsg@plt>
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.msghdr = type { i32, i64, i64, i32*, %struct.iovec*, i64, i32* }
%struct.iovec = type { i8*, i64 }
define i32 @sendmsg_to_client(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.msghdr
%6 = alloca %struct.iovec
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i32 0, i32 0
store i8* %8, i8** %9
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %11, 1
%13 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i32 0, i32 1
store i64 %12, i64* %13
%14 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 6
store i32* null, i32** %14
%15 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 5
store i64 0, i64* %15
%16 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 4
store %struct.iovec* %6, %struct.iovec** %16
%17 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 0
store i32 1, i32* %17
%18 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 3
store i32* null, i32** %18
%19 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 2
store i64 0, i64* %19
%20 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i32 0, i32 1
store i64 0, i64* %20
%21 = load i32, i32* %3
%22 = call i32 @sendmsg(i32 %21, %struct.msghdr* %5, i32 0)
store i32 %22, i32* %7
%23 = load i32, i32* %7
ret i32 %23
}

LLVM IR (-O2):
%struct.msghdr = type { i32, i64, i64, i32*, %struct.iovec*, i64, i32* }
%struct.iovec = type { i8*, i64 }
define i32 @sendmsg_to_client(i32 %0, i8* %1) {
%3 = alloca %struct.msghdr
%4 = alloca %struct.iovec
%5 = bitcast %struct.msghdr* %3 to i8*
%6 = bitcast %struct.iovec* %4 to i8*
%7 = getelementptr inbounds %struct.iovec, %struct.iovec* %4, i64 0, i32 0
store i8* %1, i8** %7
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = add nsw i64 %8, 1
%10 = getelementptr inbounds %struct.iovec, %struct.iovec* %4, i64 0, i32 1
store i64 %9, i64* %10
%11 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 5
%12 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 4
%13 = bitcast i64* %11 to i8*
store %struct.iovec* %4, %struct.iovec** %12
%14 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 0
store i32 1, i32* %14
%15 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %3, i64 0, i32 1
%16 = bitcast i64* %15 to i8*
%17 = call i32 @sendmsg(i32 %0, %struct.msghdr* %3, i32 0)
ret i32 %17
}