#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*/ ft_strcat(char *, char const *);
int /*<<< orphan*/ ft_strcpy(char *, char const *);
scalar_t__ ft_strlen(char const *);
char *ft_strnew(scalar_t__);
char *ft_strjoin(char const *s1, char const *s2) {
  char *str;
  str = ft_strnew(ft_strlen(s1) + ft_strlen(s2));
  if (str == NULL)
    return (NULL);
  ft_strcpy(str, s1);
  ft_strcat(str, s2);
  return (str);
}


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   1040 <ft_strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ft_strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
call   1060 <ft_strnew@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118e <ft_strjoin+0x4e>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <ft_strjoin+0x70>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <ft_strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <ft_strcat@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   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <ft_strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <ft_strlen@plt>
add    %rax,%rbx
mov    %rbx,%rdi
call   1060 <ft_strnew@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1184 <ft_strjoin+0x44>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <ft_strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <ft_strcat@plt>
mov    %rbx,%rax
pop    %rbx
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*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i64 @ft_strlen(i8* %7)
%9 = load i8*, i8** %5
%10 = call i64 @ft_strlen(i8* %9)
%11 = add nsw i64 %8, %10
%12 = call i8* @ft_strnew(i64 %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i8* null, i8** %3
br label %24
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = load i8*, i8** %4
%19 = call i32 @ft_strcpy(i8* %17, i8* %18)
%20 = load i8*, i8** %6
%21 = load i8*, i8** %5
%22 = call i32 @ft_strcat(i8* %20, i8* %21)
%23 = load i8*, i8** %6
store i8* %23, i8** %3
br label %24
24: ; preds = %16, %15
%25 = load i8*, i8** %3
ret i8* %25
}

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 nsw i64 %4, %3
%6 = tail call i8* @ft_strnew(i64 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @ft_strcpy(i8* %6, i8* %0)
%10 = tail call i32 @ft_strcat(i8* %6, i8* %1)
br label %11
11: ; preds = %2, %8
ret i8* %6
}