#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*/ strcat(char *, char const *);
scalar_t__ strcmp(char *, char *);
char *join(const char *glue, char *elements[], int element_count,
           char *buffer) {
  int i;
  for (i = 0; i < element_count; i++) {
    if (strcmp(elements[i], "") != 0) {
      strcat(buffer, elements[i]);
      if (i != element_count - 1)
        strcat(buffer, glue);
    }
  }
  return buffer;
}


x86 assembly (clang, -O0):
<join>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b7 <join+0x97>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xea3(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     11a4 <join+0x84>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcat@plt>
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     119f <join+0x7f>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcat@plt>
jmp    11a4 <join+0x84>
jmp    11a9 <join+0x89>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113e <join+0x1e>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<join>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdi,(%rsp)
test   %edx,%edx
jle    1189 <join+0x69>
mov    %rsi,%rbx
lea    -0x1(%rdx),%r13d
mov    %edx,%ebp
xor    %r15d,%r15d
lea    0xeb7(%rip),%r12
jmp    1159 <join+0x39>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    %r15,%rbp
je     1189 <join+0x69>
mov    (%rbx,%r15,8),%rdi
mov    %r12,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1150 <join+0x30>
mov    (%rbx,%r15,8),%rsi
mov    %r14,%rdi
call   1040 <strcat@plt>
cmp    %r15,%r13
je     1150 <join+0x30>
mov    %r14,%rdi
mov    (%rsp),%rsi
call   1040 <strcat@plt>
jmp    1150 <join+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @join(i8* %0, i8** nocapture %1, i32 %2, i8* returned %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %25
6: ; preds = %4
%7 = add nsw i32 %2, -1
%8 = zext i32 %7 to i64
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %6, %22
%11 = phi i64 [ 0, %6 ], [ %23, %22 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %10
%17 = load i8*, i8** %12
%18 = tail call i32 @strcat(i8* %3, i8* %17)
%19 = icmp eq i64 %11, %8
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = tail call i32 @strcat(i8* %3, i8* %0)
br label %22
22: ; preds = %10, %20, %16
%23 = add nuw nsw i64 %11, 1
%24 = icmp eq i64 %23, %9
br i1 %24, label %25, label %10
25: ; preds = %22, %4
ret i8* %3
}