#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 */
char *ensure_buffer(struct matlab_buffer *, int);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ memset(char *, char, int);
size_t strlen(char const *);
int /*<<< orphan*/ write_buffer_uint32(struct matlab_buffer *, int);
void prepare_matlab_header(struct matlab_buffer *buffer) {
  const char *description =
      "MATLAB 5.0 MAT-file generated from FA sniffer data";
  size_t l = strlen(description);
  char *mat_header = ensure_buffer(buffer, 124);
  memcpy(mat_header, description, l);
  memset(mat_header + l, ' ', 124 - l);
  write_buffer_uint32(buffer, 0x4d490100);
}


x86 assembly (clang, -O0):
<prepare_matlab_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x7c,%esi
call   1070 <ensure_buffer@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    $0x7c,%eax
sub    -0x18(%rbp),%rax
mov    %eax,%edx
mov    $0x20,%esi
call   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    $0x4d490100,%esi
call   1030 <write_buffer_uint32@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepare_matlab_header>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x7c,%esi
call   1060 <ensure_buffer@plt>
mov    %rax,%rbx
lea    0xea5(%rip),%rsi
mov    $0x32,%edx
mov    %rax,%rdi
call   1050 <memcpy@plt>
add    $0x32,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
mov    $0x4a,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    $0x4d490100,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <write_buffer_uint32@plt>

LLVM IR (-O0):
%struct.matlab_buffer = type { i32 }
@.str = [51 x i8] c"MATLAB 5.0 MAT-file generated from FA sniffer data\00"
define void @prepare_matlab_header(%struct.matlab_buffer* %0) {
%2 = alloca %struct.matlab_buffer*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store %struct.matlab_buffer* %0, %struct.matlab_buffer** %2
store i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %4
%8 = load %struct.matlab_buffer*, %struct.matlab_buffer** %2
%9 = call i8* @ensure_buffer(%struct.matlab_buffer* %8, i32 124)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = load i8*, i8** %3
%12 = load i64, i64* %4
%13 = call i32 @memcpy(i8* %10, i8* %11, i64 %12)
%14 = load i8*, i8** %5
%15 = load i64, i64* %4
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i64, i64* %4
%18 = sub i64 124, %17
%19 = trunc i64 %18 to i32
%20 = call i32 @memset(i8* %16, i8 signext 32, i32 %19)
%21 = load %struct.matlab_buffer*, %struct.matlab_buffer** %2
%22 = call i32 @write_buffer_uint32(%struct.matlab_buffer* %21, i32 1296630016)
ret void
}

LLVM IR (-O2):
%struct.matlab_buffer = type { i32 }
@.str = [51 x i8] c"MATLAB 5.0 MAT-file generated from FA sniffer data\00"
define void @prepare_matlab_header(%struct.matlab_buffer* %0) {
%2 = tail call i8* @ensure_buffer(%struct.matlab_buffer* %0, i32 124)
%3 = tail call i32 @memcpy(i8* %2, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i64 50)
%4 = getelementptr inbounds i8, i8* %2, i64 50
%5 = tail call i32 @memset(i8* %4, i8 signext 32, i32 74)
%6 = tail call i32 @write_buffer_uint32(%struct.matlab_buffer* %0, i32 1296630016)
ret void
}