#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char, ...);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int writeCSV(double *vals, int n, int m, char f, char rd, FILE *s) {
  int i, j;
  for (i = 0; i < n; i++) {
    fprintf(s, "%f", vals[i * m]);
    for (j = 1; j < m; j++)
      fprintf(s, "%c%f", f, vals[i * m + j]);
    putc(rd, s);
  }
  return 0;
}


x86 assembly (clang, -O0):
<writeCSV>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8b,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %cl,-0x11(%rbp)
mov    %al,-0x12(%rbp)
mov    %r9,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ec <writeCSV+0xcc>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%edx
imul   %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%eax
lea    0xe8c(%rip),%rsi
movsbl %al,%edx
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11cf <writeCSV+0xaf>
mov    -0x20(%rbp),%rdi
mov    -0x11(%rbp),%al
mov    -0x8(%rbp),%rcx
mov    -0x24(%rbp),%edx
imul   -0x10(%rbp),%edx
add    -0x28(%rbp),%edx
movslq %edx,%rdx
movsd  (%rcx,%rdx,8),%xmm0
lea    0xe49(%rip),%rsi
movsbl %al,%edx
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1187 <writeCSV+0x67>
mov    -0x12(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1030 <putc@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1146 <writeCSV+0x26>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeCSV>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,0x10(%rsp)
test   %esi,%esi
jle    1204 <writeCSV+0xe4>
mov    %r9,%rbx
movslq %edx,%rax
mov    %esi,%edx
mov    %rdx,0x20(%rsp)
mov    %eax,%r14d
mov    %rax,0x28(%rsp)
lea    0x0(,%rax,8),%rax
mov    %rax,0x18(%rsp)
movsbl %cl,%ebp
movsbl %r8b,%eax
mov    %eax,0xc(%rsp)
mov    0x10(%rsp),%r13
xor    %eax,%eax
jmp    11a1 <writeCSV+0x81>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
call   1030 <putc@plt>
mov    0x30(%rsp),%rax
add    $0x1,%rax
add    0x18(%rsp),%r13
cmp    0x20(%rsp),%rax
je     1204 <writeCSV+0xe4>
mov    %rax,0x30(%rsp)
mov    0x28(%rsp),%r12
imul   %r12,%rax
mov    0x10(%rsp),%rcx
cvttsd2si (%rcx,%rax,8),%eax
movsbl %al,%edx
mov    %rbx,%rdi
lea    0xe3c(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    $0x2,%r12d
lea    0xe28(%rip),%r15
jl     1180 <writeCSV+0x60>
mov    $0x1,%r12d
movsd  0x0(%r13,%r12,8),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    $0x1,%al
call   1040 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%r14
jne    11e0 <writeCSV+0xc0>
jmp    1180 <writeCSV+0x60>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%f\00"
@.str.1 = [5 x i8] c"%c%f\00"
define i32 @writeCSV(double* %0, i32 %1, i32 %2, i8 signext %3, i8 signext %4, i32* %5) {
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i8
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
store double* %0, double** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8 %3, i8* %10
store i8 %4, i8* %11
store i32* %5, i32** %12
store i32 0, i32* %13
br label %15
15: ; preds = %54, %6
%16 = load i32, i32* %13
%17 = load i32, i32* %8
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %57
19: ; preds = %15
%20 = load i32*, i32** %12
%21 = load double*, double** %7
%22 = load i32, i32* %13
%23 = load i32, i32* %9
%24 = mul nsw i32 %22, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %21, i64 %25
%27 = load double, double* %26
%28 = fptosi double %27 to i8
%29 = call i32 (i32*, i8*, i8, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %28)
store i32 1, i32* %14
br label %30
30: ; preds = %47, %19
%31 = load i32, i32* %14
%32 = load i32, i32* %9
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %50
34: ; preds = %30
%35 = load i32*, i32** %12
%36 = load i8, i8* %10
%37 = load double*, double** %7
%38 = load i32, i32* %13
%39 = load i32, i32* %9
%40 = mul nsw i32 %38, %39
%41 = load i32, i32* %14
%42 = add nsw i32 %40, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %37, i64 %43
%45 = load double, double* %44
%46 = call i32 (i32*, i8*, i8, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 signext %36, double %45)
br label %47
47: ; preds = %34
%48 = load i32, i32* %14
%49 = add nsw i32 %48, 1
store i32 %49, i32* %14
br label %30
50: ; preds = %30
%51 = load i8, i8* %11
%52 = load i32*, i32** %12
%53 = call i32 @putc(i8 signext %51, i32* %52)
br label %54
54: ; preds = %50
%55 = load i32, i32* %13
%56 = add nsw i32 %55, 1
store i32 %56, i32* %13
br label %15
57: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%f\00"
@.str.1 = [5 x i8] c"%c%f\00"
define i32 @writeCSV(double* nocapture %0, i32 %1, i32 %2, i8 signext %3, i8 signext %4, i32* nocapture %5) {
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %32
8: ; preds = %6
%9 = icmp sgt i32 %2, 1
%10 = sext i32 %2 to i64
%11 = zext i32 %1 to i64
%12 = zext i32 %2 to i64
br label %13
13: ; preds = %8, %28
%14 = phi i64 [ 0, %8 ], [ %30, %28 ]
%15 = mul nsw i64 %14, %10
%16 = getelementptr inbounds double, double* %0, i64 %15
%17 = load double, double* %16
%18 = fptosi double %17 to i8
%19 = tail call i32 (i32*, i8*, i8, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %18)
br i1 %9, label %20, label %28
20: ; preds = %13, %20
%21 = phi i64 [ %26, %20 ], [ 1, %13 ]
%22 = add nsw i64 %21, %15
%23 = getelementptr inbounds double, double* %0, i64 %22
%24 = load double, double* %23
%25 = tail call i32 (i32*, i8*, i8, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 signext %3, double %24)
%26 = add nuw nsw i64 %21, 1
%27 = icmp eq i64 %26, %12
br i1 %27, label %28, label %20
28: ; preds = %20, %13
%29 = tail call i32 @putc(i8 signext %4, i32* %5)
%30 = add nuw nsw i64 %14, 1
%31 = icmp eq i64 %30, %11
br i1 %31, label %32, label %13
32: ; preds = %28, %6
ret i32 0
}