#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 *concat_three_str(size_t, char *, char const *, char *);
char *sliced_string(char const *, int, size_t);
size_t strlen(char const *);
char *add_cali(const char *treestr, int index_of_tmrca, const char *cali_info) {
  char *left_part, *right_part;
  size_t treelen = strlen(treestr);
  size_t buflen = 2 * treelen;
  left_part = sliced_string(treestr, 0, index_of_tmrca);
  right_part = sliced_string(treestr, index_of_tmrca, treelen);
  return concat_three_str(buflen, left_part, cali_info, right_part);
}


x86 assembly (clang, -O0):
<add_cali>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rdx
xor    %esi,%esi
call   1040 <sliced_string@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1040 <sliced_string@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <concat_three_str@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_cali>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r13
lea    (%rax,%rax,1),%r12
movslq %r15d,%rbp
mov    %rbx,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
call   1040 <sliced_string@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
call   1040 <sliced_string@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <concat_three_str@plt>

LLVM IR (-O0):
define i8* @add_cali(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %9
%13 = load i64, i64* %9
%14 = mul i64 2, %13
store i64 %14, i64* %10
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = call i8* @sliced_string(i8* %15, i32 0, i64 %17)
store i8* %18, i8** %7
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = load i64, i64* %9
%22 = call i8* @sliced_string(i8* %19, i32 %20, i64 %21)
store i8* %22, i8** %8
%23 = load i64, i64* %10
%24 = load i8*, i8** %7
%25 = load i8*, i8** %6
%26 = load i8*, i8** %8
%27 = call i8* @concat_three_str(i64 %23, i8* %24, i8* %25, i8* %26)
ret i8* %27
}

LLVM IR (-O2):
define i8* @add_cali(i8* %0, i32 %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = shl i64 %4, 1
%6 = sext i32 %1 to i64
%7 = tail call i8* @sliced_string(i8* %0, i32 0, i64 %6)
%8 = tail call i8* @sliced_string(i8* %0, i32 %1, i64 %4)
%9 = tail call i8* @concat_three_str(i64 %5, i8* %7, i8* %2, i8* %8)
ret i8* %9
}