#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(int);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *concat(const char *s1, const char *s2) {
  int i_s1 = 0;
  int i_s2 = 0;
  if (&(s1)[0] != NULL)
    i_s1 = strlen(s1);
  if (&(s2)[0] != NULL)
    i_s2 = strlen(s2);
  char *result = malloc(i_s1 + i_s2 + 1);
  if (&(s1)[0] != NULL)
    strcpy(result, s1);
  if (&(s2)[0] != NULL)
    strcat(result, s2);
  return result;
}


x86 assembly (clang, -O0):
<concat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmp    $0x0,%rax
je     1178 <concat+0x38>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmp    $0x0,%rax
je     1192 <concat+0x52>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
add    -0x18(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
cmp    $0x0,%rax
je     11bf <concat+0x7f>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
cmp    $0x0,%rax
je     11da <concat+0x9a>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     116b <concat+0x2b>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
add    $0x1,%ebp
test   %r14,%r14
je     1175 <concat+0x35>
mov    %r14,%rdi
call   1040 <strlen@plt>
jmp    1177 <concat+0x37>
mov    $0x1,%ebp
test   %r14,%r14
jne    1161 <concat+0x21>
xor    %eax,%eax
add    %eax,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
test   %rbx,%rbx
je     1193 <concat+0x53>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
test   %r14,%r14
je     11a3 <concat+0x63>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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