#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 */
scalar_t__ column(char *, int, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
char *column2delimiter(char *destination, char *source, char delimiter) {
  char this_column[1024];
  int field_offset;
  int first_time = 1;
  char *hold = destination;
  *destination = '\0';
  for (field_offset = 0; column(this_column, field_offset, source);
       field_offset++) {
    if (first_time)
      first_time = 0;
    else
      destination += sprintf(destination, "%c", delimiter);
    destination += sprintf(destination, "%s", this_column);
  }
  return hold;
}


x86 assembly (clang, -O0):
<column2delimiter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movl   $0x1,-0x428(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x424(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <column@plt>
cmp    $0x0,%rax
je     11fd <column2delimiter+0xdd>
cmpl   $0x0,-0x428(%rbp)
je     119a <column2delimiter+0x7a>
movl   $0x0,-0x428(%rbp)
jmp    11c0 <column2delimiter+0xa0>
mov    -0x8(%rbp),%rdi
movsbl -0x11(%rbp),%edx
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    115e <column2delimiter+0x3e>
mov    -0x430(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<column2delimiter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,0x8(%rsp)
movb   $0x0,(%rdi)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1040 <column@plt>
test   %rax,%rax
je     11d7 <column2delimiter+0xb7>
lea    0x10(%rsp),%rbp
mov    0x8(%rsp),%rdi
mov    %rbp,%rsi
call   1030 <stpcpy@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
call   1040 <column@plt>
test   %rax,%rax
je     11d7 <column2delimiter+0xb7>
mov    0x8(%rsp),%rax
sub    %eax,%ebx
movslq %ebx,%r14
add    %rax,%r14
mov    $0x2,%ebp
lea    0x10(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %r15b,(%r14)
lea    0x1(%r14),%rbx
movb   $0x0,0x1(%r14)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <stpcpy@plt>
sub    %ebx,%eax
cltq
add    %rax,%r14
add    $0x1,%r14
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
call   1040 <column@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    11a0 <column2delimiter+0x80>
mov    0x8(%rsp),%rax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @column2delimiter(i8* returned %0, i8* %1, i8 signext %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
store i8 0, i8* %0
%6 = call i64 @column(i8* %5, i32 0, i8* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %33, label %8
8: ; preds = %3
%9 = call i8* @stpcpy(i8* %0, i8* %5)
%10 = call i64 @column(i8* %5, i32 1, i8* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %33, label %12
12: ; preds = %8
%13 = ptrtoint i8* %9 to i64
%14 = ptrtoint i8* %0 to i64
%15 = sub i64 %13, %14
%16 = shl i64 %15, 32
%17 = ashr exact i64 %16, 32
%18 = getelementptr inbounds i8, i8* %0, i64 %17
br label %19
19: ; preds = %12, %19
%20 = phi i8* [ %29, %19 ], [ %18, %12 ]
%21 = phi i32 [ %30, %19 ], [ 1, %12 ]
store i8 %2, i8* %20
%22 = getelementptr i8, i8* %20, i64 1
store i8 0, i8* %22
%23 = call i8* @stpcpy(i8* %22, i8* %5)
%24 = ptrtoint i8* %23 to i64
%25 = ptrtoint i8* %22 to i64
%26 = sub i64 %24, %25
%27 = shl i64 %26, 32
%28 = ashr exact i64 %27, 32
%29 = getelementptr inbounds i8, i8* %22, i64 %28
%30 = add nuw nsw i32 %21, 1
%31 = call i64 @column(i8* %5, i32 %30, i8* %1)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %19
33: ; preds = %19, %8, %3
ret i8* %0
}