#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
char *prepareMessage(int *countCommand, int totalCommands, char **table,
                     int *length) {
  char *messageAux;
  messageAux = (char *)malloc(3000 * sizeof(char));
  int nmsg;
  nmsg = 0;
  memset(messageAux, 0, 3000);
  if ((*countCommand) < totalCommands) {
    strncat(messageAux, table[(*countCommand)], strlen(table[(*countCommand)]));
    (*countCommand)++;
  } else {
    strncat(messageAux, "", 0);
  }
  *length = strlen(messageAux) + 1;
  return messageAux;
}


x86 assembly (clang, -O0):
<prepareMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0xbb8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xbb8,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
cmp    -0xc(%rbp),%eax
jge    11d9 <prepareMessage+0x99>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1050 <strncat@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11eb <prepareMessage+0xab>
mov    -0x28(%rbp),%rdi
lea    0xe1c(%rip),%rsi
xor    %edx,%edx
call   1050 <strncat@plt>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepareMessage>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r12
mov    %esi,%ebp
mov    %rdi,%r15
mov    $0xbb8,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xbb8,%edx
call   1040 <memset@plt>
movslq (%r15),%rax
cmp    %ebp,%eax
jge    1195 <prepareMessage+0x55>
mov    (%r12,%rax,8),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <strncat@plt>
addl   $0x1,(%r15)
jmp    11a6 <prepareMessage+0x66>
lea    0xe64(%rip),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <strncat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,(%r14)
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @prepareMessage(i32* %0, i32 %1, i8** %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
store i32* %3, i32** %8
%11 = call i64 @malloc(i32 3000)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %9
store i32 0, i32* %10
%13 = load i8*, i8** %9
%14 = call i32 @memset(i8* %13, i32 0, i32 3000)
%15 = load i32*, i32** %5
%16 = load i32, i32* %15
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %38
19: ; preds = %4
%20 = load i8*, i8** %9
%21 = load i8**, i8*** %7
%22 = load i32*, i32** %5
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %21, i64 %24
%26 = load i8*, i8** %25
%27 = load i8**, i8*** %7
%28 = load i32*, i32** %5
%29 = load i32, i32* %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %27, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @strlen(i8* %32)
%34 = call i32 @strncat(i8* %20, i8* %26, i32 %33)
%35 = load i32*, i32** %5
%36 = load i32, i32* %35
%37 = add nsw i32 %36, 1
store i32 %37, i32* %35
br label %41
38: ; preds = %4
%39 = load i8*, i8** %9
%40 = call i32 @strncat(i8* %39, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0)
br label %41
41: ; preds = %38, %19
%42 = load i8*, i8** %9
%43 = call i32 @strlen(i8* %42)
%44 = add nsw i32 %43, 1
%45 = load i32*, i32** %8
store i32 %44, i32* %45
%46 = load i8*, i8** %9
ret i8* %46
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @prepareMessage(i32* nocapture %0, i32 %1, i8** nocapture %2, i32* nocapture writeonly %3) {
%5 = tail call i64 @malloc(i32 3000)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @memset(i8* %6, i32 0, i32 3000)
%8 = load i32, i32* %0
%9 = icmp slt i32 %8, %1
br i1 %9, label %10, label %18
10: ; preds = %4
%11 = sext i32 %8 to i64
%12 = getelementptr inbounds i8*, i8** %2, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32 @strlen(i8* %13)
%15 = tail call i32 @strncat(i8* %6, i8* %13, i32 %14)
%16 = load i32, i32* %0
%17 = add nsw i32 %16, 1
store i32 %17, i32* %0
br label %20
18: ; preds = %4
%19 = tail call i32 @strncat(i8* %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0)
br label %20
20: ; preds = %18, %10
%21 = tail call i32 @strlen(i8* %6)
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
ret i8* %6
}