#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__ calloc(scalar_t__, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *concatenate(char *a, char *b) {
  char *c = NULL;
  if (a != NULL && b != NULL) {
    while (c == NULL) {
      c = (char *)calloc(strlen(a) + strlen(b) + 2, sizeof(char));
    }
    strcpy(c, a);
    strcat(c, b);
  }
  return c;
}


x86 assembly (clang, -O0):
<concatenate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11cc <concatenate+0x8c>
cmpq   $0x0,-0x10(%rbp)
je     11cc <concatenate+0x8c>
jmp    1173 <concatenate+0x33>
cmpq   $0x0,-0x18(%rbp)
jne    11b2 <concatenate+0x72>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
jmp    1173 <concatenate+0x33>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concatenate>:
push   %r15
push   %r14
push   %rbx
xor    %ebx,%ebx
test   %rdi,%rdi
je     11a3 <concatenate+0x63>
mov    %rsi,%r14
test   %rsi,%rsi
je     11a3 <concatenate+0x63>
mov    %rdi,%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     1160 <concatenate+0x20>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @concatenate(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %5
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %31
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %31
11: ; preds = %8
br label %12
12: ; preds = %15, %11
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = call i64 @strlen(i8* %16)
%18 = load i8*, i8** %4
%19 = call i64 @strlen(i8* %18)
%20 = add nsw i64 %17, %19
%21 = add nsw i64 %20, 2
%22 = call i64 @calloc(i64 %21, i32 1)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %5
br label %12
24: ; preds = %12
%25 = load i8*, i8** %5
%26 = load i8*, i8** %3
%27 = call i32 @strcpy(i8* %25, i8* %26)
%28 = load i8*, i8** %5
%29 = load i8*, i8** %4
%30 = call i32 @strcat(i8* %28, i8* %29)
br label %31
31: ; preds = %24, %8, %2
%32 = load i8*, i8** %5
ret i8* %32
}

LLVM IR (-O2):
define i8* @concatenate(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %17
6: ; preds = %2, %6
%7 = tail call i64 @strlen(i8* %0)
%8 = tail call i64 @strlen(i8* %1)
%9 = add i64 %7, 2
%10 = add i64 %9, %8
%11 = tail call i64 @calloc(i64 %10, i32 1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %6, label %13
13: ; preds = %6
%14 = inttoptr i64 %11 to i8*
%15 = tail call i32 @strcpy(i8* %14, i8* %0)
%16 = tail call i32 @strcat(i8* %14, i8* %1)
br label %17
17: ; preds = %13, %2
%18 = phi i8* [ %14, %13 ], [ null, %2 ]
ret i8* %18
}