#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 */
typedef int /*<<< orphan*/ uint8_t;
struct skynet_context {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ *malloc(size_t);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, void const *, size_t);
int /*<<< orphan*/ skynet_error(struct skynet_context *, char *, int);
scalar_t__ skynet_socket_send(struct skynet_context *, int,
                              int /*<<< orphan*/ *, size_t);
int /*<<< orphan*/ to_bigendian(int /*<<< orphan*/ *, size_t);
void _send_package(struct skynet_context *ctx, int fd, const void *buffer,
                   size_t sz) {
  uint8_t *sendbuf = malloc(sz + 4);
  to_bigendian(sendbuf, sz);
  memcpy(sendbuf + 4, buffer, sz);
  if (skynet_socket_send(ctx, fd, sendbuf, sz + 4)) {
    skynet_error(ctx, "Send to %d error", fd);
  }
}


x86 assembly (clang, -O0):
<_send_package>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x4,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <to_bigendian@plt>
mov    -0x28(%rbp),%rdi
add    $0x10,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
add    $0x4,%rcx
call   1070 <skynet_socket_send@plt>
cmp    $0x0,%rax
je     11cf <_send_package+0x7f>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe36(%rip),%rsi
call   1040 <skynet_error@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_send_package>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbp
mov    %rdx,%r12
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x4(%rcx),%r13
mov    %r13,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1060 <to_bigendian@plt>
lea    0x10(%rbx),%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1030 <memcpy@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
mov    %r13,%rcx
call   1070 <skynet_socket_send@plt>
test   %rax,%rax
je     11c6 <_send_package+0x76>
lea    0xe53(%rip),%rsi
mov    %r15,%rdi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <skynet_error@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.skynet_context = type { i32 }
@.str = [17 x i8] c"Send to %d error\00"
define void @_send_package(%struct.skynet_context* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca %struct.skynet_context*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
store %struct.skynet_context* %0, %struct.skynet_context** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%10 = load i64, i64* %8
%11 = add i64 %10, 4
%12 = call i32* @malloc(i64 %11)
store i32* %12, i32** %9
%13 = load i32*, i32** %9
%14 = load i64, i64* %8
%15 = call i32 @to_bigendian(i32* %13, i64 %14)
%16 = load i32*, i32** %9
%17 = getelementptr inbounds i32, i32* %16, i64 4
%18 = load i8*, i8** %7
%19 = load i64, i64* %8
%20 = call i32 @memcpy(i32* %17, i8* %18, i64 %19)
%21 = load %struct.skynet_context*, %struct.skynet_context** %5
%22 = load i32, i32* %6
%23 = load i32*, i32** %9
%24 = load i64, i64* %8
%25 = add i64 %24, 4
%26 = call i64 @skynet_socket_send(%struct.skynet_context* %21, i32 %22, i32* %23, i64 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %4
%29 = load %struct.skynet_context*, %struct.skynet_context** %5
%30 = load i32, i32* %6
%31 = call i32 @skynet_error(%struct.skynet_context* %29, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %28, %4
ret void
}

LLVM IR (-O2):
%struct.skynet_context = type { i32 }
@.str = [17 x i8] c"Send to %d error\00"
define void @_send_package(%struct.skynet_context* %0, i32 %1, i8* %2, i64 %3) {
%5 = add i64 %3, 4
%6 = tail call i32* @malloc(i64 %5)
%7 = tail call i32 @to_bigendian(i32* %6, i64 %3)
%8 = getelementptr inbounds i32, i32* %6, i64 4
%9 = tail call i32 @memcpy(i32* %8, i8* %2, i64 %3)
%10 = tail call i64 @skynet_socket_send(%struct.skynet_context* %0, i32 %1, i32* %6, i64 %5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %4
%13 = tail call i32 @skynet_error(%struct.skynet_context* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %14
14: ; preds = %12, %4
ret void
}