#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 */
char *malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *concat(char *s1, char *s2, char *s3) {
  char *result = malloc(strlen(s1) + strlen(s2) + 2);
  if (strlen(s1) > 0)
    strcpy(result, s1);
  if (strlen(s2) > 0)
    strcat(result, s2);
  if (strlen(s3) > 0)
    strcat(result, s3);
  return result;
}


x86 assembly (clang, -O0):
<concat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    119e <concat+0x5e>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    11be <concat+0x7e>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    11de <concat+0x9e>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,%r13
test   %rbx,%rbx
jle    1182 <concat+0x42>
mov    %r13,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    119a <concat+0x5a>
mov    %r13,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jle    11b2 <concat+0x72>
mov    %r13,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @concat(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %9, %11
%13 = add nsw i64 %12, 2
%14 = call i8* @malloc(i64 %13)
store i8* %14, i8** %7
%15 = load i8*, i8** %4
%16 = call i64 @strlen(i8* %15)
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = load i8*, i8** %7
%20 = load i8*, i8** %4
%21 = call i32 @strcpy(i8* %19, i8* %20)
br label %22
22: ; preds = %18, %3
%23 = load i8*, i8** %5
%24 = call i64 @strlen(i8* %23)
%25 = icmp sgt i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i8*, i8** %7
%28 = load i8*, i8** %5
%29 = call i32 @strcat(i8* %27, i8* %28)
br label %30
30: ; preds = %26, %22
%31 = load i8*, i8** %6
%32 = call i64 @strlen(i8* %31)
%33 = icmp sgt i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i8*, i8** %7
%36 = load i8*, i8** %6
%37 = call i32 @strcat(i8* %35, i8* %36)
br label %38
38: ; preds = %34, %30
%39 = load i8*, i8** %7
ret i8* %39
}

LLVM IR (-O2):
define i8* @concat(i8* %0, i8* %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = add i64 %4, 2
%7 = add i64 %6, %5
%8 = tail call i8* @malloc(i64 %7)
%9 = icmp sgt i64 %4, 0
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @strcpy(i8* %8, i8* %0)
br label %12
12: ; preds = %10, %3
%13 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @strcat(i8* %8, i8* %1)
br label %17
17: ; preds = %15, %12
%18 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @strcat(i8* %8, i8* %2)
br label %22
22: ; preds = %20, %17
ret i8* %8
}