#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 */
char *talloc_append_string(char *, char const *);
char *talloc_strdup(void const *, char *);
char *strjoin(const void *ctx, char *strings[], const char *delim) {
  unsigned int i;
  char *ret = talloc_strdup(ctx, "");
  for (i = 0; strings[i]; i++) {
    ret = talloc_append_string(ret, strings[i]);
    ret = talloc_append_string(ret, delim);
  }
  return ret;
}


x86 assembly (clang, -O0):
<strjoin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec1(%rip),%rsi
call   1030 <talloc_strdup@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
je     1198 <strjoin+0x78>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,8),%rsi
call   1040 <talloc_append_string@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <talloc_append_string@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <strjoin+0x2f>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strjoin>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0xecf(%rip),%rsi
call   1030 <talloc_strdup@plt>
mov    (%rbx),%rsi
test   %rsi,%rsi
je     1171 <strjoin+0x51>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rdi
call   1040 <talloc_append_string@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <talloc_append_string@plt>
mov    %ebp,%ecx
mov    (%rbx,%rcx,8),%rsi
add    $0x1,%ebp
test   %rsi,%rsi
jne    1150 <strjoin+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @strjoin(i8* %0, i8** %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = call i8* @talloc_strdup(i8* %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %8
store i32 0, i32* %7
br label %11
11: ; preds = %29, %3
%12 = load i8**, i8*** %5
%13 = load i32, i32* %7
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %12, i64 %14
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %32
18: ; preds = %11
%19 = load i8*, i8** %8
%20 = load i8**, i8*** %5
%21 = load i32, i32* %7
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = call i8* @talloc_append_string(i8* %19, i8* %24)
store i8* %25, i8** %8
%26 = load i8*, i8** %8
%27 = load i8*, i8** %6
%28 = call i8* @talloc_append_string(i8* %26, i8* %27)
store i8* %28, i8** %8
br label %29
29: ; preds = %18
%30 = load i32, i32* %7
%31 = add i32 %30, 1
store i32 %31, i32* %7
br label %11
32: ; preds = %11
%33 = load i8*, i8** %8
ret i8* %33
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @strjoin(i8* %0, i8** nocapture %1, i8* %2) {
%4 = tail call i8* @talloc_strdup(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%5 = load i8*, i8** %1
%6 = icmp eq i8* %5, null
br i1 %6, label %18, label %7
7: ; preds = %3, %7
%8 = phi i8* [ %16, %7 ], [ %5, %3 ]
%9 = phi i8* [ %12, %7 ], [ %4, %3 ]
%10 = phi i32 [ %13, %7 ], [ 0, %3 ]
%11 = tail call i8* @talloc_append_string(i8* %9, i8* %8)
%12 = tail call i8* @talloc_append_string(i8* %11, i8* %2)
%13 = add i32 %10, 1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %7
18: ; preds = %7, %3
%19 = phi i8* [ %4, %3 ], [ %12, %7 ]
ret i8* %19
}