#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(size_t);
char *strdup(char const *const);
size_t strlen(char const *const);
char *join_str_double(const char *const left, const char *const right) {
  if (left == NULL) {
    if (right == NULL) {
      return NULL;
    } else {
      return strdup(right);
    }
  } else if (right == NULL) {
    return strdup(left);
  } else {
    size_t size_left;
    size_t size_right;
    size_t i;
    char *out_str = NULL;
    size_left = strlen(left);
    size_right = strlen(right);
    out_str = malloc(size_left + size_right + 1);
    if (out_str != NULL) {
      for (i = 0; i < size_left; i++) {
        out_str[i] = left[i];
      }
      for (i = 0; i < size_right; i++) {
        out_str[size_left + i] = right[i];
      }
      out_str[size_left + size_right] = '\0';
    }
    return out_str;
  }
}


x86 assembly (clang, -O0):
<join_str_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1175 <join_str_double+0x45>
cmpq   $0x0,-0x18(%rbp)
jne    1163 <join_str_double+0x33>
movq   $0x0,-0x8(%rbp)
jmp    126a <join_str_double+0x13a>
mov    -0x18(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    126a <join_str_double+0x13a>
cmpq   $0x0,-0x18(%rbp)
jne    1192 <join_str_double+0x62>
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    126a <join_str_double+0x13a>
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1262 <join_str_double+0x132>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1211 <join_str_double+0xe1>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11dc <join_str_double+0xac>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1252 <join_str_double+0x122>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1219 <join_str_double+0xe9>
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<join_str_double>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
test   %rdi,%rdi
je     11b8 <join_str_double+0x78>
mov    %rdi,%rbx
test   %r15,%r15
je     11d2 <join_str_double+0x92>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
lea    (%rax,%r12,1),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     11c2 <join_str_double+0x82>
mov    %rax,%r14
test   %r12,%r12
je     1197 <join_str_double+0x57>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
lea    (%r12,%r13,1),%rbx
test   %r13,%r13
je     11b1 <join_str_double+0x71>
mov    %r14,%rdi
add    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%r14,%rbx,1)
jmp    11c5 <join_str_double+0x85>
test   %r15,%r15
je     11c2 <join_str_double+0x82>
mov    %r15,%rdi
jmp    11d5 <join_str_double+0x95>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1060 <strdup@plt>

LLVM IR (-O0):
define i8* @join_str_double(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %12
store i8* null, i8** %3
br label %79
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = call i8* @strdup(i8* %17)
store i8* %18, i8** %3
br label %79
19: ; preds = %2
%20 = load i8*, i8** %5
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = call i8* @strdup(i8* %23)
store i8* %24, i8** %3
br label %79
25: ; preds = %19
store i8* null, i8** %9
%26 = load i8*, i8** %4
%27 = call i64 @strlen(i8* %26)
store i64 %27, i64* %6
%28 = load i8*, i8** %5
%29 = call i64 @strlen(i8* %28)
store i64 %29, i64* %7
%30 = load i64, i64* %6
%31 = load i64, i64* %7
%32 = add i64 %30, %31
%33 = add i64 %32, 1
%34 = call i8* @malloc(i64 %33)
store i8* %34, i8** %9
%35 = load i8*, i8** %9
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %77
37: ; preds = %25
store i64 0, i64* %8
br label %38
38: ; preds = %50, %37
%39 = load i64, i64* %8
%40 = load i64, i64* %6
%41 = icmp ult i64 %39, %40
br i1 %41, label %42, label %53
42: ; preds = %38
%43 = load i8*, i8** %4
%44 = load i64, i64* %8
%45 = getelementptr inbounds i8, i8* %43, i64 %44
%46 = load i8, i8* %45
%47 = load i8*, i8** %9
%48 = load i64, i64* %8
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8 %46, i8* %49
br label %50
50: ; preds = %42
%51 = load i64, i64* %8
%52 = add i64 %51, 1
store i64 %52, i64* %8
br label %38
53: ; preds = %38
store i64 0, i64* %8
br label %54
54: ; preds = %68, %53
%55 = load i64, i64* %8
%56 = load i64, i64* %7
%57 = icmp ult i64 %55, %56
br i1 %57, label %58, label %71
58: ; preds = %54
%59 = load i8*, i8** %5
%60 = load i64, i64* %8
%61 = getelementptr inbounds i8, i8* %59, i64 %60
%62 = load i8, i8* %61
%63 = load i8*, i8** %9
%64 = load i64, i64* %6
%65 = load i64, i64* %8
%66 = add i64 %64, %65
%67 = getelementptr inbounds i8, i8* %63, i64 %66
store i8 %62, i8* %67
br label %68
68: ; preds = %58
%69 = load i64, i64* %8
%70 = add i64 %69, 1
store i64 %70, i64* %8
br label %54
71: ; preds = %54
%72 = load i8*, i8** %9
%73 = load i64, i64* %6
%74 = load i64, i64* %7
%75 = add i64 %73, %74
%76 = getelementptr inbounds i8, i8* %72, i64 %75
store i8 0, i8* %76
br label %77
77: ; preds = %71, %25
%78 = load i8*, i8** %9
store i8* %78, i8** %3
br label %79
79: ; preds = %77, %22, %16, %15
%80 = load i8*, i8** %3
ret i8* %80
}

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