#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(scalar_t__);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *Concat3Strings(char *str1, char *str2, char *str3) {
  if (((str1 == NULL) || (str1[0] == '\0')) ||
      ((str2 == NULL) || (str2[0] == '\0')) ||
      ((str3 == NULL) || (str3[0] == '\0'))) {
    printf("ERROR IN CONCAT 3 STRING");
    return NULL;
  }
  char *str4 = (char *)malloc(1 + strlen(str1) + strlen(str2));
  strcpy(str4, str1);
  strcat(str4, str2);
  char *str5 = (char *)malloc(1 + strlen(str4) + strlen(","));
  strcpy(str5, str4);
  strcat(str5, ",");
  char *str6 = (char *)malloc(1 + strlen(str5) + strlen(str3));
  strcpy(str6, str5);
  strcat(str6, str3);
  return str6;
}


x86 assembly (clang, -O0):
<Concat3Strings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b5 <Concat3Strings+0x65>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b5 <Concat3Strings+0x65>
cmpq   $0x0,-0x18(%rbp)
je     11b5 <Concat3Strings+0x65>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b5 <Concat3Strings+0x65>
cmpq   $0x0,-0x20(%rbp)
je     11b5 <Concat3Strings+0x65>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ce <Concat3Strings+0x7e>
lea    0xe44(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12a8 <Concat3Strings+0x158>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
add    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
lea    0xdef(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
add    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xdc2(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Concat3Strings>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     123b <Concat3Strings+0xeb>
mov    %rsi,%r15
test   %rsi,%rsi
je     123b <Concat3Strings+0xeb>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     123b <Concat3Strings+0xeb>
mov    %rdx,%r14
test   %rdx,%rdx
je     123b <Concat3Strings+0xeb>
cmpb   $0x0,(%r15)
je     123b <Concat3Strings+0xeb>
cmpb   $0x0,(%r14)
je     123b <Concat3Strings+0xeb>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%r12,%rax,1),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    0x2(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
lea    0xe21(%rip),%rsi
mov    %r15,%rdi
call   1070 <strcat@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
jmp    1249 <Concat3Strings+0xf9>
lea    0xdbe(%rip),%rdi
call   1050 <printf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"ERROR IN CONCAT 3 STRING\00"
@.str.1 = [2 x i8] c",\00"
define i8* @Concat3Strings(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %37, label %13
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %37, label %19
19: ; preds = %13
%20 = load i8*, i8** %6
%21 = icmp eq i8* %20, null
br i1 %21, label %37, label %22
22: ; preds = %19
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %37, label %28
28: ; preds = %22
%29 = load i8*, i8** %7
%30 = icmp eq i8* %29, null
br i1 %30, label %37, label %31
31: ; preds = %28
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %31, %28, %22, %19, %13, %3
%38 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %4
br label %81
39: ; preds = %31
%40 = load i8*, i8** %5
%41 = call i64 @strlen(i8* %40)
%42 = add nsw i64 1, %41
%43 = load i8*, i8** %6
%44 = call i64 @strlen(i8* %43)
%45 = add nsw i64 %42, %44
%46 = call i64 @malloc(i64 %45)
%47 = inttoptr i64 %46 to i8*
store i8* %47, i8** %8
%48 = load i8*, i8** %8
%49 = load i8*, i8** %5
%50 = call i32 @strcpy(i8* %48, i8* %49)
%51 = load i8*, i8** %8
%52 = load i8*, i8** %6
%53 = call i32 @strcat(i8* %51, i8* %52)
%54 = load i8*, i8** %8
%55 = call i64 @strlen(i8* %54)
%56 = add nsw i64 1, %55
%57 = call i64 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%58 = add nsw i64 %56, %57
%59 = call i64 @malloc(i64 %58)
%60 = inttoptr i64 %59 to i8*
store i8* %60, i8** %9
%61 = load i8*, i8** %9
%62 = load i8*, i8** %8
%63 = call i32 @strcpy(i8* %61, i8* %62)
%64 = load i8*, i8** %9
%65 = call i32 @strcat(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%66 = load i8*, i8** %9
%67 = call i64 @strlen(i8* %66)
%68 = add nsw i64 1, %67
%69 = load i8*, i8** %7
%70 = call i64 @strlen(i8* %69)
%71 = add nsw i64 %68, %70
%72 = call i64 @malloc(i64 %71)
%73 = inttoptr i64 %72 to i8*
store i8* %73, i8** %10
%74 = load i8*, i8** %10
%75 = load i8*, i8** %9
%76 = call i32 @strcpy(i8* %74, i8* %75)
%77 = load i8*, i8** %10
%78 = load i8*, i8** %7
%79 = call i32 @strcat(i8* %77, i8* %78)
%80 = load i8*, i8** %10
store i8* %80, i8** %4
br label %81
81: ; preds = %39, %37
%82 = load i8*, i8** %4
ret i8* %82
}

LLVM IR (-O2):
@.str = [25 x i8] c"ERROR IN CONCAT 3 STRING\00"
@.str.1 = [2 x i8] c",\00"
define i8* @Concat3Strings(i8* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %18, label %5
5: ; preds = %3
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
%8 = icmp eq i8* %1, null
%9 = or i1 %8, %7
br i1 %9, label %18, label %10
10: ; preds = %5
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 0
%13 = icmp eq i8* %2, null
%14 = or i1 %13, %12
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = load i8, i8* %2
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15, %10, %5, %3
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %43
20: ; preds = %15
%21 = tail call i64 @strlen(i8* %0)
%22 = add nsw i64 %21, 1
%23 = tail call i64 @strlen(i8* %1)
%24 = add nsw i64 %22, %23
%25 = tail call i64 @malloc(i64 %24)
%26 = inttoptr i64 %25 to i8*
%27 = tail call i32 @strcpy(i8* %26, i8* %0)
%28 = tail call i32 @strcat(i8* %26, i8* %1)
%29 = tail call i64 @strlen(i8* dereferenceable(1) %26)
%30 = add nsw i64 %29, 2
%31 = tail call i64 @malloc(i64 %30)
%32 = inttoptr i64 %31 to i8*
%33 = tail call i32 @strcpy(i8* %32, i8* %26)
%34 = tail call i32 @strcat(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%35 = tail call i64 @strlen(i8* dereferenceable(1) %32)
%36 = add nsw i64 %35, 1
%37 = tail call i64 @strlen(i8* %2)
%38 = add nsw i64 %36, %37
%39 = tail call i64 @malloc(i64 %38)
%40 = inttoptr i64 %39 to i8*
%41 = tail call i32 @strcpy(i8* %40, i8* %32)
%42 = tail call i32 @strcat(i8* %40, i8* %2)
br label %43
43: ; preds = %20, %18
%44 = phi i8* [ null, %18 ], [ %40, %20 ]
ret i8* %44
}