#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 *, double);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *cd_mat_vec_sprintf(char *buf, double *a, int n) {
  int j;
  buf[0] = '<';
  buf[1] = 0;
  for (j = 0; j < n; j++)
    sprintf(buf + strlen(buf), "%8.4f,", a[j]);
  buf[strlen(buf) - 1] = 0;
  strcat(buf, ">");
  return buf;
}


x86 assembly (clang, -O0):
<cd_mat_vec_sprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x3c,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x1(%rax)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a6 <cd_mat_vec_sprintf+0x76>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe6d(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1159 <cd_mat_vec_sprintf+0x29>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cd_mat_vec_sprintf>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r13
movw   $0x3c,(%rdi)
test   %edx,%edx
jle    1185 <cd_mat_vec_sprintf+0x55>
mov    %rsi,%r14
mov    %edx,%r12d
xor    %ebx,%ebx
lea    0xeac(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %r13,%rdi
movsd  (%r14,%rbx,8),%xmm0
mov    %r15,%rsi
call   1050 <sprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <cd_mat_vec_sprintf+0x30>
mov    %r13,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r13,1)
lea    0xe6b(%rip),%rsi
mov    %r13,%rdi
call   1040 <strcat@plt>
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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