#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*/ cgc_memcpy(unsigned char *, unsigned char *, unsigned int);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(unsigned int);
int /*<<< orphan*/ session_send(void *, unsigned int, unsigned char *);
void send_data(void *channel, unsigned int type, unsigned int length,
               unsigned char *data) {
  unsigned char *hdrdata = malloc(length + 1);
  hdrdata[0] = (10 << 4) | type;
  cgc_memcpy(&hdrdata[1], data, length);
  session_send(channel, length + 1, hdrdata);
  free(hdrdata);
}


x86 assembly (clang, -O0):
<send_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
or     $0xa0,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1060 <cgc_memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    -0x20(%rbp),%rdx
call   1040 <session_send@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%r13d
mov    %esi,%ebp
mov    %rdi,%r15
lea    0x1(%r13),%r12d
mov    %r12d,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
or     $0xa0,%bpl
mov    %bpl,(%rax)
lea    0x1(%rax),%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1060 <cgc_memcpy@plt>
mov    %r15,%rdi
mov    %r12d,%esi
mov    %rbx,%rdx
call   1040 <session_send@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @send_data(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = load i32, i32* %7
%11 = add i32 %10, 1
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %9
%13 = load i32, i32* %6
%14 = or i32 160, %13
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %9
%17 = getelementptr inbounds i8, i8* %16, i64 0
store i8 %15, i8* %17
%18 = load i8*, i8** %9
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8*, i8** %8
%21 = load i32, i32* %7
%22 = call i32 @cgc_memcpy(i8* %19, i8* %20, i32 %21)
%23 = load i8*, i8** %5
%24 = load i32, i32* %7
%25 = add i32 %24, 1
%26 = load i8*, i8** %9
%27 = call i32 @session_send(i8* %23, i32 %25, i8* %26)
%28 = load i8*, i8** %9
%29 = call i32 @free(i8* %28)
ret void
}

LLVM IR (-O2):
define void @send_data(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = add i32 %2, 1
%6 = tail call i8* @malloc(i32 %5)
%7 = trunc i32 %1 to i8
%8 = or i8 %7, -96
store i8 %8, i8* %6
%9 = getelementptr inbounds i8, i8* %6, i64 1
%10 = tail call i32 @cgc_memcpy(i8* %9, i8* %3, i32 %2)
%11 = tail call i32 @session_send(i8* %0, i32 %5, i8* %6)
%12 = tail call i32 @free(i8* %6)
ret void
}