#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 *find_non_cali_pointer(char *);
char *get_exists_cali(char *);
int /*<<< orphan*/ printf(char *, char const *);
char *sliced_string(char const *, int, size_t);
size_t strlen(char const *);
char *modify_exists_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);
  printf("[Label Exists]:          %s  [- Old]\n", get_exists_cali(right_part));
  printf("[Label Replaced By]:     %s  [+ New]\n", cali_info);
  right_part = find_non_cali_pointer(right_part);
  return concat_three_str(buflen, left_part, cali_info, right_part);
}


x86 assembly (clang, -O0):
<modify_exists_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   1050 <sliced_string@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1050 <sliced_string@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <get_exists_cali@plt>
mov    %rax,%rsi
lea    0xe3a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <find_non_cali_pointer@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1080 <concat_three_str@plt>
add    $0x40,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@.str = [38 x i8] c"[Label Exists]: %s [- Old]\0A\00"
@.str.1 = [38 x i8] c"[Label Replaced By]: %s [+ New]\0A\00"
define i8* @modify_exists_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 i8*, i8** %8
%24 = call i8* @get_exists_cali(i8* %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %6
%27 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %8
%29 = call i8* @find_non_cali_pointer(i8* %28)
store i8* %29, i8** %8
%30 = load i64, i64* %10
%31 = load i8*, i8** %7
%32 = load i8*, i8** %6
%33 = load i8*, i8** %8
%34 = call i8* @concat_three_str(i64 %30, i8* %31, i8* %32, i8* %33)
ret i8* %34
}

LLVM IR (-O2):
@.str = [38 x i8] c"[Label Exists]: %s [- Old]\0A\00"
@.str.1 = [38 x i8] c"[Label Replaced By]: %s [+ New]\0A\00"
define i8* @modify_exists_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* @get_exists_cali(i8* %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%12 = tail call i8* @find_non_cali_pointer(i8* %8)
%13 = tail call i8* @concat_three_str(i64 %5, i8* %7, i8* %2, i8* %12)
ret i8* %13
}