#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 *, size_t);
int /*<<< orphan*/ strcat(char *, char *);
char *cadena_concatenar(char *str, char *str_cpy, char sep,
                        size_t nueva_capacidad) {
  char *str_aux = realloc(str, nueva_capacidad);
  if (!str_aux)
    return NULL;
  strcat(str_aux, str_cpy);
  str_aux[nueva_capacidad - 2] = sep;
  str_aux[nueva_capacidad - 1] = '\0';
  return str_aux;
}


x86 assembly (clang, -O0):
<cadena_concatenar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <realloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1162 <cadena_concatenar+0x42>
movq   $0x0,-0x8(%rbp)
jmp    1199 <cadena_concatenar+0x79>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x19(%rbp),%dl
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x2,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cadena_concatenar>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rcx,%rsi
call   1030 <realloc@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1155 <cadena_concatenar+0x35>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
mov    %r14b,-0x2(%rbx,%rbp,1)
movb   $0x0,-0x1(%rbx,%rbp,1)
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @cadena_concatenar(i8* %0, i8* %1, i8 signext %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i64
%10 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8 %2, i8* %8
store i64 %3, i64* %9
%11 = load i8*, i8** %6
%12 = load i64, i64* %9
%13 = call i8* @realloc(i8* %11, i64 %12)
store i8* %13, i8** %10
%14 = load i8*, i8** %10
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %4
store i8* null, i8** %5
br label %31
17: ; preds = %4
%18 = load i8*, i8** %10
%19 = load i8*, i8** %7
%20 = call i32 @strcat(i8* %18, i8* %19)
%21 = load i8, i8* %8
%22 = load i8*, i8** %10
%23 = load i64, i64* %9
%24 = sub i64 %23, 2
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
%26 = load i8*, i8** %10
%27 = load i64, i64* %9
%28 = sub i64 %27, 1
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 0, i8* %29
%30 = load i8*, i8** %10
store i8* %30, i8** %5
br label %31
31: ; preds = %17, %16
%32 = load i8*, i8** %5
ret i8* %32
}

LLVM IR (-O2):
define i8* @cadena_concatenar(i8* nocapture %0, i8* %1, i8 signext %2, i64 %3) {
%5 = tail call i8* @realloc(i8* %0, i64 %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = tail call i32 @strcat(i8* %5, i8* %1)
%9 = add i64 %3, -2
%10 = getelementptr inbounds i8, i8* %5, i64 %9
store i8 %2, i8* %10
%11 = add i64 %3, -1
%12 = getelementptr inbounds i8, i8* %5, i64 %11
store i8 0, i8* %12
br label %13
13: ; preds = %4, %7
ret i8* %5
}