#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 *cmalloc(short);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
int strlen(char *);
int strAttach(char **dst, char *src) {
  short len;
  char *t;
  if (*dst == NULL) {
    *dst = strdup(src);
    return 0;
  }
  len = strlen(*dst) + strlen(src) + 1;
  t = cmalloc(len);
  strcpy(t, *dst);
  strcat(t, src);
  free(*dst);
  *dst = t;
  return 1;
}


x86 assembly (clang, -O0):
<strAttach>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    119d <strAttach+0x3d>
mov    -0x18(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    120b <strAttach+0xab>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %ax,-0x1a(%rbp)
movswl -0x1a(%rbp),%edi
call   1060 <cmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strAttach>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
test   %rdi,%rdi
je     11b7 <strAttach+0x57>
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <strlen@plt>
add    %ebx,%eax
add    $0x1,%eax
movswl %ax,%edi
call   1060 <cmalloc@plt>
mov    %rax,%rbx
mov    (%r15),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    (%r15),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
jmp    11c4 <strAttach+0x64>
mov    %r14,%rdi
call   1080 <strdup@plt>
mov    %rax,%rbx
xor    %eax,%eax
mov    %rbx,(%r15)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @strAttach(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i16
%7 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
%8 = load i8**, i8*** %4
%9 = load i8*, i8** %8
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i8* @strdup(i8* %12)
%14 = load i8**, i8*** %4
store i8* %13, i8** %14
store i32 0, i32* %3
br label %38
15: ; preds = %2
%16 = load i8**, i8*** %4
%17 = load i8*, i8** %16
%18 = call i32 @strlen(i8* %17)
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %18, %20
%22 = add nsw i32 %21, 1
%23 = trunc i32 %22 to i16
store i16 %23, i16* %6
%24 = load i16, i16* %6
%25 = call i8* @cmalloc(i16 signext %24)
store i8* %25, i8** %7
%26 = load i8*, i8** %7
%27 = load i8**, i8*** %4
%28 = load i8*, i8** %27
%29 = call i32 @strcpy(i8* %26, i8* %28)
%30 = load i8*, i8** %7
%31 = load i8*, i8** %5
%32 = call i32 @strcat(i8* %30, i8* %31)
%33 = load i8**, i8*** %4
%34 = load i8*, i8** %33
%35 = call i32 @free(i8* %34)
%36 = load i8*, i8** %7
%37 = load i8**, i8*** %4
store i8* %36, i8** %37
store i32 1, i32* %3
br label %38
38: ; preds = %15, %11
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
define i32 @strAttach(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i8* @strdup(i8* %1)
br label %19
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %3)
%9 = tail call i32 @strlen(i8* %1)
%10 = add nsw i32 %9, %8
%11 = trunc i32 %10 to i16
%12 = add i16 %11, 1
%13 = tail call i8* @cmalloc(i16 signext %12)
%14 = load i8*, i8** %0
%15 = tail call i32 @strcpy(i8* %13, i8* %14)
%16 = tail call i32 @strcat(i8* %13, i8* %1)
%17 = load i8*, i8** %0
%18 = tail call i32 @free(i8* %17)
br label %19
19: ; preds = %7, %5
%20 = phi i8* [ %13, %7 ], [ %6, %5 ]
%21 = phi i32 [ 1, %7 ], [ 0, %5 ]
store i8* %20, i8** %0
ret i32 %21
}