#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 */
int StrLen(char *);
char *StrRealloc(char *, int);
int StrSize(char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *StrCat(char *d, char *s) {
  int l;
  l = StrLen(d);
  if (StrLen(s) + l > StrSize(d) - 1) {
    d = StrRealloc(d, StrLen(s) + l + 1);
  }
  strcpy(&(d[l]), s);
  return d;
}


x86 assembly (clang, -O0):
<StrCat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <StrLen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <StrLen@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <StrSize@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    11aa <StrCat+0x6a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <StrLen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
add    -0x14(%rbp),%esi
add    $0x1,%esi
call   1030 <StrRealloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StrCat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <StrLen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1050 <StrLen@plt>
mov    %eax,%ebp
add    %r15d,%ebp
mov    %rbx,%rdi
call   1060 <StrSize@plt>
cmp    %eax,%ebp
jl     1188 <StrCat+0x48>
mov    %r14,%rdi
call   1050 <StrLen@plt>
lea    (%r15,%rax,1),%esi
add    $0x1,%esi
mov    %rbx,%rdi
call   1030 <StrRealloc@plt>
mov    %rax,%rbx
movslq %r15d,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @StrCat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @StrLen(i8* %6)
store i32 %7, i32* %5
%8 = load i8*, i8** %4
%9 = call i32 @StrLen(i8* %8)
%10 = load i32, i32* %5
%11 = add nsw i32 %9, %10
%12 = load i8*, i8** %3
%13 = call i32 @StrSize(i8* %12)
%14 = sub nsw i32 %13, 1
%15 = icmp sgt i32 %11, %14
br i1 %15, label %16, label %24
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = load i8*, i8** %4
%19 = call i32 @StrLen(i8* %18)
%20 = load i32, i32* %5
%21 = add nsw i32 %19, %20
%22 = add nsw i32 %21, 1
%23 = call i8* @StrRealloc(i8* %17, i32 %22)
store i8* %23, i8** %3
br label %24
24: ; preds = %16, %2
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8*, i8** %4
%30 = call i32 @strcpy(i8* %28, i8* %29)
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
define i8* @StrCat(i8* %0, i8* %1) {
%3 = tail call i32 @StrLen(i8* %0)
%4 = tail call i32 @StrLen(i8* %1)
%5 = add nsw i32 %4, %3
%6 = tail call i32 @StrSize(i8* %0)
%7 = icmp slt i32 %5, %6
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = tail call i32 @StrLen(i8* %1)
%10 = add i32 %3, 1
%11 = add i32 %10, %9
%12 = tail call i8* @StrRealloc(i8* %0, i32 %11)
br label %13
13: ; preds = %8, %2
%14 = phi i8* [ %12, %8 ], [ %0, %2 ]
%15 = sext i32 %3 to i64
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = tail call i32 @strcpy(i8* %16, i8* %1)
ret i8* %14
}