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

/* Variables and functions */
int /*<<< orphan*/ memset(struct msghdr *, int /*<<< orphan*/, int);
int recvmsg(int, struct msghdr *, int /*<<< orphan*/);
int ahcp_recv(int s, void *buf, int buflen, struct sockaddr *sin, int slen) {
  struct iovec iovec;
  struct msghdr msg;
  int rc;
  memset(&msg, 0, sizeof(msg));
  iovec.iov_base = buf;
  iovec.iov_len = buflen;
  msg.msg_name = sin;
  msg.msg_namelen = slen;
  msg.msg_iov = &iovec;
  msg.msg_iovlen = 1;
  rc = recvmsg(s, &msg, 0);
  return rc;
}


x86 assembly (clang, -O0):
<ahcp_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x50(%rbp)
lea    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
xor    %edx,%edx
call   1040 <recvmsg@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ahcp_recv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r12d
mov    %rsp,%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    %rbx,0x20(%rsp)
mov    %ebp,0x18(%rsp)
mov    %r15,0x10(%rsp)
mov    %r14d,(%rsp)
lea    0x18(%rsp),%rax
mov    %rax,0x8(%rsp)
movl   $0x1,0x4(%rsp)
mov    %r12d,%edi
mov    %r13,%rsi
xor    %edx,%edx
call   1040 <recvmsg@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.iovec = type { i32, i8* }
%struct.msghdr = type { i32, i32, %struct.iovec*, %struct.sockaddr* }
define i32 @ahcp_recv(i32 %0, i8* %1, i32 %2, %struct.sockaddr* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.sockaddr*
%10 = alloca i32
%11 = alloca %struct.iovec
%12 = alloca %struct.msghdr
%13 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store %struct.sockaddr* %3, %struct.sockaddr** %9
store i32 %4, i32* %10
%14 = call i32 @memset(%struct.msghdr* %12, i32 0, i32 24)
%15 = load i8*, i8** %7
%16 = getelementptr inbounds %struct.iovec, %struct.iovec* %11, i32 0, i32 1
store i8* %15, i8** %16
%17 = load i32, i32* %8
%18 = getelementptr inbounds %struct.iovec, %struct.iovec* %11, i32 0, i32 0
store i32 %17, i32* %18
%19 = load %struct.sockaddr*, %struct.sockaddr** %9
%20 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %12, i32 0, i32 3
store %struct.sockaddr* %19, %struct.sockaddr** %20
%21 = load i32, i32* %10
%22 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %12, i32 0, i32 0
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %12, i32 0, i32 2
store %struct.iovec* %11, %struct.iovec** %23
%24 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %12, i32 0, i32 1
store i32 1, i32* %24
%25 = load i32, i32* %6
%26 = call i32 @recvmsg(i32 %25, %struct.msghdr* %12, i32 0)
store i32 %26, i32* %13
%27 = load i32, i32* %13
ret i32 %27
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.iovec = type { i32, i8* }
%struct.msghdr = type { i32, i32, %struct.iovec*, %struct.sockaddr* }
define i32 @ahcp_recv(i32 %0, i8* %1, i32 %2, %struct.sockaddr* %3, i32 %4) {
%6 = alloca %struct.iovec
%7 = alloca %struct.msghdr
%8 = bitcast %struct.iovec* %6 to i8*
%9 = bitcast %struct.msghdr* %7 to i8*
%10 = call i32 @memset(%struct.msghdr* %7, i32 0, i32 24)
%11 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i64 0, i32 1
store i8* %1, i8** %11
%12 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i64 0, i32 0
store i32 %2, i32* %12
%13 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 3
store %struct.sockaddr* %3, %struct.sockaddr** %13
%14 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 0
store i32 %4, i32* %14
%15 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 2
store %struct.iovec* %6, %struct.iovec** %15
%16 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i64 0, i32 1
store i32 1, i32* %16
%17 = call i32 @recvmsg(i32 %0, %struct.msghdr* %7, i32 0)
ret i32 %17
}