#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_memcpy(char *, char const *, size_t const);
size_t ft_strlen(char const *);
scalar_t__ malloc(size_t const);
char *ft_strjoin(const char *s1, const char *s2) {
  const size_t len1 = ft_strlen(s1);
  const size_t len2 = ft_strlen(s2);
  char *str;
  str = (char *)malloc(len1 + len2 + 1);
  if (!str)
    return (NULL);
  ft_memcpy(str, s1, len1);
  ft_memcpy(str + len1, s2, len2);
  str[len1 + len2] = 0;
  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   1030 <ft_strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1187 <ft_strjoin+0x57>
movq   $0x0,-0x8(%rbp)
jmp    11c5 <ft_strjoin+0x95>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <ft_memcpy@plt>
mov    -0x30(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <ft_memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strjoin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <ft_strlen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <ft_strlen@plt>
mov    %rax,%r13
lea    (%rax,%r12,1),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1194 <ft_strjoin+0x64>
mov    %rax,%rbx
mov    %r13,%rbp
add    %r12,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <ft_memcpy@plt>
mov    %rbx,%rdi
add    %r12,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1050 <ft_memcpy@plt>
movb   $0x0,(%rbx,%rbp,1)
jmp    1196 <ft_strjoin+0x66>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
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*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
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* %6
%11 = load i8*, i8** %5
%12 = call i64 @ft_strlen(i8* %11)
store i64 %12, i64* %7
%13 = load i64, i64* %6
%14 = load i64, i64* %7
%15 = add i64 %13, %14
%16 = add i64 %15, 1
%17 = call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %2
store i8* null, i8** %3
br label %39
22: ; preds = %2
%23 = load i8*, i8** %8
%24 = load i8*, i8** %4
%25 = load i64, i64* %6
%26 = call i32 @ft_memcpy(i8* %23, i8* %24, i64 %25)
%27 = load i8*, i8** %8
%28 = load i64, i64* %6
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = load i8*, i8** %5
%31 = load i64, i64* %7
%32 = call i32 @ft_memcpy(i8* %29, i8* %30, i64 %31)
%33 = load i8*, i8** %8
%34 = load i64, i64* %6
%35 = load i64, i64* %7
%36 = add i64 %34, %35
%37 = getelementptr inbounds i8, i8* %33, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %8
store i8* %38, i8** %3
br label %39
39: ; preds = %22, %21
%40 = load i8*, i8** %3
ret i8* %40
}

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