#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*/ printf(char *, char const *);
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strlen(char *);
char *implode(const char *glue, const char **array, char *str) {
  while (*array) {
    if (strlen(str))
      strcat(str, glue);
    printf("%s\n", *array);
    strcat(str, *array);
    array++;
  }
  return str;
}


x86 assembly (clang, -O0):
<implode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11a6 <implode+0x76>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
je     1172 <implode+0x42>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1144 <implode+0x14>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<implode>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    (%rsi),%rsi
test   %rsi,%rsi
je     1186 <implode+0x66>
mov    %rdi,%r15
lea    0xec0(%rip),%r12
jmp    1170 <implode+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1030 <printf@plt>
mov    (%rbx),%rsi
mov    %r14,%rdi
call   1040 <strcat@plt>
mov    0x8(%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
je     1186 <implode+0x66>
cmpb   $0x0,(%r14)
je     1150 <implode+0x30>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
mov    (%rbx),%rsi
jmp    1150 <implode+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define i8* @implode(i8* %0, i8** %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
br label %7
7: ; preds = %19, %3
%8 = load i8**, i8*** %5
%9 = load i8*, i8** %8
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %29
11: ; preds = %7
%12 = load i8*, i8** %6
%13 = call i64 @strlen(i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i8*, i8** %6
%17 = load i8*, i8** %4
%18 = call i32 @strcat(i8* %16, i8* %17)
br label %19
19: ; preds = %15, %11
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %6
%24 = load i8**, i8*** %5
%25 = load i8*, i8** %24
%26 = call i32 @strcat(i8* %23, i8* %25)
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i32 1
store i8** %28, i8*** %5
br label %7
29: ; preds = %7
%30 = load i8*, i8** %6
ret i8* %30
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define i8* @implode(i8* %0, i8** nocapture %1, i8* returned %2) {
%4 = load i8*, i8** %1
%5 = icmp eq i8* %4, null
br i1 %5, label %22, label %6
6: ; preds = %3, %14
%7 = phi i8* [ %20, %14 ], [ %4, %3 ]
%8 = phi i8** [ %19, %14 ], [ %1, %3 ]
%9 = load i8, i8* %2
%10 = icmp eq i8 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = tail call i32 @strcat(i8* %2, i8* %0)
%13 = load i8*, i8** %8
br label %14
14: ; preds = %11, %6
%15 = phi i8* [ %13, %11 ], [ %7, %6 ]
%16 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %8
%18 = tail call i32 @strcat(i8* %2, i8* %17)
%19 = getelementptr inbounds i8*, i8** %8, i64 1
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %6
22: ; preds = %14, %3
ret i8* %2
}