#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(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *concat(char *a, char *b) {
  if (a == NULL || b == NULL)
    return NULL;
  int length = strlen(a) + strlen(b) + 2;
  char *result = (char *)malloc(length * sizeof(char));
  if (result == NULL)
    return NULL;
  result[length - 1] = 0;
  char *middle = result + strlen(a);
  strcpy(result, a);
  middle[0] = '/';
  strcpy(++middle, b);
  return result;
}


x86 assembly (clang, -O0):
<concat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1156 <concat+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1163 <concat+0x33>
movq   $0x0,-0x8(%rbp)
jmp    1213 <concat+0xe3>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b0 <concat+0x80>
movq   $0x0,-0x8(%rbp)
jmp    1213 <concat+0xe3>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
xor    %ebx,%ebx
test   %rdi,%rdi
je     11ac <concat+0x7c>
mov    %rsi,%r14
test   %rsi,%rsi
je     11ac <concat+0x7c>
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
lea    (%r12,%r13,1),%edi
add    $0x2,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11aa <concat+0x7a>
mov    %rax,%rbx
add    %r12d,%r13d
movslq %r13d,%rax
movb   $0x0,0x1(%rax,%rbx,1)
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%r12
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
movb   $0x2f,(%rbx,%r12,1)
lea    (%rbx,%r12,1),%rdi
add    $0x1,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    11ac <concat+0x7c>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @concat(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %24, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i32 @strlen(i8* %1)
%9 = add nsw i32 %8, %7
%10 = add nsw i32 %9, 2
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = icmp eq i64 %11, 0
br i1 %13, label %24, label %14
14: ; preds = %6
%15 = add nsw i32 %9, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %12, i64 %16
store i8 0, i8* %17
%18 = tail call i32 @strlen(i8* %0)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %12, i64 %19
%21 = tail call i32 @strcpy(i8* %12, i8* %0)
store i8 47, i8* %20
%22 = getelementptr inbounds i8, i8* %20, i64 1
%23 = tail call i32 @strcpy(i8* %22, i8* %1)
br label %24
24: ; preds = %14, %6, %2
%25 = phi i8* [ null, %2 ], [ %12, %14 ], [ null, %6 ]
ret i8* %25
}