#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);
size_t 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);
void place_matlab_value(struct matlab_buffer *buffer, const char *name,
                        int data_type, void *data) {
  size_t data_size = lookup_size(data_type);
  unsigned int padding =
      place_matrix_header(buffer, name, data_type, NULL, 1, 1);
  memcpy(ensure_buffer(buffer, data_size + padding), data, data_size);
}


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

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

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

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