#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 sockaddr {
  int dummy;
};
struct msghdr {
  int msg_iovlen;
  int /*<<< orphan*/ msg_namelen;
  scalar_t__ msg_name;
  TYPE_1__ *msg_iov;
};
typedef int /*<<< orphan*/ ssize_t;
struct TYPE_2__ {
  int /*<<< orphan*/ iov_len;
  int /*<<< orphan*/ iov_base;
};

/* Variables and functions */
int /*<<< orphan*/ real_sendmsg(int, struct msghdr const *, int);
int /*<<< orphan*/ sendto(int, int /*<<< orphan*/, int /*<<< orphan*/, int,
                          struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ warn(char *);
ssize_t sendmsg(int fd, const struct msghdr *msg, int flags) {
  if (msg->msg_iovlen == 1) {
    return sendto(fd, msg->msg_iov[0].iov_base, msg->msg_iov[0].iov_len, flags,
                  (struct sockaddr *)msg->msg_name, msg->msg_namelen);
  } else {
    warn("Routing sendmsg to socket (too many buffers)");
    return real_sendmsg(fd, msg, flags);
  }
}


x86 assembly (clang, -O0):
<sendmsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jne    1187 <sendmsg+0x57>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    0x4(%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%edx
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%r9d
call   1040 <sendto@plt>
mov    %eax,-0x4(%rbp)
jmp    11a5 <sendmsg+0x75>
lea    0xe72(%rip),%rdi
call   1030 <warn@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <real_sendmsg@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendmsg>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
cmpl   $0x1,(%rsi)
jne    1160 <sendmsg+0x30>
mov    0x10(%rbx),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    0x8(%rbx),%r8
mov    0x4(%rbx),%r9d
mov    %ebp,%edi
mov    %r14d,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <sendto@plt>
lea    0xe99(%rip),%rdi
call   1030 <warn@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <real_sendmsg@plt>

LLVM IR (-O0):
%struct.msghdr = type { i32, i32, i64, %struct.TYPE_2__* }
%struct.TYPE_2__ = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [45 x i8] c"Routing sendmsg to socket (too many buffers)\00"
define i32 @sendmsg(i32 %0, %struct.msghdr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.msghdr*
%7 = alloca i32
store i32 %0, i32* %5
store %struct.msghdr* %1, %struct.msghdr** %6
store i32 %2, i32* %7
%8 = load %struct.msghdr*, %struct.msghdr** %6
%9 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %35
12: ; preds = %3
%13 = load i32, i32* %5
%14 = load %struct.msghdr*, %struct.msghdr** %6
%15 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %14, i32 0, i32 3
%16 = load %struct.TYPE_2__*, %struct.TYPE_2__** %15
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i64 0
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load %struct.msghdr*, %struct.msghdr** %6
%21 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %20, i32 0, i32 3
%22 = load %struct.TYPE_2__*, %struct.TYPE_2__** %21
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i64 0
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = load i32, i32* %7
%27 = load %struct.msghdr*, %struct.msghdr** %6
%28 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %27, i32 0, i32 2
%29 = load i64, i64* %28
%30 = inttoptr i64 %29 to %struct.sockaddr*
%31 = load %struct.msghdr*, %struct.msghdr** %6
%32 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %31, i32 0, i32 1
%33 = load i32, i32* %32
%34 = call i32 @sendto(i32 %13, i32 %19, i32 %25, i32 %26, %struct.sockaddr* %30, i32 %33)
store i32 %34, i32* %4
br label %41
35: ; preds = %3
%36 = call i32 @warn(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%37 = load i32, i32* %5
%38 = load %struct.msghdr*, %struct.msghdr** %6
%39 = load i32, i32* %7
%40 = call i32 @real_sendmsg(i32 %37, %struct.msghdr* %38, i32 %39)
store i32 %40, i32* %4
br label %41
41: ; preds = %35, %12
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
%struct.msghdr = type { i32, i32, i64, %struct.TYPE_2__* }
%struct.TYPE_2__ = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [45 x i8] c"Routing sendmsg to socket (too many buffers)\00"
define i32 @sendmsg(i32 %0, %struct.msghdr* %1, i32 %2) {
%4 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %20
7: ; preds = %3
%8 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %1, i64 0, i32 3
%9 = load %struct.TYPE_2__*, %struct.TYPE_2__** %8
%10 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %9, i64 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %9, i64 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %1, i64 0, i32 2
%15 = load i64, i64* %14
%16 = inttoptr i64 %15 to %struct.sockaddr*
%17 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %1, i64 0, i32 1
%18 = load i32, i32* %17
%19 = tail call i32 @sendto(i32 %0, i32 %11, i32 %13, i32 %2, %struct.sockaddr* %16, i32 %18)
br label %23
20: ; preds = %3
%21 = tail call i32 @warn(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%22 = tail call i32 @real_sendmsg(i32 %0, %struct.msghdr* %1, i32 %2)
br label %23
23: ; preds = %20, %7
%24 = phi i32 [ %19, %7 ], [ %22, %20 ]
ret i32 %24
}