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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ SOCK_DGRAM;
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
size_t sendmsg(int, struct msghdr *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int fd;
  struct sockaddr_in sa;
  struct msghdr msg;
  struct iovec iov[2];
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (fd == -1) {
    perror("socket()");
    exit(EXIT_FAILURE);
  }
  sa.sin_family = AF_INET;
  sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  sa.sin_port = htons(12345);
  if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
    perror("connect ()");
    exit(EXIT_FAILURE);
  }
  msg.msg_namelen = 0;
  iov[0].iov_base = "one";
  iov[0].iov_len = 3;
  iov[1].iov_base = "two";
  iov[1].iov_len = 3;
  msg.msg_iov = &iov[0];
  msg.msg_iovlen = 2;
  msg.msg_control = NULL;
  msg.msg_controllen = 0;
  size_t s = sendmsg(fd, &msg, 0);
  msg.msg_name = NULL;
  fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (fd == -1) {
    perror("socket()");
    exit(EXIT_FAILURE);
  }
  if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
    perror("connect ()");
    exit(EXIT_FAILURE);
  }
  s = sendmsg(fd, &msg, 0);
  if (s == -1) {
    perror("sendmsg ()");
    exit(EXIT_FAILURE);
  } else
    fprintf(stderr, "sendmsg: %d\n", (int)s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11d9 <main+0x59>
lea    0xe3a(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x3039,%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
jne    1237 <main+0xb7>
lea    0xde5(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movq   $0x0,-0x28(%rbp)
lea    0xdce(%rip),%rax
mov    %rax,-0x70(%rbp)
movl   $0x3,-0x68(%rbp)
lea    0xdc0(%rip),%rax
mov    %rax,-0x60(%rbp)
movl   $0x3,-0x58(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x2,-0x50(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
xor    %edx,%edx
call   1030 <sendmsg@plt>
mov    %rax,-0x78(%rbp)
movq   $0x0,-0x48(%rbp)
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
mov    0x2d34(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12dc <main+0x15c>
lea    0xd37(%rip),%rdi
call   1070 <perror@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
jne    1310 <main+0x190>
lea    0xd0c(%rip),%rdi
call   1070 <perror@plt>
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
xor    %edx,%edx
call   1030 <sendmsg@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0xffffffffffffffff,-0x78(%rbp)
jne    1347 <main+0x1c7>
lea    0xce8(%rip),%rdi
call   1070 <perror@plt>
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2c7a(%rip),%rax
mov    (%rax),%edi
mov    -0x78(%rbp),%rax
mov    %eax,%edx
lea    0xcca(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    0x2e58(%rip),%r14
mov    (%r14),%edi
mov    0x2e46(%rip),%r15
mov    (%r15),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     12ae <main+0x12e>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    $0x3039,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
je     12b7 <main+0x137>
movq   $0x0,0x58(%rsp)
lea    0xe17(%rip),%rax
mov    %rax,0x10(%rsp)
movl   $0x3,0x18(%rsp)
lea    0xe07(%rip),%rax
mov    %rax,0x20(%rsp)
movl   $0x3,0x28(%rsp)
lea    0x10(%rsp),%rax
mov    %rax,0x50(%rsp)
movl   $0x2,0x30(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x40(%rsp)
lea    0x30(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sendmsg@plt>
movq   $0x0,0x38(%rsp)
mov    (%r14),%edi
mov    (%r15),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     12ae <main+0x12e>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
je     12b7 <main+0x137>
lea    0x30(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sendmsg@plt>
cmp    $0xffffffffffffffff,%rax
je     12c0 <main+0x140>
mov    0x2d36(%rip),%rcx
mov    (%rcx),%edi
lea    0xd8c(%rip),%rsi
mov    %eax,%edx
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd4b(%rip),%rdi
jmp    12c7 <main+0x147>
lea    0xd4b(%rip),%rdi
jmp    12c7 <main+0x147>
lea    0xd55(%rip),%rdi
call   1070 <perror@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.msghdr = type { i32, i32*, i64, i32*, %struct.iovec*, i64 }
%struct.iovec = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [9 x i8] c"socket()\00"
@EXIT_FAILURE = global i32 0
@INADDR_LOOPBACK = global i32 0
@.str.1 = [11 x i8] c"connect ()\00"
@.str.2 = [4 x i8] c"one\00"
@.str.3 = [4 x i8] c"two\00"
@.str.4 = [11 x i8] c"sendmsg ()\00"
@stderr = global i32 0
@.str.5 = [13 x i8] c"sendmsg: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.msghdr
%9 = alloca [2 x %struct.iovec]
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_LOOPBACK
%24 = call i32 @htonl(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = call i32 @htons(i32 12345)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* %6
%30 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%31 = call i32 @connect(i32 %29, %struct.sockaddr* %30, i32 12)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %20
%34 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %20
%38 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 5
store i64 0, i64* %38
%39 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %9, i64 0, i64 0
%40 = getelementptr inbounds %struct.iovec, %struct.iovec* %39, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %40
%41 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %9, i64 0, i64 0
%42 = getelementptr inbounds %struct.iovec, %struct.iovec* %41, i32 0, i32 1
store i32 3, i32* %42
%43 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %9, i64 0, i64 1
%44 = getelementptr inbounds %struct.iovec, %struct.iovec* %43, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %44
%45 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %9, i64 0, i64 1
%46 = getelementptr inbounds %struct.iovec, %struct.iovec* %45, i32 0, i32 1
store i32 3, i32* %46
%47 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %9, i64 0, i64 0
%48 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 4
store %struct.iovec* %47, %struct.iovec** %48
%49 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 0
store i32 2, i32* %49
%50 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 3
store i32* null, i32** %50
%51 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 2
store i64 0, i64* %51
%52 = load i32, i32* %6
%53 = call i64 @sendmsg(i32 %52, %struct.msghdr* %8, i32 0)
store i64 %53, i64* %10
%54 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 1
store i32* null, i32** %54
%55 = load i32, i32* @AF_INET
%56 = load i32, i32* @SOCK_DGRAM
%57 = call i32 @socket(i32 %55, i32 %56, i32 0)
store i32 %57, i32* %6
%58 = load i32, i32* %6
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %37
%61 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %37
%65 = load i32, i32* %6
%66 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%67 = call i32 @connect(i32 %65, %struct.sockaddr* %66, i32 12)
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %73
69: ; preds = %64
%70 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %64
%74 = load i32, i32* %6
%75 = call i64 @sendmsg(i32 %74, %struct.msghdr* %8, i32 0)
store i64 %75, i64* %10
%76 = load i64, i64* %10
%77 = icmp eq i64 %76, -1
br i1 %77, label %78, label %82
78: ; preds = %73
%79 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%80 = load i32, i32* @EXIT_FAILURE
%81 = call i32 @exit(i32 %80)
unreachable
82: ; preds = %73
%83 = load i32, i32* @stderr
%84 = load i64, i64* %10
%85 = trunc i64 %84 to i32
%86 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %85)
br label %87
87: ; preds = %82
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.msghdr = type { i32, i32*, i64, i32*, %struct.iovec*, i64 }
%struct.iovec = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [9 x i8] c"socket()\00"
@EXIT_FAILURE = global i32 0
@INADDR_LOOPBACK = global i32 0
@.str.1 = [11 x i8] c"connect ()\00"
@.str.2 = [4 x i8] c"one\00"
@.str.3 = [4 x i8] c"two\00"
@.str.4 = [11 x i8] c"sendmsg ()\00"
@stderr = global i32 0
@.str.5 = [13 x i8] c"sendmsg: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.msghdr
%5 = alloca [2 x %struct.iovec]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast %struct.msghdr* %4 to i8*
%8 = bitcast [2 x %struct.iovec]* %5 to i8*
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %18, i32* %19
%20 = load i32, i32* @INADDR_LOOPBACK
%21 = tail call i32 @htonl(i32 %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %21, i32* %22
%23 = tail call i32 @htons(i32 12345)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i32 @connect(i32 %11, %struct.sockaddr* %25, i32 12)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %17
%29 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %17
%33 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 5
store i64 0, i64* %33
%34 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %5, i64 0, i64 0
%35 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %5, i64 0, i64 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %35
%36 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %5, i64 0, i64 0, i32 1
store i32 3, i32* %36
%37 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %5, i64 0, i64 1, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %37
%38 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %5, i64 0, i64 1, i32 1
store i32 3, i32* %38
%39 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 4
store %struct.iovec* %34, %struct.iovec** %39
%40 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 0
store i32 2, i32* %40
%41 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 2
%42 = bitcast i64* %41 to i8*
%43 = call i64 @sendmsg(i32 %11, %struct.msghdr* %4, i32 0)
%44 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 1
store i32* null, i32** %44
%45 = load i32, i32* @AF_INET
%46 = load i32, i32* @SOCK_DGRAM
%47 = call i32 @socket(i32 %45, i32 %46, i32 0)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %53
49: ; preds = %32
%50 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %32
%54 = call i32 @connect(i32 %47, %struct.sockaddr* %25, i32 12)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %60
56: ; preds = %53
%57 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %53
%61 = call i64 @sendmsg(i32 %47, %struct.msghdr* %4, i32 0)
%62 = icmp eq i64 %61, -1
br i1 %62, label %63, label %67
63: ; preds = %60
%64 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %60
%68 = load i32, i32* @stderr
%69 = trunc i64 %61 to i32
%70 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %69)
ret i32 0
}