#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 */
struct dyString {
  int dummy;
};

/* Variables and functions */
char *dyStringCannibalize(struct dyString **);
int /*<<< orphan*/ dyStringPrintf(struct dyString *, char *, char);
struct dyString *newDyString(int);
char *sqlByteArrayToString(signed char *array, int arraySize) {
  int i;
  struct dyString *string = newDyString(256);
  for (i = 0; i < arraySize; i++) {
    dyStringPrintf(string, "%d,", array[i]);
  }
  return dyStringCannibalize(&string);
}


x86 assembly (clang, -O0):
<sqlByteArrayToString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x100,%edi
call   1030 <newDyString@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118a <sqlByteArrayToString+0x5a>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xe8d(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1050 <dyStringPrintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1154 <sqlByteArrayToString+0x24>
lea    -0x18(%rbp),%rdi
call   1040 <dyStringCannibalize@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlByteArrayToString>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0x100,%edi
call   1030 <newDyString@plt>
mov    %rax,0x8(%rsp)
test   %ebp,%ebp
jle    1189 <sqlByteArrayToString+0x59>
mov    %rax,%r12
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe9e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%r14,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <dyStringPrintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <sqlByteArrayToString+0x40>
lea    0x8(%rsp),%rdi
call   1040 <dyStringCannibalize@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dyString = type { i32 }
@.str = [4 x i8] c"%d,\00"
define i8* @sqlByteArrayToString(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.dyString*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call %struct.dyString* @newDyString(i32 256)
store %struct.dyString* %7, %struct.dyString** %6
store i32 0, i32* %5
br label %8
8: ; preds = %20, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %23
12: ; preds = %8
%13 = load %struct.dyString*, %struct.dyString** %6
%14 = load i8*, i8** %3
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = call i32 @dyStringPrintf(%struct.dyString* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %18)
br label %20
20: ; preds = %12
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %8
23: ; preds = %8
%24 = call i8* @dyStringCannibalize(%struct.dyString** %6)
ret i8* %24
}

LLVM IR (-O2):
%struct.dyString = type { i32 }
@.str = [4 x i8] c"%d,\00"
define i8* @sqlByteArrayToString(i8* nocapture %0, i32 %1) {
%3 = alloca %struct.dyString*
%4 = bitcast %struct.dyString** %3 to i8*
%5 = tail call %struct.dyString* @newDyString(i32 256)
store %struct.dyString* %5, %struct.dyString** %3
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %14, %9 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = tail call i32 @dyStringPrintf(%struct.dyString* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %8
br i1 %15, label %16, label %9
16: ; preds = %9, %2
%17 = call i8* @dyStringCannibalize(%struct.dyString** %3)
ret i8* %17
}