#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 *, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *blStrcatalloc(char *instr, char *catstr) {
  int totLen;
  char *outstr = NULL;
  totLen = ((instr == NULL) ? 0 : strlen(instr)) +
           ((catstr == NULL) ? 0 : strlen(catstr));
  if ((outstr = realloc(instr, totLen + 1)) != NULL) {
    if (instr == NULL)
      outstr[0] = '\0';
    if (catstr != NULL)
      strcat(outstr, catstr);
  }
  return (outstr);
}


x86 assembly (clang, -O0):
<blStrcatalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    115d <blStrcatalloc+0x2d>
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
jmp    1169 <blStrcatalloc+0x39>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1184 <blStrcatalloc+0x54>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    1190 <blStrcatalloc+0x60>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x2c(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
call   1040 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11e7 <blStrcatalloc+0xb7>
cmpq   $0x0,-0x8(%rbp)
jne    11ca <blStrcatalloc+0x9a>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     11e2 <blStrcatalloc+0xb2>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
jmp    11e7 <blStrcatalloc+0xb7>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blStrcatalloc>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     115b <blStrcatalloc+0x2b>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
add    $0x1,%ebp
test   %r14,%r14
je     1165 <blStrcatalloc+0x35>
mov    %r14,%rdi
call   1030 <strlen@plt>
jmp    1167 <blStrcatalloc+0x37>
mov    $0x1,%ebp
test   %r14,%r14
jne    1151 <blStrcatalloc+0x21>
xor    %eax,%eax
add    %eax,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <realloc@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1190 <blStrcatalloc+0x60>
test   %rbx,%rbx
je     1198 <blStrcatalloc+0x68>
test   %r14,%r14
je     1190 <blStrcatalloc+0x60>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
movb   $0x0,0x0(%rbp)
test   %r14,%r14
jne    1185 <blStrcatalloc+0x55>
jmp    1190 <blStrcatalloc+0x60>

LLVM IR (-O0):
define i8* @blStrcatalloc(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
store i8* null, i8** %6
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
br label %13
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
br label %13
13: ; preds = %10, %9
%14 = phi i32 [ 0, %9 ], [ %12, %10 ]
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %13
br label %21
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
br label %21
21: ; preds = %18, %17
%22 = phi i32 [ 0, %17 ], [ %20, %18 ]
%23 = add nsw i32 %14, %22
store i32 %23, i32* %5
%24 = load i8*, i8** %3
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
%27 = call i8* @realloc(i8* %24, i32 %26)
store i8* %27, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %43
29: ; preds = %21
%30 = load i8*, i8** %3
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 0
store i8 0, i8* %34
br label %35
35: ; preds = %32, %29
%36 = load i8*, i8** %4
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load i8*, i8** %6
%40 = load i8*, i8** %4
%41 = call i32 @strcat(i8* %39, i8* %40)
br label %42
42: ; preds = %38, %35
br label %43
43: ; preds = %42, %21
%44 = load i8*, i8** %6
ret i8* %44
}

LLVM IR (-O2):
define i8* @blStrcatalloc(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %0)
%6 = add i32 %5, 1
br label %7
7: ; preds = %2, %4
%8 = phi i32 [ %6, %4 ], [ 1, %2 ]
%9 = icmp eq i8* %1, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @strlen(i8* %1)
br label %12
12: ; preds = %7, %10
%13 = phi i32 [ %11, %10 ], [ 0, %7 ]
%14 = add i32 %8, %13
%15 = tail call i8* @realloc(i8* %0, i32 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %22, label %17
17: ; preds = %12
br i1 %3, label %18, label %19
18: ; preds = %17
store i8 0, i8* %15
br label %19
19: ; preds = %18, %17
br i1 %9, label %22, label %20
20: ; preds = %19
%21 = tail call i32 @strcat(i8* %15, i8* %1)
br label %22
22: ; preds = %19, %20, %12
ret i8* %15
}