#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 */
typedef size_t ssize_t;

/* Variables and functions */
char *ft_strndup(char *, size_t);
char *ft_strnjoin(char *, size_t, char *, size_t);
void merge(char **buffer, char *buf, ssize_t ret, size_t *bufsize) {
  char *ptr;
  ptr = *buffer;
  if (ptr) {
    *buffer = ft_strnjoin(ptr, *bufsize, buf, ret);
    *bufsize += ret;
  } else {
    *buffer = ft_strndup(buf, ret);
    *bufsize = ret;
  }
}


x86 assembly (clang, -O0):
<merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1183 <merge+0x63>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1040 <ft_strnjoin@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
jmp    11a5 <merge+0x85>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <ft_strndup@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%rdx
mov    %rdi,%r15
mov    (%rdi),%rdi
test   %rdi,%rdi
je     114c <merge+0x2c>
mov    (%r14),%rsi
mov    %rbx,%rcx
call   1040 <ft_strnjoin@plt>
mov    %rax,(%r15)
add    (%r14),%rbx
jmp    115a <merge+0x3a>
mov    %rdx,%rdi
mov    %rbx,%rsi
call   1030 <ft_strndup@plt>
mov    %rax,(%r15)
mov    %rbx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @merge(i8** nocapture %0, i8* %1, i64 %2, i64* nocapture %3) {
%5 = load i8*, i8** %0
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = load i64, i64* %3
%9 = tail call i8* @ft_strnjoin(i8* %5, i64 %8, i8* %1, i64 %2)
store i8* %9, i8** %0
%10 = load i64, i64* %3
%11 = add i64 %10, %2
br label %14
12: ; preds = %4
%13 = tail call i8* @ft_strndup(i8* %1, i64 %2)
store i8* %13, i8** %0
br label %14
14: ; preds = %12, %7
%15 = phi i64 [ %2, %12 ], [ %11, %7 ]
store i64 %15, i64* %3
ret void
}