#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_recvmsg(int, struct msghdr *, int);
int /*<<< orphan*/ recvfrom(int, int /*<<< orphan*/, int /*<<< orphan*/, int,
                            struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ warn(char *);
ssize_t recvmsg(int fd, struct msghdr *msg, int flags) {
  if (msg->msg_iovlen == 1) {
    return recvfrom(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 recvmsg to socket (too many buffers)");
    return real_recvmsg(fd, msg, flags);
  }
}


x86 assembly (clang, -O0):
<recvmsg>:
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 <recvmsg+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),%r9
add    $0x4,%r9
call   1050 <recvfrom@plt>
mov    %eax,-0x4(%rbp)
jmp    11a5 <recvmsg+0x75>
lea    0xe72(%rip),%rdi
call   1030 <warn@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <real_recvmsg@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recvmsg>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
cmpl   $0x1,(%rsi)
jne    1163 <recvmsg+0x33>
mov    0x8(%rbx),%r8
mov    0x10(%rbx),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
add    $0x4,%rbx
mov    %ebp,%edi
mov    %r14d,%ecx
mov    %rbx,%r9
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <recvfrom@plt>
lea    0xe96(%rip),%rdi
call   1030 <warn@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <real_recvmsg@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 recvmsg to socket (too many buffers)\00"
define i32 @recvmsg(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 %34
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 = call i32 @recvfrom(i32 %13, i32 %19, i32 %25, i32 %26, %struct.sockaddr* %30, i32* %32)
store i32 %33, i32* %4
br label %40
34: ; preds = %3
%35 = call i32 @warn(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%36 = load i32, i32* %5
%37 = load %struct.msghdr*, %struct.msghdr** %6
%38 = load i32, i32* %7
%39 = call i32 @real_recvmsg(i32 %36, %struct.msghdr* %37, i32 %38)
store i32 %39, i32* %4
br label %40
40: ; preds = %34, %12
%41 = load i32, i32* %4
ret i32 %41
}

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 recvmsg to socket (too many buffers)\00"
define i32 @recvmsg(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 %19
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 = tail call i32 @recvfrom(i32 %0, i32 %11, i32 %13, i32 %2, %struct.sockaddr* %16, i32* %17)
br label %22
19: ; preds = %3
%20 = tail call i32 @warn(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%21 = tail call i32 @real_recvmsg(i32 %0, %struct.msghdr* %1, i32 %2)
br label %22
22: ; preds = %19, %7
%23 = phi i32 [ %18, %7 ], [ %21, %19 ]
ret i32 %23
}