#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_strcpy(char *, char const *);
int ft_strlen(char const *);
char *ft_strnew(int);
char *ft_strjoin(char const *s1, char const *s2) {
  char *str;
  str = ft_strnew(ft_strlen(s1) + ft_strlen(s2) + 1);
  if (str != 0) {
    ft_strcpy(str, s1);
    ft_strcpy(str + ft_strlen(s1), s2);
  }
  return (str);
}


x86 assembly (clang, -O0):
<ft_strjoin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ft_strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ft_strlen@plt>
mov    -0x1c(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1050 <ft_strnew@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a1 <ft_strjoin+0x71>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <ft_strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ft_strlen@plt>
mov    -0x28(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <ft_strcpy@plt>
mov    -0x18(%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    %eax,%ebx
mov    %r14,%rdi
call   1040 <ft_strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1050 <ft_strnew@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1180 <ft_strjoin+0x50>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <ft_strcpy@plt>
mov    %r15,%rdi
call   1040 <ft_strlen@plt>
cltq
mov    %rbx,%rdi
add    %rax,%rdi
mov    %r14,%rsi
call   1030 <ft_strcpy@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*
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 = add nsw i32 %10, 1
%12 = call i8* @ft_strnew(i32 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %26
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = load i8*, i8** %3
%18 = call i32 @ft_strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %5
%20 = load i8*, i8** %3
%21 = call i32 @ft_strlen(i8* %20)
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8*, i8** %4
%25 = call i32 @ft_strcpy(i8* %23, i8* %24)
br label %26
26: ; preds = %15, %2
%27 = load i8*, i8** %5
ret i8* %27
}

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 i32 %3, 1
%6 = add i32 %5, %4
%7 = tail call i8* @ft_strnew(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = tail call i32 @ft_strcpy(i8* %7, i8* %0)
%11 = tail call i32 @ft_strlen(i8* %0)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %7, i64 %12
%14 = tail call i32 @ft_strcpy(i8* %13, i8* %1)
br label %15
15: ; preds = %9, %2
ret i8* %7
}