#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 matlab_buffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ensure_buffer(struct matlab_buffer *, size_t);
unsigned int lookup_size(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, void *, size_t);
unsigned int place_matrix_header(struct matlab_buffer *, char const *, int,
                                 int /*<<< orphan*/ *, int, int, unsigned int);
void place_matlab_vector(struct matlab_buffer *buffer, const char *name,
                         int data_type, void *data,
                         unsigned int vector_length) {
  size_t data_length = lookup_size(data_type) * vector_length;
  unsigned int padding =
      place_matrix_header(buffer, name, data_type, NULL, 2, 1, vector_length);
  memcpy(ensure_buffer(buffer, data_length + padding), data, data_length);
}


x86 assembly (clang, -O0):
<place_matlab_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <lookup_size@plt>
imul   -0x24(%rbp),%eax
mov    %eax,%eax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x24(%rbp),%eax
xor    %ecx,%ecx
mov    $0x2,%r8d
mov    $0x1,%r9d
mov    %eax,(%rsp)
call   1050 <place_matrix_header@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%eax
add    %rax,%rsi
call   1040 <ensure_buffer@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <memcpy@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<place_matlab_vector>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%ebp
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%r13
mov    %edx,%edi
call   1060 <lookup_size@plt>
mov    %eax,%ebx
imul   %ebp,%ebx
mov    %ebp,(%rsp)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
mov    $0x2,%r8d
mov    $0x1,%r9d
call   1050 <place_matrix_header@plt>
mov    %eax,%esi
add    %rbx,%rsi
mov    %r13,%rdi
call   1040 <ensure_buffer@plt>
mov    %eax,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <memcpy@plt>

LLVM IR (-O0):
%struct.matlab_buffer = type { i32 }
define void @place_matlab_vector(%struct.matlab_buffer* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca %struct.matlab_buffer*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
store %struct.matlab_buffer* %0, %struct.matlab_buffer** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%13 = load i32, i32* %8
%14 = call i32 @lookup_size(i32 %13)
%15 = load i32, i32* %10
%16 = mul i32 %14, %15
%17 = zext i32 %16 to i64
store i64 %17, i64* %11
%18 = load %struct.matlab_buffer*, %struct.matlab_buffer** %6
%19 = load i8*, i8** %7
%20 = load i32, i32* %8
%21 = load i32, i32* %10
%22 = call i32 @place_matrix_header(%struct.matlab_buffer* %18, i8* %19, i32 %20, i32* null, i32 2, i32 1, i32 %21)
store i32 %22, i32* %12
%23 = load %struct.matlab_buffer*, %struct.matlab_buffer** %6
%24 = load i64, i64* %11
%25 = load i32, i32* %12
%26 = zext i32 %25 to i64
%27 = add i64 %24, %26
%28 = call i32 @ensure_buffer(%struct.matlab_buffer* %23, i64 %27)
%29 = load i8*, i8** %9
%30 = load i64, i64* %11
%31 = call i32 @memcpy(i32 %28, i8* %29, i64 %30)
ret void
}

LLVM IR (-O2):
%struct.matlab_buffer = type { i32 }
define void @place_matlab_vector(%struct.matlab_buffer* %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = tail call i32 @lookup_size(i32 %2)
%7 = mul i32 %6, %4
%8 = zext i32 %7 to i64
%9 = tail call i32 @place_matrix_header(%struct.matlab_buffer* %0, i8* %1, i32 %2, i32* null, i32 2, i32 1, i32 %4)
%10 = zext i32 %9 to i64
%11 = add nuw nsw i64 %8, %10
%12 = tail call i32 @ensure_buffer(%struct.matlab_buffer* %0, i64 %11)
%13 = tail call i32 @memcpy(i32 %12, i8* %3, i64 %8)
ret void
}