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


x86 assembly (clang, -O0):
<Concat4Strings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d7 <Concat4Strings+0x87>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d7 <Concat4Strings+0x87>
cmpq   $0x0,-0x18(%rbp)
je     11d7 <Concat4Strings+0x87>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d7 <Concat4Strings+0x87>
cmpq   $0x0,-0x20(%rbp)
je     11d7 <Concat4Strings+0x87>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d7 <Concat4Strings+0x87>
cmpq   $0x0,-0x28(%rbp)
je     11d7 <Concat4Strings+0x87>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11f0 <Concat4Strings+0xa0>
lea    0xe22(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1358 <Concat4Strings+0x208>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x78(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x78(%rbp),%rdi
add    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x70(%rbp)
lea    0xdcd(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x70(%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
lea    0xda0(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x68(%rbp),%rdi
add    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
lea    0xd3f(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
add    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x48(%rbp),%rdi
lea    0xd12(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rdi
add    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Concat4Strings>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     12bb <Concat4Strings+0x16b>
mov    %rsi,%r12
test   %rsi,%rsi
je     12bb <Concat4Strings+0x16b>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     12bb <Concat4Strings+0x16b>
mov    %rdx,%r15
test   %rdx,%rdx
je     12bb <Concat4Strings+0x16b>
cmpb   $0x0,(%r12)
je     12bb <Concat4Strings+0x16b>
mov    %rcx,%r14
test   %rcx,%rcx
je     12bb <Concat4Strings+0x16b>
cmpb   $0x0,(%r15)
je     12bb <Concat4Strings+0x16b>
cmpb   $0x0,(%r14)
je     12bb <Concat4Strings+0x16b>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    (%rax,%r13,1),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <strcat@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
lea    0x2(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
lea    0xe07(%rip),%r12
mov    %rbp,%rdi
mov    %r12,%rsi
call   1070 <strcat@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%rax,%r13,1),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x2(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1070 <strcat@plt>
mov    %rbp,%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    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
jmp    12c9 <Concat4Strings+0x179>
lea    0xd3e(%rip),%rdi
call   1050 <printf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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