#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__ ft_memcpy(char *, char const *, size_t);
size_t ft_strlen(char const *);
char *ft_strnew(size_t);
char *ft_strjoin(char const *s1, char const *s2) {
  char *join;
  size_t len_s1;
  size_t len_s2;
  len_s1 = ft_strlen(s1);
  len_s2 = ft_strlen(s2);
  join = ft_strnew(len_s1 + len_s2 + 1);
  if (join == NULL)
    return (NULL);
  join = (char *)ft_memcpy(join, s1, len_s1);
  ft_memcpy(join + len_s1, s2, len_s2);
  return (join);
}


x86 assembly (clang, -O0):
<ft_strjoin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
add    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1040 <ft_strnew@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1187 <ft_strjoin+0x57>
movq   $0x0,-0x8(%rbp)
jmp    11b9 <ft_strjoin+0x89>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <ft_memcpy@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <ft_memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strjoin>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <ft_strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <ft_strlen@plt>
mov    %rax,%r15
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1040 <ft_strnew@plt>
test   %rax,%rax
je     1187 <ft_strjoin+0x57>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <ft_memcpy@plt>
mov    %rax,%r12
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <ft_memcpy@plt>
jmp    118a <ft_strjoin+0x5a>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @ft_strjoin(i8* %0, i8* %1) {
%3 = tail call i64 @ft_strlen(i8* %0)
%4 = tail call i64 @ft_strlen(i8* %1)
%5 = add i64 %3, 1
%6 = add i64 %5, %4
%7 = tail call i8* @ft_strnew(i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = tail call i64 @ft_memcpy(i8* %7, i8* %0, i64 %3)
%11 = inttoptr i64 %10 to i8*
%12 = getelementptr inbounds i8, i8* %11, i64 %3
%13 = tail call i64 @ft_memcpy(i8* %12, i8* %1, i64 %4)
br label %14
14: ; preds = %2, %9
%15 = phi i8* [ %11, %9 ], [ null, %2 ]
ret i8* %15
}