#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*/ sprintf(char *, char *, char *, double);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int matAssemble1D(double *m, int dim, char *string) {
  int i;
  strcpy(string, "{");
  for (i = 0; i < dim; i++)
    sprintf(string, "%s%g,", string, m[i]);
  string[strlen(string) - 1] = '\0';
  strcat(string, "}");
  return 0;
}


x86 assembly (clang, -O0):
<matAssemble1D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a5 <matAssemble1D+0x65>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe70(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116a <matAssemble1D+0x2a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1050 <strcat@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matAssemble1D>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xea9(%rip),%rsi
mov    %rdx,%rdi
call   1030 <strcpy@plt>
test   %ebp,%ebp
jle    118d <matAssemble1D+0x4d>
mov    %ebp,%r12d
xor    %ebp,%ebp
lea    0xe93(%rip),%r15
nop
movsd  (%r14,%rbp,8),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <sprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1170 <matAssemble1D+0x30>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"{\00"
@.str.1 = [6 x i8] c"%s%g,\00"
@.str.2 = [2 x i8] c"}\00"
define i32 @matAssemble1D(double* %0, i32 %1, i8* %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %10
10: ; preds = %23, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %26
14: ; preds = %10
%15 = load i8*, i8** %6
%16 = load i8*, i8** %6
%17 = load double*, double** %4
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %17, i64 %19
%21 = load double, double* %20
%22 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %16, double %21)
br label %23
23: ; preds = %14
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %10
26: ; preds = %10
%27 = load i8*, i8** %6
%28 = load i8*, i8** %6
%29 = call i32 @strlen(i8* %28)
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %27, i64 %31
store i8 0, i8* %32
%33 = load i8*, i8** %6
%34 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"{\00"
@.str.1 = [6 x i8] c"%s%g,\00"
@.str.2 = [2 x i8] c"}\00"
define i32 @matAssemble1D(double* nocapture %0, i32 %1, i8* %2) {
%4 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %15
6: ; preds = %3
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %13, %8 ]
%10 = getelementptr inbounds double, double* %0, i64 %9
%11 = load double, double* %10
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %2, double %11)
%13 = add nuw nsw i64 %9, 1
%14 = icmp eq i64 %13, %7
br i1 %14, label %15, label %8
15: ; preds = %8, %3
%16 = tail call i32 @strlen(i8* %2)
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %2, i64 %18
store i8 0, i8* %19
%20 = tail call i32 @strcat(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}