#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 *realloc(char *, scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
int str_cat(char **pstr, char *text) {
  char *p = realloc(*pstr, strlen(*pstr) + strlen(text) + 1);
  if (!p)
    return -1;
  *pstr = p;
  strcat(p, text);
  return 0;
}


x86 assembly (clang, -O0):
<str_cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdi
add    %rax,%rsi
add    $0x1,%rsi
call   1040 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1193 <str_cat+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <str_cat+0x82>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cat>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r12,%rax,1),%rsi
add    $0x1,%rsi
mov    %rbx,%rdi
call   1040 <realloc@plt>
test   %rax,%rax
je     117b <str_cat+0x4b>
mov    %rax,(%r15)
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
xor    %eax,%eax
jmp    1180 <str_cat+0x50>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @str_cat(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
%7 = load i8**, i8*** %4
%8 = load i8*, i8** %7
%9 = load i8**, i8*** %4
%10 = load i8*, i8** %9
%11 = call i64 @strlen(i8* %10)
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
%14 = add nsw i64 %11, %13
%15 = add nsw i64 %14, 1
%16 = call i8* @realloc(i8* %8, i64 %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %2
store i32 -1, i32* %3
br label %26
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = load i8**, i8*** %4
store i8* %21, i8** %22
%23 = load i8*, i8** %6
%24 = load i8*, i8** %5
%25 = call i32 @strcat(i8* %23, i8* %24)
store i32 0, i32* %3
br label %26
26: ; preds = %20, %19
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @str_cat(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = add i64 %4, 1
%7 = add i64 %6, %5
%8 = tail call i8* @realloc(i8* %3, i64 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %2
store i8* %8, i8** %0
%11 = tail call i32 @strcat(i8* %8, i8* %1)
br label %12
12: ; preds = %2, %10
%13 = phi i32 [ 0, %10 ], [ -1, %2 ]
ret i32 %13
}