#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 */
typedef scalar_t__ malloc;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ memcpy(char *, void *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int, int /*<<< orphan*/);
int dump_data_to_bytestream(char **pp_bytestream, int n_files,
                            const char *str_files_metadata,
                            int n_files_metadata_len, const char *str_msg_data,
                            int n_msg_len) {
  int int_size = sizeof(int);
  int n_status = 0;
  int n_bytestream_len = n_files_metadata_len + n_msg_len + 3 * int_size + 1;
  *pp_bytestream = (char *)(malloc)(n_bytestream_len);
  if (NULL == *pp_bytestream) {
    syslog(LOG_ERR,
           "dump_data_to_bytestream: "
           "unable to allocate %d bytes of memory, error = %s",
           n_bytestream_len, strerror(errno));
    n_status = -1;
  }
  if (0 == n_status) {
    int n_offset = 0;
    memcpy(*pp_bytestream + n_offset, (void *)&n_files, int_size);
    n_offset += int_size;
    memcpy(*pp_bytestream + n_offset, (void *)&n_files_metadata_len, int_size);
    n_offset += int_size;
    memcpy(*pp_bytestream + n_offset, (void *)&n_msg_len, int_size);
    n_offset += int_size;
    memcpy(*pp_bytestream + n_offset, (void *)str_files_metadata,
           n_files_metadata_len);
    n_offset += n_files_metadata_len;
    memcpy(*pp_bytestream + n_offset, (void *)str_msg_data, n_msg_len);
  }
  return (0 == n_status ? n_bytestream_len : -1);
}


x86 assembly (clang, -O0):
<dump_data_to_bytestream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movl   $0x4,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x2c(%rbp),%eax
imul   $0x3,-0x30(%rbp),%ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
movslq -0x38(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
jne    11c3 <dump_data_to_bytestream+0x93>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%edx
mov    %eax,%ecx
lea    0xe49(%rip),%rsi
call   1040 <syslog@plt>
movl   $0xffffffff,-0x34(%rbp)
xor    %eax,%eax
cmp    -0x34(%rbp),%eax
jne    127b <dump_data_to_bytestream+0x14b>
movl   $0x0,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
lea    -0xc(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x30(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
lea    -0x1c(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x30(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
lea    -0x2c(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x30(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
movslq -0x3c(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <memcpy@plt>
xor    %eax,%eax
cmp    -0x34(%rbp),%eax
jne    1291 <dump_data_to_bytestream+0x161>
mov    -0x38(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    129e <dump_data_to_bytestream+0x16e>
mov    $0xffffffff,%eax
mov    %eax,-0x48(%rbp)
jmp    129e <dump_data_to_bytestream+0x16e>
mov    -0x48(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_data_to_bytestream>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    %esi,0x14(%rsp)
mov    %ecx,0xc(%rsp)
mov    %r9d,0x10(%rsp)
lea    (%rcx,%r9,1),%ebp
add    $0xd,%ebp
movslq %ebp,%rdi
mov    %rdi,(%rbx)
test   %edi,%edi
je     11cd <dump_data_to_bytestream+0x9d>
mov    %r8,%r14
mov    %rdx,%r15
lea    0x14(%rsp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    (%rbx),%rdi
add    $0x4,%rdi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    (%rbx),%rdi
add    $0x8,%rdi
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    (%rbx),%rdi
add    $0xc,%rdi
mov    0xc(%rsp),%edx
mov    %r15,%rsi
call   1030 <memcpy@plt>
movslq 0xc(%rsp),%rax
mov    (%rbx),%rcx
lea    (%rax,%rcx,1),%rdi
add    $0xc,%rdi
mov    0x10(%rsp),%edx
mov    %r14,%rsi
call   1030 <memcpy@plt>
jmp    11fb <dump_data_to_bytestream+0xcb>
mov    0x2dfc(%rip),%rax
mov    (%rax),%ebx
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe15(%rip),%rsi
mov    %ebx,%edi
xor    %edx,%edx
mov    %eax,%ecx
call   1040 <syslog@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [75 x i8] c"dump_data_to_bytestream: unable to allocate %d bytes of memory, error = %s\00"
@errno = global i32 0
define i32 @dump_data_to_bytestream(i8** %0, i32 %1, i8* %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8** %0, i8*** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i8* %4, i8** %11
store i32 %5, i32* %12
store i32 4, i32* %13
store i32 0, i32* %14
%17 = load i32, i32* %10
%18 = load i32, i32* %12
%19 = add nsw i32 %17, %18
%20 = load i32, i32* %13
%21 = mul nsw i32 3, %20
%22 = add nsw i32 %19, %21
%23 = add nsw i32 %22, 1
store i32 %23, i32* %15
%24 = load i32, i32* %15
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i8*
%27 = load i8**, i8*** %7
store i8* %26, i8** %27
%28 = load i8**, i8*** %7
%29 = load i8*, i8** %28
%30 = icmp eq i8* null, %29
br i1 %30, label %31, label %37
31: ; preds = %6
%32 = load i32, i32* @LOG_ERR
%33 = load i32, i32* %15
%34 = load i32, i32* @errno
%35 = call i32 @strerror(i32 %34)
%36 = call i32 @syslog(i32 %32, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %35)
store i32 -1, i32* %14
br label %37
37: ; preds = %31, %6
%38 = load i32, i32* %14
%39 = icmp eq i32 0, %38
br i1 %39, label %40, label %93
40: ; preds = %37
store i32 0, i32* %16
%41 = load i8**, i8*** %7
%42 = load i8*, i8** %41
%43 = load i32, i32* %16
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = bitcast i32* %8 to i8*
%47 = load i32, i32* %13
%48 = call i32 @memcpy(i8* %45, i8* %46, i32 %47)
%49 = load i32, i32* %13
%50 = load i32, i32* %16
%51 = add nsw i32 %50, %49
store i32 %51, i32* %16
%52 = load i8**, i8*** %7
%53 = load i8*, i8** %52
%54 = load i32, i32* %16
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = bitcast i32* %10 to i8*
%58 = load i32, i32* %13
%59 = call i32 @memcpy(i8* %56, i8* %57, i32 %58)
%60 = load i32, i32* %13
%61 = load i32, i32* %16
%62 = add nsw i32 %61, %60
store i32 %62, i32* %16
%63 = load i8**, i8*** %7
%64 = load i8*, i8** %63
%65 = load i32, i32* %16
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = bitcast i32* %12 to i8*
%69 = load i32, i32* %13
%70 = call i32 @memcpy(i8* %67, i8* %68, i32 %69)
%71 = load i32, i32* %13
%72 = load i32, i32* %16
%73 = add nsw i32 %72, %71
store i32 %73, i32* %16
%74 = load i8**, i8*** %7
%75 = load i8*, i8** %74
%76 = load i32, i32* %16
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
%79 = load i8*, i8** %9
%80 = load i32, i32* %10
%81 = call i32 @memcpy(i8* %78, i8* %79, i32 %80)
%82 = load i32, i32* %10
%83 = load i32, i32* %16
%84 = add nsw i32 %83, %82
store i32 %84, i32* %16
%85 = load i8**, i8*** %7
%86 = load i8*, i8** %85
%87 = load i32, i32* %16
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %86, i64 %88
%90 = load i8*, i8** %11
%91 = load i32, i32* %12
%92 = call i32 @memcpy(i8* %89, i8* %90, i32 %91)
br label %93
93: ; preds = %40, %37
%94 = load i32, i32* %14
%95 = icmp eq i32 0, %94
br i1 %95, label %96, label %98
96: ; preds = %93
%97 = load i32, i32* %15
br label %99
98: ; preds = %93
br label %99
99: ; preds = %98, %96
%100 = phi i32 [ %97, %96 ], [ -1, %98 ]
ret i32 %100
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [75 x i8] c"dump_data_to_bytestream: unable to allocate %d bytes of memory, error = %s\00"
@errno = global i32 0
define i32 @dump_data_to_bytestream(i8** nocapture %0, i32 %1, i8* %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %1, i32* %7
store i32 %3, i32* %8
store i32 %5, i32* %9
%10 = add i32 %3, 13
%11 = add i32 %10, %5
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %0
%14 = icmp eq i32 %11, 0
br i1 %14, label %15, label %20
15: ; preds = %6
%16 = load i32, i32* @LOG_ERR
%17 = load i32, i32* @errno
%18 = tail call i32 @strerror(i32 %17)
%19 = tail call i32 @syslog(i32 %16, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i32 0, i32 %18)
br label %42
20: ; preds = %6
%21 = bitcast i32* %7 to i8*
%22 = call i32 @memcpy(i8* %13, i8* %21, i32 4)
%23 = load i8*, i8** %0
%24 = getelementptr inbounds i8, i8* %23, i64 4
%25 = bitcast i32* %8 to i8*
%26 = call i32 @memcpy(i8* %24, i8* %25, i32 4)
%27 = load i8*, i8** %0
%28 = getelementptr inbounds i8, i8* %27, i64 8
%29 = bitcast i32* %9 to i8*
%30 = call i32 @memcpy(i8* %28, i8* %29, i32 4)
%31 = load i8*, i8** %0
%32 = getelementptr inbounds i8, i8* %31, i64 12
%33 = load i32, i32* %8
%34 = call i32 @memcpy(i8* %32, i8* %2, i32 %33)
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 12
%37 = load i8*, i8** %0
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i32, i32* %9
%41 = call i32 @memcpy(i8* %39, i8* %4, i32 %40)
br label %42
42: ; preds = %15, %20
%43 = phi i32 [ %11, %20 ], [ -1, %15 ]
ret i32 %43
}