#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_free(char *);
int ft_splitcount(char **);
char *ft_strdup(char *);
char *ft_strjoin(char *, char *);
char *ft_strjoinc(char *, char);
char *ft_strglue(char **split, char glue) {
  int i;
  int nb_split;
  char *out;
  char *tmp;
  char *tmp2;
  i = 0;
  out = ft_strdup("");
  nb_split = ft_splitcount(split);
  while (split[i]) {
    tmp = (i > 0 && i < nb_split ? ft_strjoinc(out, glue) : ft_strdup(""));
    tmp2 = ft_strjoin(tmp, split[i]);
    i++;
    ft_free(out);
    ft_free(tmp);
    out = tmp2;
  }
  return (out);
}


x86 assembly (clang, -O0):
<ft_strglue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xe90(%rip),%rdi
call   1050 <ft_strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <ft_splitcount@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     121d <ft_strglue+0xcd>
cmpl   $0x0,-0x10(%rbp)
jle    11c4 <ft_strglue+0x74>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c4 <ft_strglue+0x74>
mov    -0x20(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1030 <ft_strjoinc@plt>
mov    %rax,-0x38(%rbp)
jmp    11d4 <ft_strglue+0x84>
lea    0xe35(%rip),%rdi
call   1050 <ft_strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <ft_strjoin@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <ft_free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <ft_free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1185 <ft_strglue+0x35>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strglue>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xe96(%rip),%rdi
call   1050 <ft_strdup@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1070 <ft_splitcount@plt>
cmpq   $0x0,(%r14)
je     11fb <ft_strglue+0xab>
cltq
mov    %rax,0x10(%rsp)
xor    %r12d,%r12d
movsbl %bpl,%eax
mov    %eax,0xc(%rsp)
jmp    11e1 <ft_strglue+0x91>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe59(%rip),%rdi
call   1050 <ft_strdup@plt>
mov    %rax,%rbp
mov    (%r14,%r12,8),%rsi
mov    %rax,%rdi
call   1060 <ft_strjoin@plt>
mov    %rax,%rbx
lea    0x1(%r12),%r15
mov    %r13,%rdi
call   1040 <ft_free@plt>
mov    %rbp,%rdi
call   1040 <ft_free@plt>
cmpq   $0x0,0x8(%r14,%r12,8)
mov    %r15,%r12
mov    %rbx,%r13
je     11fe <ft_strglue+0xae>
test   %r12,%r12
je     11a0 <ft_strglue+0x50>
cmp    0x10(%rsp),%r12
jge    11a0 <ft_strglue+0x50>
mov    %r13,%rdi
mov    0xc(%rsp),%esi
call   1030 <ft_strjoinc@plt>
jmp    11ac <ft_strglue+0x5c>
mov    %r13,%rbx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @ft_strglue(i8** %0, i8 signext %1) {
%3 = alloca i8**
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8** %0, i8*** %3
store i8 %1, i8* %4
store i32 0, i32* %5
%10 = call i8* @ft_strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %7
%11 = load i8**, i8*** %3
%12 = call i32 @ft_splitcount(i8** %11)
store i32 %12, i32* %6
br label %13
13: ; preds = %33, %2
%14 = load i8**, i8*** %3
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %49
20: ; preds = %13
%21 = load i32, i32* %5
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i8*, i8** %7
%29 = load i8, i8* %4
%30 = call i8* @ft_strjoinc(i8* %28, i8 signext %29)
br label %33
31: ; preds = %23, %20
%32 = call i8* @ft_strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = phi i8* [ %30, %27 ], [ %32, %31 ]
store i8* %34, i8** %8
%35 = load i8*, i8** %8
%36 = load i8**, i8*** %3
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = call i8* @ft_strjoin(i8* %35, i8* %40)
store i8* %41, i8** %9
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
%44 = load i8*, i8** %7
%45 = call i32 @ft_free(i8* %44)
%46 = load i8*, i8** %8
%47 = call i32 @ft_free(i8* %46)
%48 = load i8*, i8** %9
store i8* %48, i8** %7
br label %13
49: ; preds = %13
%50 = load i8*, i8** %7
ret i8* %50
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @ft_strglue(i8** %0, i8 signext %1) {
%3 = tail call i8* @ft_strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @ft_splitcount(i8** %0)
%5 = load i8*, i8** %0
%6 = icmp eq i8* %5, null
br i1 %6, label %30, label %7
7: ; preds = %2
%8 = sext i32 %4 to i64
br label %9
9: ; preds = %7, %20
%10 = phi i64 [ 0, %7 ], [ %24, %20 ]
%11 = phi i8** [ %0, %7 ], [ %27, %20 ]
%12 = phi i8* [ %3, %7 ], [ %23, %20 ]
%13 = icmp ne i64 %10, 0
%14 = icmp slt i64 %10, %8
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = tail call i8* @ft_strjoinc(i8* %12, i8 signext %1)
br label %20
18: ; preds = %9
%19 = tail call i8* @ft_strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
%21 = phi i8* [ %17, %16 ], [ %19, %18 ]
%22 = load i8*, i8** %11
%23 = tail call i8* @ft_strjoin(i8* %21, i8* %22)
%24 = add nuw i64 %10, 1
%25 = tail call i32 @ft_free(i8* %12)
%26 = tail call i32 @ft_free(i8* %21)
%27 = getelementptr inbounds i8*, i8** %0, i64 %24
%28 = load i8*, i8** %27
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %9
30: ; preds = %20, %2
%31 = phi i8* [ %3, %2 ], [ %23, %20 ]
ret i8* %31
}