#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(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strcat_without_alloc(char *s1, char *s2) {
  int old_size;
  char *t;
  if (s1) {
    old_size = strlen(s1);
  } else {
    old_size = 0;
  }
  t = malloc(sizeof(char) * (old_size + strlen(s2) + 1));
  if (s1) {
    strcpy(t, s1);
  }
  strcpy(t + old_size, s2);
  return t;
}


x86 assembly (clang, -O0):
<strcat_without_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     115c <strcat_without_alloc+0x2c>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
jmp    1163 <strcat_without_alloc+0x33>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a5 <strcat_without_alloc+0x75>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcat_without_alloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
test   %rdi,%rdi
je     1150 <strcat_without_alloc+0x20>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
jmp    1153 <strcat_without_alloc+0x23>
xor    %r15d,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %r12,%r12
je     117a <strcat_without_alloc+0x4a>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
movslq %r15d,%rax
mov    %rbx,%rdi
add    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @strcat_without_alloc(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %5
br label %13
12: ; preds = %2
store i32 0, i32* %5
br label %13
13: ; preds = %12, %9
%14 = load i32, i32* %5
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %14, %16
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = mul i64 1, %19
%21 = trunc i64 %20 to i32
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %6
%23 = load i8*, i8** %3
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %13
%26 = load i8*, i8** %6
%27 = load i8*, i8** %3
%28 = call i32 @strcpy(i8* %26, i8* %27)
br label %29
29: ; preds = %25, %13
%30 = load i8*, i8** %6
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8*, i8** %4
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = load i8*, i8** %6
ret i8* %36
}

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