#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);
int /*<<< orphan*/ free(char *);
char *malloc_err(size_t);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char const *);
char *strncat(char *, char const *, size_t);
char *ResizedAppend(char *src1, const char *src2, char dealloc) {
  char *temp;
  size_t size1, size2;
  (assert((src1 != NULL) && (src2 != NULL)));
  size1 = strlen(src1);
  size2 = strlen(src2);
  temp = malloc_err(size1 + size2 + 1);
  strcpy(temp, src1);
  if (dealloc)
    free(src1);
  return (strncat(temp, src2, size2));
}


x86 assembly (clang, -O0):
<ResizedAppend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x31(%rbp)
je     1190 <ResizedAppend+0x30>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
add    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1080 <malloc_err@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
cmpb   $0x0,-0x11(%rbp)
je     11ec <ResizedAppend+0x8c>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <strncat@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ResizedAppend>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
lea    (%rax,%rbp,1),%rdi
add    $0x1,%rdi
call   1080 <malloc_err@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
test   %r15b,%r15b
je     11c5 <ResizedAppend+0x65>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <strncat@plt>

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

LLVM IR (-O2):
define i8* @ResizedAppend(i8* %0, i8* %1, i8 signext %2) {
%4 = icmp ne i8* %0, null
%5 = icmp ne i8* %1, null
%6 = and i1 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%10 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%11 = add i64 %9, 1
%12 = add i64 %11, %10
%13 = tail call i8* @malloc_err(i64 %12)
%14 = tail call i32 @strcpy(i8* %13, i8* %0)
%15 = icmp eq i8 %2, 0
br i1 %15, label %18, label %16
16: ; preds = %3
%17 = tail call i32 @free(i8* %0)
br label %18
18: ; preds = %16, %3
%19 = tail call i8* @strncat(i8* dereferenceable(1) %13, i8* %1, i64 %10)
ret i8* %13
}