#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);
scalar_t__ malloc(size_t);
char *ft_strnjoin(const char *s1, size_t len1, const char *s2, size_t len2) {
  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_strnjoin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1165 <ft_strnjoin+0x45>
movq   $0x0,-0x8(%rbp)
jmp    11a3 <ft_strnjoin+0x83>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <ft_memcpy@plt>
mov    -0x30(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <ft_memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x18(%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_strnjoin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
lea    (%rcx,%rsi,1),%rdi
add    $0x1,%rdi
call   1030 <malloc@plt>
test   %rax,%rax
je     1175 <ft_strnjoin+0x55>
mov    %rax,%rbx
lea    (%r14,%r12,1),%rbp
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1040 <ft_memcpy@plt>
mov    %rbx,%rdi
add    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <ft_memcpy@plt>
movb   $0x0,(%rbx,%rbp,1)
jmp    1177 <ft_strnjoin+0x57>
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_strnjoin(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%11 = load i64, i64* %7
%12 = load i64, i64* %9
%13 = add i64 %11, %12
%14 = add i64 %13, 1
%15 = call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %10
%17 = load i8*, i8** %10
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %4
store i8* null, i8** %5
br label %37
20: ; preds = %4
%21 = load i8*, i8** %10
%22 = load i8*, i8** %6
%23 = load i64, i64* %7
%24 = call i32 @ft_memcpy(i8* %21, i8* %22, i64 %23)
%25 = load i8*, i8** %10
%26 = load i64, i64* %7
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = load i8*, i8** %8
%29 = load i64, i64* %9
%30 = call i32 @ft_memcpy(i8* %27, i8* %28, i64 %29)
%31 = load i8*, i8** %10
%32 = load i64, i64* %7
%33 = load i64, i64* %9
%34 = add i64 %32, %33
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %10
store i8* %36, i8** %5
br label %37
37: ; preds = %20, %19
%38 = load i8*, i8** %5
ret i8* %38
}

LLVM IR (-O2):
define i8* @ft_strnjoin(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = add i64 %3, %1
%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 = %4
%11 = tail call i32 @ft_memcpy(i8* %8, i8* %0, i64 %1)
%12 = getelementptr inbounds i8, i8* %8, i64 %1
%13 = tail call i32 @ft_memcpy(i8* %12, i8* %2, i64 %3)
%14 = getelementptr inbounds i8, i8* %8, i64 %5
store i8 0, i8* %14
br label %15
15: ; preds = %4, %10
%16 = phi i8* [ %8, %10 ], [ null, %4 ]
ret i8* %16
}