#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 *);
int ft_strlen(char const *);
scalar_t__ malloc(int);
char *ft_strjoin(char const *s1, char const *s2) {
  char *new;
  int len;
  len = ft_strlen(s1) + ft_strlen(s2);
  if (!(new = (char *)malloc((len + 1) * sizeof(char))))
    return (NULL);
  ft_strcpy(new, s1);
  ft_strcat(new, s2);
  new[len] = '\0';
  return (new);
}


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    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ft_strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    119d <ft_strjoin+0x5d>
movq   $0x0,-0x8(%rbp)
jmp    11cb <ft_strjoin+0x8b>
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
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
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   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <ft_strlen@plt>
mov    %eax,%r13d
mov    %r14,%rdi
call   1040 <ft_strlen@plt>
mov    %eax,%r12d
lea    (%r12,%r13,1),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1198 <ft_strjoin+0x58>
mov    %rax,%rbx
add    %r13d,%r12d
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <ft_strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <ft_strcat@plt>
movslq %r12d,%rax
movb   $0x0,(%rbx,%rax,1)
jmp    119a <ft_strjoin+0x5a>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
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 i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32 @ft_strlen(i8* %8)
%10 = load i8*, i8** %5
%11 = call i32 @ft_strlen(i8* %10)
%12 = add nsw i32 %9, %11
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %2
store i8* null, i8** %3
br label %34
22: ; preds = %2
%23 = load i8*, i8** %6
%24 = load i8*, i8** %4
%25 = call i32 @ft_strcpy(i8* %23, i8* %24)
%26 = load i8*, i8** %6
%27 = load i8*, i8** %5
%28 = call i32 @ft_strcat(i8* %26, i8* %27)
%29 = load i8*, i8** %6
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
%33 = load i8*, i8** %6
store i8* %33, i8** %3
br label %34
34: ; preds = %22, %21
%35 = load i8*, i8** %3
ret i8* %35
}

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 = add nsw i32 %5, 1
%7 = tail call i64 @malloc(i32 %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_strcpy(i8* %8, i8* %0)
%12 = tail call i32 @ft_strcat(i8* %8, i8* %1)
%13 = sext i32 %5 to i64
%14 = getelementptr inbounds i8, i8* %8, i64 %13
store i8 0, i8* %14
br label %15
15: ; preds = %2, %10
%16 = phi i8* [ %8, %10 ], [ null, %2 ]
ret i8* %16
}