#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(scalar_t__);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *gs_strcat_m(const char *dest, const char *src) {
  char *ptr;
  if (!dest || !src)
    return NULL;
  ptr = (char *)malloc(strlen(dest) + strlen(src) + 1);
  if (!ptr)
    return 0;
  strcpy(ptr, dest);
  strcat(ptr, src);
  return ptr;
}


x86 assembly (clang, -O0):
<gs_strcat_m>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1166 <gs_strcat_m+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1173 <gs_strcat_m+0x33>
movq   $0x0,-0x8(%rbp)
jmp    11d7 <gs_strcat_m+0x97>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b5 <gs_strcat_m+0x75>
movq   $0x0,-0x8(%rbp)
jmp    11d7 <gs_strcat_m+0x97>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gs_strcat_m>:
push   %r15
push   %r14
push   %rbx
xor    %ebx,%ebx
test   %rdi,%rdi
je     1196 <gs_strcat_m+0x56>
mov    %rsi,%r14
test   %rsi,%rsi
je     1196 <gs_strcat_m+0x56>
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     1194 <gs_strcat_m+0x54>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
jmp    1196 <gs_strcat_m+0x56>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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