#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);
int strlen(char *const);
char *implode(int argc, char *const *argv, char *sep) {
  static char ret[256];
  ret[0] = '\0';
  int i, len = 255, decrement = 0;
  for (i = 0; i < argc; ++i) {
    decrement = strlen(sep) + strlen(argv[i]);
    if (decrement > len)
      break;
    strcat(ret, sep);
    strcat(ret, argv[i]);
    len -= decrement;
  }
  return ret;
}


x86 assembly (clang, -O0):
<implode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movb   $0x0,0x2f06(%rip)
movl   $0xff,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d4 <implode+0xb4>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    1193 <implode+0x73>
jmp    11d4 <implode+0xb4>
mov    -0x18(%rbp),%rsi
lea    0x2ea2(%rip),%rdi
call   1040 <strcat@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0x2e8a(%rip),%rdi
call   1040 <strcat@plt>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <implode+0x2f>
lea    0x2e65(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<implode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movb   $0x0,0x2f0e(%rip)
test   %edi,%edi
jle    119c <implode+0x7c>
mov    %rdx,%r14
mov    %rsi,%r13
mov    %edi,%eax
mov    %rax,(%rsp)
mov    $0xff,%ebx
xor    %r12d,%r12d
lea    0x2eef(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    0x0(%r13,%r12,8),%rdi
call   1030 <strlen@plt>
add    %ebp,%eax
sub    %eax,%ebx
jl     119c <implode+0x7c>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcat@plt>
mov    0x0(%r13,%r12,8),%rsi
mov    %r15,%rdi
call   1040 <strcat@plt>
add    $0x1,%r12
cmp    %r12,(%rsp)
jne    1160 <implode+0x40>
lea    0x2e9d(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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