#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 sockaddr_tipc {
  int dummy;
};
struct msghdr {
  int msg_iovlen;
  int msg_namelen;
  int msg_controllen;
  void *msg_control;
  struct sockaddr_tipc *msg_name;
  struct msghdr *msg_iov;
};
struct iovec {
  int msg_iovlen;
  int msg_namelen;
  int msg_controllen;
  void *msg_control;
  struct sockaddr_tipc *msg_name;
  struct iovec *msg_iov;
};

/* Variables and functions */
int /*<<< orphan*/ memset(struct msghdr *, int /*<<< orphan*/, int);
void msghdr_create(struct msghdr *m, struct iovec *iov, int iovlen,
                   void *control_buf, int control_len,
                   struct sockaddr_tipc *saddr) {
  memset(m, 0, sizeof(struct msghdr));
  memset(iov, 0, sizeof(struct iovec) * iovlen);
  m->msg_iov = iov;
  m->msg_iovlen = iovlen;
  m->msg_name = saddr;
  m->msg_namelen = sizeof(struct sockaddr_tipc);
  m->msg_control = control_buf;
  m->msg_controllen = control_len;
}


x86 assembly (clang, -O0):
<msghdr_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
imul   $0x28,%rax,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x8(%rbp),%rax
movl   $0x4,0x4(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x24(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msghdr_create>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r15
mov    %r8d,%r14d
mov    %rcx,%r12
mov    %edx,%r13d
mov    %rsi,%rbp
mov    %rdi,%rbx
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
lea    0x0(,%r13,8),%eax
lea    (%rax,%rax,4),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    %rbp,0x20(%rbx)
mov    %r13d,(%rbx)
mov    %r15,0x18(%rbx)
movl   $0x4,0x4(%rbx)
mov    %r12,0x10(%rbx)
mov    %r14d,0x8(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.msghdr = type { i32, i32, i32, i8*, %struct.sockaddr_tipc*, %struct.msghdr* }
%struct.iovec = type { i32, i32, i32, i8*, %struct.sockaddr_tipc*, %struct.iovec* }
%struct.sockaddr_tipc = type { i32 }
define void @msghdr_create(%struct.msghdr* %0, %struct.iovec* %1, i32 %2, i8* %3, i32 %4, %struct.sockaddr_tipc* %5) {
%7 = alloca %struct.msghdr*
%8 = alloca %struct.iovec*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca %struct.sockaddr_tipc*
store %struct.msghdr* %0, %struct.msghdr** %7
store %struct.iovec* %1, %struct.iovec** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store %struct.sockaddr_tipc* %5, %struct.sockaddr_tipc** %12
%13 = load %struct.msghdr*, %struct.msghdr** %7
%14 = call i32 @memset(%struct.msghdr* %13, i32 0, i32 40)
%15 = load %struct.iovec*, %struct.iovec** %8
%16 = bitcast %struct.iovec* %15 to %struct.msghdr*
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = mul i64 40, %18
%20 = trunc i64 %19 to i32
%21 = call i32 @memset(%struct.msghdr* %16, i32 0, i32 %20)
%22 = load %struct.iovec*, %struct.iovec** %8
%23 = bitcast %struct.iovec* %22 to %struct.msghdr*
%24 = load %struct.msghdr*, %struct.msghdr** %7
%25 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %24, i32 0, i32 5
store %struct.msghdr* %23, %struct.msghdr** %25
%26 = load i32, i32* %9
%27 = load %struct.msghdr*, %struct.msghdr** %7
%28 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %27, i32 0, i32 0
store i32 %26, i32* %28
%29 = load %struct.sockaddr_tipc*, %struct.sockaddr_tipc** %12
%30 = load %struct.msghdr*, %struct.msghdr** %7
%31 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %30, i32 0, i32 4
store %struct.sockaddr_tipc* %29, %struct.sockaddr_tipc** %31
%32 = load %struct.msghdr*, %struct.msghdr** %7
%33 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %32, i32 0, i32 1
store i32 4, i32* %33
%34 = load i8*, i8** %10
%35 = load %struct.msghdr*, %struct.msghdr** %7
%36 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %35, i32 0, i32 3
store i8* %34, i8** %36
%37 = load i32, i32* %11
%38 = load %struct.msghdr*, %struct.msghdr** %7
%39 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %38, i32 0, i32 2
store i32 %37, i32* %39
ret void
}

LLVM IR (-O2):
%struct.msghdr = type { i32, i32, i32, i8*, %struct.sockaddr_tipc*, %struct.msghdr* }
%struct.iovec = type { i32, i32, i32, i8*, %struct.sockaddr_tipc*, %struct.iovec* }
%struct.sockaddr_tipc = type { i32 }
define void @msghdr_create(%struct.msghdr* %0, %struct.iovec* %1, i32 %2, i8* %3, i32 %4, %struct.sockaddr_tipc* %5) {
%7 = tail call i32 @memset(%struct.msghdr* %0, i32 0, i32 40)
%8 = bitcast %struct.iovec* %1 to %struct.msghdr*
%9 = mul i32 %2, 40
%10 = tail call i32 @memset(%struct.msghdr* %8, i32 0, i32 %9)
%11 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %0, i64 0, i32 5
%12 = bitcast %struct.msghdr** %11 to %struct.iovec**
store %struct.iovec* %1, %struct.iovec** %12
%13 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %0, i64 0, i32 0
store i32 %2, i32* %13
%14 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %0, i64 0, i32 4
store %struct.sockaddr_tipc* %5, %struct.sockaddr_tipc** %14
%15 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %0, i64 0, i32 1
store i32 4, i32* %15
%16 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %0, i64 0, i32 3
store i8* %3, i8** %16
%17 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %0, i64 0, i32 2
store i32 %4, i32* %17
ret void
}