#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int countDigits(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int getpid();
char *malloc(int);
char *realloc(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void buildMessage(char **message, char **receivers, int count) {
  int dimension_message = 4, i;
  for (i = 0; i < count; i++) {
    dimension_message += strlen(*(receivers + i)) + 1;
  }
  dimension_message += (countDigits(getpid()) + 2);
  dimension_message += strlen(*message) + 1;
  char *temp = malloc(sizeof(char) * dimension_message);
  if (temp == NULL)
    exit(EXIT_FAILURE);
  strcpy(temp, "MSG ");
  for (i = 0; i < count; i++) {
    strcat(temp, *(receivers + i));
    strcat(temp, " ");
  }
  char *mypid = malloc(sizeof(char) * (countDigits(getpid()) + 3));
  if (mypid == NULL)
    exit(EXIT_FAILURE);
  sprintf(mypid, "$%d ", getpid());
  strcat(temp, mypid);
  strcat(temp, *message);
  *message = realloc(*message, sizeof(char) * (strlen(temp) + 1));
  strcpy(*message, temp);
  free(temp);
  free(mypid);
}


x86 assembly (clang, -O0):
<buildMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x4,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f5 <buildMessage+0x55>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c1 <buildMessage+0x21>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%edi
call   1070 <countDigits@plt>
add    $0x2,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    124d <buildMessage+0xad>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    0xda8(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12a3 <buildMessage+0x103>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   10a0 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xd73(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1264 <buildMessage+0xc4>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,%edi
call   1070 <countDigits@plt>
add    $0x3,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12de <buildMessage+0x13e>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xd0b(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   10a0 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1090 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buildMessage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rsi,%r15
mov    %rdi,(%rsp)
mov    %edx,%r14d
test   %edx,%edx
jle    11ec <buildMessage+0x4c>
mov    $0x4,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15,%rbp,8),%rdi
call   1060 <strlen@plt>
add    %eax,%ebx
add    $0x1,%ebx
add    $0x1,%rbp
cmp    %rbp,%r14
jne    11d0 <buildMessage+0x30>
add    $0x3,%ebx
jmp    11f1 <buildMessage+0x51>
mov    $0x7,%ebx
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%edi
call   1070 <countDigits@plt>
mov    %eax,%r13d
mov    (%rsp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
add    %ebx,%r13d
add    %eax,%r13d
mov    %r13d,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1305 <buildMessage+0x165>
mov    %rax,%rbx
lea    0xdd1(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
test   %r12d,%r12d
jle    1270 <buildMessage+0xd0>
xor    %ebp,%ebp
lea    0xdbe(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15,%rbp,8),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10a0 <strcat@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1250 <buildMessage+0xb0>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%edi
call   1070 <countDigits@plt>
lea    0x3(%rax),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1305 <buildMessage+0x165>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xd69(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <strcat@plt>
mov    (%rsp),%rbp
mov    0x0(%rbp),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    0x0(%rbp),%r15
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%esi
mov    %r15,%rdi
call   1090 <realloc@plt>
mov    %rax,0x0(%rbp)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [5 x i8] c"MSG \00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [5 x i8] c"$%d \00"
define void @buildMessage(i8** %0, i8** %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i8** %0, i8*** %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
store i32 4, i32* %7
store i32 0, i32* %8
br label %11
11: ; preds = %25, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = load i8**, i8*** %5
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %21, 1
%23 = load i32, i32* %7
%24 = add nsw i32 %23, %22
store i32 %24, i32* %7
br label %25
25: ; preds = %15
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %11
28: ; preds = %11
%29 = call i32 (...) @getpid()
%30 = call i32 @countDigits(i32 %29)
%31 = add nsw i32 %30, 2
%32 = load i32, i32* %7
%33 = add nsw i32 %32, %31
store i32 %33, i32* %7
%34 = load i8**, i8*** %4
%35 = load i8*, i8** %34
%36 = call i32 @strlen(i8* %35)
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %7
%39 = add nsw i32 %38, %37
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = mul i64 1, %41
%43 = trunc i64 %42 to i32
%44 = call i8* @malloc(i32 %43)
store i8* %44, i8** %9
%45 = load i8*, i8** %9
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %28
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %28
%51 = load i8*, i8** %9
%52 = call i32 @strcpy(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %53
53: ; preds = %67, %50
%54 = load i32, i32* %8
%55 = load i32, i32* %6
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %70
57: ; preds = %53
%58 = load i8*, i8** %9
%59 = load i8**, i8*** %5
%60 = load i32, i32* %8
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %59, i64 %61
%63 = load i8*, i8** %62
%64 = call i32 @strcat(i8* %58, i8* %63)
%65 = load i8*, i8** %9
%66 = call i32 @strcat(i8* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %67
67: ; preds = %57
%68 = load i32, i32* %8
%69 = add nsw i32 %68, 1
store i32 %69, i32* %8
br label %53
70: ; preds = %53
%71 = call i32 (...) @getpid()
%72 = call i32 @countDigits(i32 %71)
%73 = add nsw i32 %72, 3
%74 = sext i32 %73 to i64
%75 = mul i64 1, %74
%76 = trunc i64 %75 to i32
%77 = call i8* @malloc(i32 %76)
store i8* %77, i8** %10
%78 = load i8*, i8** %10
%79 = icmp eq i8* %78, null
br i1 %79, label %80, label %83
80: ; preds = %70
%81 = load i32, i32* @EXIT_FAILURE
%82 = call i32 @exit(i32 %81)
unreachable
83: ; preds = %70
%84 = load i8*, i8** %10
%85 = call i32 (...) @getpid()
%86 = call i32 @sprintf(i8* %84, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %85)
%87 = load i8*, i8** %9
%88 = load i8*, i8** %10
%89 = call i32 @strcat(i8* %87, i8* %88)
%90 = load i8*, i8** %9
%91 = load i8**, i8*** %4
%92 = load i8*, i8** %91
%93 = call i32 @strcat(i8* %90, i8* %92)
%94 = load i8**, i8*** %4
%95 = load i8*, i8** %94
%96 = load i8*, i8** %9
%97 = call i32 @strlen(i8* %96)
%98 = add nsw i32 %97, 1
%99 = sext i32 %98 to i64
%100 = mul i64 1, %99
%101 = trunc i64 %100 to i32
%102 = call i8* @realloc(i8* %95, i32 %101)
%103 = load i8**, i8*** %4
store i8* %102, i8** %103
%104 = load i8**, i8*** %4
%105 = load i8*, i8** %104
%106 = load i8*, i8** %9
%107 = call i32 @strcpy(i8* %105, i8* %106)
%108 = load i8*, i8** %9
%109 = call i32 @free(i8* %108)
%110 = load i8*, i8** %10
%111 = call i32 @free(i8* %110)
ret void
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [5 x i8] c"MSG \00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [5 x i8] c"$%d \00"
define void @buildMessage(i8** nocapture %0, i8** nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %19
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %15, %7 ]
%9 = phi i32 [ 4, %5 ], [ %14, %7 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %8
%11 = load i8*, i8** %10
%12 = tail call i32 @strlen(i8* %11)
%13 = add i32 %9, 1
%14 = add i32 %13, %12
%15 = add nuw nsw i64 %8, 1
%16 = icmp eq i64 %15, %6
br i1 %16, label %17, label %7
17: ; preds = %7
%18 = add i32 %14, 3
br label %19
19: ; preds = %17, %3
%20 = phi i32 [ 7, %3 ], [ %18, %17 ]
%21 = tail call i32 (...) @getpid()
%22 = tail call i32 @countDigits(i32 %21)
%23 = load i8*, i8** %0
%24 = tail call i32 @strlen(i8* %23)
%25 = add i32 %20, %22
%26 = add i32 %25, %24
%27 = tail call i8* @malloc(i32 %26)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %19
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %19
%33 = tail call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br i1 %4, label %34, label %44
34: ; preds = %32
%35 = zext i32 %2 to i64
br label %36
36: ; preds = %34, %36
%37 = phi i64 [ 0, %34 ], [ %42, %36 ]
%38 = getelementptr inbounds i8*, i8** %1, i64 %37
%39 = load i8*, i8** %38
%40 = tail call i32 @strcat(i8* %27, i8* %39)
%41 = tail call i32 @strcat(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%42 = add nuw nsw i64 %37, 1
%43 = icmp eq i64 %42, %35
br i1 %43, label %44, label %36
44: ; preds = %36, %32
%45 = tail call i32 (...) @getpid()
%46 = tail call i32 @countDigits(i32 %45)
%47 = add nsw i32 %46, 3
%48 = tail call i8* @malloc(i32 %47)
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %53
50: ; preds = %44
%51 = load i32, i32* @EXIT_FAILURE
%52 = tail call i32 @exit(i32 %51)
unreachable
53: ; preds = %44
%54 = tail call i32 (...) @getpid()
%55 = tail call i32 @sprintf(i8* %48, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = tail call i32 @strcat(i8* %27, i8* %48)
%57 = load i8*, i8** %0
%58 = tail call i32 @strcat(i8* %27, i8* %57)
%59 = load i8*, i8** %0
%60 = tail call i32 @strlen(i8* %27)
%61 = add nsw i32 %60, 1
%62 = tail call i8* @realloc(i8* %59, i32 %61)
store i8* %62, i8** %0
%63 = tail call i32 @strcpy(i8* %62, i8* %27)
%64 = tail call i32 @free(i8* %27)
%65 = tail call i32 @free(i8* %48)
ret void
}