#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 */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
unsigned char *malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
unsigned char *catlloc_new_str(unsigned char *s1, int n1, unsigned char *s2,
                               int n2) {
  assert(s1 != NULL);
  unsigned char *new_string;
  if (s1 == NULL) {
    new_string = malloc(n2);
    memcpy(new_string, s2, n2);
  } else {
    new_string = malloc(n1 + n2);
    memcpy(new_string, s1, n1);
    memcpy(new_string + n1, s2, n2);
  }
  return new_string;
}


x86 assembly (clang, -O0):
<catlloc_new_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
jne    1184 <catlloc_new_str+0x54>
mov    -0x1c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
jmp    11ba <catlloc_new_str+0x8a>
mov    -0xc(%rbp),%edi
add    -0x1c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<catlloc_new_str>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
test   %rbx,%rbx
je     117a <catlloc_new_str+0x4a>
lea    (%r15,%r12,1),%edi
call   1050 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
movslq %r12d,%rdi
add    %r13,%rdi
jmp    1188 <catlloc_new_str+0x58>
mov    %r15d,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
mov    %rax,%r13
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <memcpy@plt>
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @catlloc_new_str(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %23
16: ; preds = %4
%17 = load i32, i32* %8
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %9
%19 = load i8*, i8** %9
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = call i32 @memcpy(i8* %19, i8* %20, i32 %21)
br label %39
23: ; preds = %4
%24 = load i32, i32* %6
%25 = load i32, i32* %8
%26 = add nsw i32 %24, %25
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %9
%28 = load i8*, i8** %9
%29 = load i8*, i8** %5
%30 = load i32, i32* %6
%31 = call i32 @memcpy(i8* %28, i8* %29, i32 %30)
%32 = load i8*, i8** %9
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8*, i8** %7
%37 = load i32, i32* %8
%38 = call i32 @memcpy(i8* %35, i8* %36, i32 %37)
br label %39
39: ; preds = %23, %16
%40 = load i8*, i8** %9
ret i8* %40
}

LLVM IR (-O2):
define i8* @catlloc_new_str(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp ne i8* %0, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp eq i8* %0, null
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i8* @malloc(i32 %3)
br label %17
11: ; preds = %4
%12 = add nsw i32 %3, %1
%13 = tail call i8* @malloc(i32 %12)
%14 = tail call i32 @memcpy(i8* %13, i8* %0, i32 %1)
%15 = sext i32 %1 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
br label %17
17: ; preds = %11, %9
%18 = phi i8* [ %16, %11 ], [ %10, %9 ]
%19 = phi i8* [ %13, %11 ], [ %10, %9 ]
%20 = tail call i32 @memcpy(i8* %18, i8* %2, i32 %3)
ret i8* %19
}