#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*/ free(unsigned char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ mapif_sendall(unsigned char *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int mapif_GMmessage(unsigned char *mes, int len) {
  unsigned char *buf = (unsigned char *)malloc(len);
  (*(unsigned short *)(((unsigned char *)((buf))) + ((0)))) = 0x3800;
  (*(unsigned short *)(((unsigned char *)((buf))) + ((2)))) = len;
  memcpy((((unsigned char *)(buf)) + (4)), mes, len - 4);
  mapif_sendall(buf, len);
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<mapif_GMmessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movw   $0x3800,(%rax)
mov    -0xc(%rbp),%eax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,0x2(%rax)
mov    -0x18(%rbp),%rdi
add    $0x4,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
sub    $0x4,%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <mapif_sendall@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapif_GMmessage>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%r15d
mov    %rdi,%r14
mov    %esi,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movw   $0x3800,(%rax)
mov    %r15w,0x2(%rax)
lea    0x4(%rax),%rdi
lea    -0x4(%r15),%edx
mov    %r14,%rsi
call   1050 <memcpy@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <mapif_sendall@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @mapif_GMmessage(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = bitcast i8* %10 to i16*
store i16 14336, i16* %11
%12 = load i32, i32* %4
%13 = trunc i32 %12 to i16
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 2
%16 = bitcast i8* %15 to i16*
store i16 %13, i16* %16
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 4
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 4
%22 = call i32 @memcpy(i8* %18, i8* %19, i32 %21)
%23 = load i8*, i8** %5
%24 = load i32, i32* %4
%25 = call i32 @mapif_sendall(i8* %23, i32 %24)
%26 = load i8*, i8** %5
%27 = call i32 @free(i8* %26)
ret i32 0
}

LLVM IR (-O2):
define i32 @mapif_GMmessage(i8* %0, i32 %1) {
%3 = tail call i64 @malloc(i32 %1)
%4 = inttoptr i64 %3 to i8*
%5 = inttoptr i64 %3 to i16*
store i16 14336, i16* %5
%6 = trunc i32 %1 to i16
%7 = getelementptr inbounds i8, i8* %4, i64 2
%8 = bitcast i8* %7 to i16*
store i16 %6, i16* %8
%9 = getelementptr inbounds i8, i8* %4, i64 4
%10 = add nsw i32 %1, -4
%11 = tail call i32 @memcpy(i8* %9, i8* %0, i32 %10)
%12 = tail call i32 @mapif_sendall(i8* %4, i32 %1)
%13 = tail call i32 @free(i8* %4)
ret i32 0
}