#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 */

/* Variables and functions */
int /*<<< orphan*/ buf_htonl(void *, int);
int /*<<< orphan*/ free(void *);
void *malloc(int);
int /*<<< orphan*/ memcpy(void *, void *, int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int send(int, void *, int, int /*<<< orphan*/);
int idrnet_send_buf(int sockfd, void *data, int len) {
  void *buf_cpy = malloc(len);
  memset(buf_cpy, 0, len);
  memcpy(buf_cpy, data, len);
  buf_htonl(buf_cpy, len);
  int res = send(sockfd, buf_cpy, len, 0);
  free(buf_cpy);
  return res;
}


x86 assembly (clang, -O0):
<idrnet_send_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <buf_htonl@plt>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<idrnet_send_buf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%r15d
mov    %edx,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1060 <memset@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1070 <memcpy@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1030 <buf_htonl@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @idrnet_send_buf(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = load i32, i32* %6
%13 = call i32 @memset(i8* %11, i32 0, i32 %12)
%14 = load i8*, i8** %7
%15 = load i8*, i8** %5
%16 = load i32, i32* %6
%17 = call i32 @memcpy(i8* %14, i8* %15, i32 %16)
%18 = load i8*, i8** %7
%19 = load i32, i32* %6
%20 = call i32 @buf_htonl(i8* %18, i32 %19)
%21 = load i32, i32* %4
%22 = load i8*, i8** %7
%23 = load i32, i32* %6
%24 = call i32 @send(i32 %21, i8* %22, i32 %23, i32 0)
store i32 %24, i32* %8
%25 = load i8*, i8** %7
%26 = call i32 @free(i8* %25)
%27 = load i32, i32* %8
ret i32 %27
}

LLVM IR (-O2):
define i32 @idrnet_send_buf(i32 %0, i8* %1, i32 %2) {
%4 = tail call i8* @malloc(i32 %2)
%5 = tail call i32 @memset(i8* %4, i32 0, i32 %2)
%6 = tail call i32 @memcpy(i8* %4, i8* %1, i32 %2)
%7 = tail call i32 @buf_htonl(i8* %4, i32 %2)
%8 = tail call i32 @send(i32 %0, i8* %4, i32 %2, i32 0)
%9 = tail call i32 @free(i8* %4)
ret i32 %8
}