#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 ft_strlen(char *);
int /*<<< orphan*/ ft_strncpy(char *, char *, int);
char *ft_strnew(int);
char *ft_strjoin(char *str1, char *str2) {
  char *res;
  res = ft_strnew(ft_strlen(str1) + ft_strlen(str2));
  ft_strncpy(res, str1, ft_strlen(str1));
  ft_strncpy(res + ft_strlen(str1), str2, ft_strlen(str2));
  return (res);
}


x86 assembly (clang, -O0):
<ft_strjoin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    -0x44(%rbp),%edi
add    %eax,%edi
call   1040 <ft_strnew@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1050 <ft_strncpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1050 <ft_strncpy@plt>
mov    -0x18(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strjoin>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <ft_strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <ft_strlen@plt>
add    %eax,%ebp
mov    %ebp,%edi
call   1040 <ft_strnew@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <ft_strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <ft_strncpy@plt>
mov    %rbx,%rdi
call   1030 <ft_strlen@plt>
movslq %eax,%rbx
add    %r15,%rbx
mov    %r14,%rdi
call   1030 <ft_strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <ft_strncpy@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @ft_strjoin(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @ft_strlen(i8* %6)
%8 = load i8*, i8** %4
%9 = call i32 @ft_strlen(i8* %8)
%10 = add nsw i32 %7, %9
%11 = call i8* @ft_strnew(i32 %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = load i8*, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @ft_strlen(i8* %14)
%16 = call i32 @ft_strncpy(i8* %12, i8* %13, i32 %15)
%17 = load i8*, i8** %5
%18 = load i8*, i8** %3
%19 = call i32 @ft_strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = load i8*, i8** %4
%23 = load i8*, i8** %4
%24 = call i32 @ft_strlen(i8* %23)
%25 = call i32 @ft_strncpy(i8* %21, i8* %22, i32 %24)
%26 = load i8*, i8** %5
ret i8* %26
}

LLVM IR (-O2):
define i8* @ft_strjoin(i8* %0, i8* %1) {
%3 = tail call i32 @ft_strlen(i8* %0)
%4 = tail call i32 @ft_strlen(i8* %1)
%5 = add nsw i32 %4, %3
%6 = tail call i8* @ft_strnew(i32 %5)
%7 = tail call i32 @ft_strlen(i8* %0)
%8 = tail call i32 @ft_strncpy(i8* %6, i8* %0, i32 %7)
%9 = tail call i32 @ft_strlen(i8* %0)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %6, i64 %10
%12 = tail call i32 @ft_strlen(i8* %1)
%13 = tail call i32 @ft_strncpy(i8* %11, i8* %1, i32 %12)
ret i8* %6
}