#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 */
typedef int /*<<< orphan*/ tab;

/* Variables and functions */
int /*<<< orphan*/ free(void *);
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 *tab;
  if ((tab = (char *)malloc(sizeof(tab) *
                            (ft_strlen(s1) + ft_strlen(s2) + 1))) == NULL)
    return (NULL);
  ft_strcpy(tab, s1);
  ft_strcat(tab, s2);
  free((void *)s1);
  return (tab);
}


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   1050 <ft_strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <ft_strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a7 <ft_strjoin+0x57>
movq   $0x0,-0x8(%rbp)
jmp    11d2 <ft_strjoin+0x82>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <ft_strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <ft_strcat@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@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   1050 <ft_strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <ft_strlen@plt>
add    %ebx,%eax
lea    0x8(,%rax,8),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11a0 <ft_strjoin+0x50>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <ft_strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <ft_strcat@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11a2 <ft_strjoin+0x52>
xor    %ebx,%ebx
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 i32 @ft_strlen(i8* %7)
%9 = load i8*, i8** %5
%10 = call i32 @ft_strlen(i8* %9)
%11 = add nsw i32 %8, %10
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = mul i64 8, %13
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %2
store i8* null, i8** %3
br label %30
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = load i8*, i8** %4
%23 = call i32 @ft_strcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %6
%25 = load i8*, i8** %5
%26 = call i32 @ft_strcat(i8* %24, i8* %25)
%27 = load i8*, i8** %4
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %6
store i8* %29, i8** %3
br label %30
30: ; preds = %20, %19
%31 = load i8*, i8** %3
ret i8* %31
}

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