#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 */
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, unsigned int);
scalar_t__ realloc(char *, unsigned int);
char *strcat(char *, char const *);
int strlen(char const *);
char *Strcat(char *left, const char *right) {
  int zero = 0;
  unsigned size;
  if ((right == (char *)NULL) || (*right == '\0') ||
      ((left = (char *)((zero = (left == (char *)NULL))
                            ? malloc(size = strlen(right) + 1)
                            : realloc(left, size = strlen(left) +
                                                   strlen(right) + 1))) ==
       (char *)NULL)) {
    return (left);
  }
  if (zero) {
    memset(left, 0, size);
  }
  return (strcat(left, right));
}


x86 assembly (clang, -O0):
<Strcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1208 <Strcat+0xb8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1208 <Strcat+0xb8>
cmpq   $0x0,-0x10(%rbp)
sete   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x1c(%rbp)
test   $0x1,%al
jne    11a2 <Strcat+0x52>
jmp    11c1 <Strcat+0x71>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
mov    %edi,-0x20(%rbp)
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
jmp    11f6 <Strcat+0xa6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rdi
add    %eax,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
call   1060 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1215 <Strcat+0xc5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    123e <Strcat+0xee>
cmpl   $0x0,-0x1c(%rbp)
je     122d <Strcat+0xdd>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Strcat>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
test   %rsi,%rsi
je     11ca <Strcat+0x7a>
mov    %rsi,%r14
cmpb   $0x0,(%rsi)
je     11ca <Strcat+0x7a>
test   %rbx,%rbx
je     1193 <Strcat+0x43>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rbp,1),%esi
add    $0x1,%esi
mov    %rbx,%rdi
call   1060 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11bb <Strcat+0x6b>
jmp    11c8 <Strcat+0x78>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11c8 <Strcat+0x78>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
jmp    11ca <Strcat+0x7a>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @Strcat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %37, label %10
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %37, label %15
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = icmp eq i8* %16, null
%18 = zext i1 %17 to i32
store i32 %18, i32* %6
br i1 %17, label %19, label %24
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
%23 = call i64 @malloc(i32 %22)
br label %33
24: ; preds = %15
%25 = load i8*, i8** %4
%26 = load i8*, i8** %4
%27 = call i32 @strlen(i8* %26)
%28 = load i8*, i8** %5
%29 = call i32 @strlen(i8* %28)
%30 = add nsw i32 %27, %29
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
%32 = call i64 @realloc(i8* %25, i32 %31)
br label %33
33: ; preds = %24, %19
%34 = phi i64 [ %23, %19 ], [ %32, %24 ]
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %4
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %39
37: ; preds = %33, %10, %2
%38 = load i8*, i8** %4
store i8* %38, i8** %3
br label %50
39: ; preds = %33
%40 = load i32, i32* %6
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = load i8*, i8** %4
%44 = load i32, i32* %7
%45 = call i32 @memset(i8* %43, i32 0, i32 %44)
br label %46
46: ; preds = %42, %39
%47 = load i8*, i8** %4
%48 = load i8*, i8** %5
%49 = call i8* @strcat(i8* %47, i8* %48)
store i8* %49, i8** %3
br label %50
50: ; preds = %46, %37
%51 = load i8*, i8** %3
ret i8* %51
}

LLVM IR (-O2):
define i8* @Strcat(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %28, label %4
4: ; preds = %2
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
br i1 %6, label %28, label %7
7: ; preds = %4
%8 = icmp eq i8* %0, null
br i1 %8, label %9, label %15
9: ; preds = %7
%10 = tail call i32 @strlen(i8* %1)
%11 = add nsw i32 %10, 1
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = icmp eq i64 %12, 0
br i1 %14, label %28, label %23
15: ; preds = %7
%16 = tail call i32 @strlen(i8* %0)
%17 = tail call i32 @strlen(i8* %1)
%18 = add i32 %16, 1
%19 = add i32 %18, %17
%20 = tail call i64 @realloc(i8* %0, i32 %19)
%21 = inttoptr i64 %20 to i8*
%22 = icmp eq i64 %20, 0
br i1 %22, label %28, label %25
23: ; preds = %9
%24 = tail call i32 @memset(i8* %13, i32 0, i32 %11)
br label %25
25: ; preds = %15, %23
%26 = phi i8* [ %13, %23 ], [ %21, %15 ]
%27 = tail call i8* @strcat(i8* %26, i8* %1)
br label %28
28: ; preds = %15, %2, %4, %9, %25
%29 = phi i8* [ %26, %25 ], [ %0, %2 ], [ %0, %4 ], [ null, %9 ], [ null, %15 ]
ret i8* %29
}