#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*/ flush_buffer(int /*<<< orphan*/ *, char *, size_t *);
int /*<<< orphan*/ printf_buffer(int /*<<< orphan*/ *, char *, int, size_t *,
                                 char *, ...);
int /*<<< orphan*/ printf_header(int /*<<< orphan*/ *, char *, int, size_t *,
                                 char *, char *, int, int, int);
void octave_save_float(FILE *f, char name[], float data[], int rows, int cols,
                       int col_len) {
  int r, c;
  char buffer[2048];
  size_t buf_idx = 0;
  printf_header(f, buffer, 2048, &buf_idx, name, "matrix", rows, cols, 1);
  for (r = 0; r < rows; r++) {
    for (c = 0; c < cols; c++)
      printf_buffer(f, buffer, 2048, &buf_idx, " %f", data[r * col_len + c]);
    printf_buffer(f, buffer, 2048, &buf_idx, "\n");
  }
  printf_buffer(f, buffer, 2048, &buf_idx, "\n\n");
  flush_buffer(f, buffer, &buf_idx);
}


x86 assembly (clang, -O0):
<octave_save_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movq   $0x0,-0x838(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x830(%rbp),%rsi
mov    -0x10(%rbp),%r8
mov    -0x1c(%rbp),%r10d
mov    -0x20(%rbp),%eax
mov    $0x800,%edx
lea    -0x838(%rbp),%rcx
lea    0xe7a(%rip),%r9
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
movl   $0x1,0x10(%rsp)
call   1030 <printf_header@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1241 <octave_save_float+0x111>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    120e <octave_save_float+0xde>
mov    -0x8(%rbp),%rdi
lea    -0x830(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
imul   -0x24(%rbp),%ecx
add    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    $0x800,%edx
lea    -0x838(%rbp),%rcx
lea    0xe0e(%rip),%r8
mov    $0x1,%al
call   1040 <printf_buffer@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b5 <octave_save_float+0x85>
mov    -0x8(%rbp),%rdi
lea    -0x830(%rbp),%rsi
mov    $0x800,%edx
lea    -0x838(%rbp),%rcx
lea    0xde0(%rip),%r8
mov    $0x0,%al
call   1040 <printf_buffer@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a2 <octave_save_float+0x72>
mov    -0x8(%rbp),%rdi
lea    -0x830(%rbp),%rsi
mov    $0x800,%edx
lea    -0x838(%rbp),%rcx
lea    0xdac(%rip),%r8
mov    $0x0,%al
call   1040 <printf_buffer@plt>
mov    -0x8(%rbp),%rdi
lea    -0x830(%rbp),%rsi
lea    -0x838(%rbp),%rdx
call   1050 <flush_buffer@plt>
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<octave_save_float>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
mov    %r9d,%r12d
mov    %r8d,%ebp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r8
mov    %rdi,%rbx
movq   $0x0,(%rsp)
sub    $0x8,%rsp
lea    0xe9a(%rip),%r9
lea    0x38(%rsp),%rsi
lea    0x8(%rsp),%rcx
mov    $0x800,%edx
push   $0x1
mov    %rbp,0x18(%rsp)
push   %rbp
push   %r14
call   1030 <printf_header@plt>
add    $0x20,%rsp
test   %r14d,%r14d
jle    1268 <octave_save_float+0x138>
mov    %r15,%rdx
movslq %r12d,%rax
mov    %r14d,%ecx
mov    %rcx,0x10(%rsp)
mov    0x8(%rsp),%ecx
mov    %rcx,0x28(%rsp)
shl    $0x2,%rax
mov    %rax,0x18(%rsp)
lea    0x30(%rsp),%rbp
mov    %rsp,%r15
xor    %eax,%eax
jmp    11f7 <octave_save_float+0xc7>
nopl   (%rax)
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rsi,%rbp
mov    $0x800,%edx
mov    %rcx,%r15
lea    0xe34(%rip),%r8
xor    %eax,%eax
call   1040 <printf_buffer@plt>
mov    0x20(%rsp),%rax
add    $0x1,%rax
add    0x18(%rsp),%r13
cmp    0x10(%rsp),%rax
mov    %r13,%rdx
je     1268 <octave_save_float+0x138>
mov    %rax,0x20(%rsp)
cmpl   $0x0,0x8(%rsp)
mov    %rbx,%rax
lea    0xdfc(%rip),%r14
mov    %rbp,%rsi
mov    %r15,%rcx
mov    %rdx,%r13
jle    11c0 <octave_save_float+0x90>
xor    %r12d,%r12d
nopl   0x0(%rax)
movss  0x0(%r13,%r12,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rsi,%r15
mov    $0x800,%edx
mov    %r13,%rbx
mov    %rcx,%r13
mov    %r14,%r8
mov    $0x1,%al
call   1040 <printf_buffer@plt>
mov    0x28(%rsp),%rdx
mov    %r13,%rcx
mov    %rbx,%r13
mov    %r15,%rsi
mov    %rbp,%rax
add    $0x1,%r12
cmp    %r12,%rdx
jne    1220 <octave_save_float+0xf0>
jmp    11c0 <octave_save_float+0x90>
lea    0xd9c(%rip),%r8
lea    0x30(%rsp),%r14
mov    %rsp,%rbp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x800,%edx
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <printf_buffer@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1050 <flush_buffer@plt>
add    $0x838,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"matrix\00"
@.str.1 = [4 x i8] c" %f\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [3 x i8] c"\0A\0A\00"
define void @octave_save_float(i32* %0, i8* %1, float* nocapture %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca [2048 x i8]
%8 = alloca i64
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%10 = bitcast i64* %8 to i8*
store i64 0, i64* %8
%11 = call i32 @printf_header(i32* %0, i8* %9, i32 2048, i64* %8, i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4, i32 1)
%12 = icmp sgt i32 %3, 0
br i1 %12, label %13, label %35
13: ; preds = %6
%14 = icmp sgt i32 %4, 0
%15 = sext i32 %5 to i64
%16 = zext i32 %3 to i64
%17 = zext i32 %4 to i64
br label %18
18: ; preds = %13, %31
%19 = phi i64 [ 0, %13 ], [ %33, %31 ]
br i1 %14, label %20, label %31
20: ; preds = %18
%21 = mul nsw i64 %19, %15
br label %22
22: ; preds = %20, %22
%23 = phi i64 [ 0, %20 ], [ %29, %22 ]
%24 = add nsw i64 %23, %21
%25 = getelementptr inbounds float, float* %2, i64 %24
%26 = load float, float* %25
%27 = fpext float %26 to double
%28 = call i32 (i32*, i8*, i32, i64*, i8*, ...) @printf_buffer(i32* %0, i8* %9, i32 2048, i64* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %27)
%29 = add nuw nsw i64 %23, 1
%30 = icmp eq i64 %29, %17
br i1 %30, label %31, label %22
31: ; preds = %22, %18
%32 = call i32 (i32*, i8*, i32, i64*, i8*, ...) @printf_buffer(i32* %0, i8* %9, i32 2048, i64* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%33 = add nuw nsw i64 %19, 1
%34 = icmp eq i64 %33, %16
br i1 %34, label %35, label %18
35: ; preds = %31, %6
%36 = call i32 (i32*, i8*, i32, i64*, i8*, ...) @printf_buffer(i32* %0, i8* %9, i32 2048, i64* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @flush_buffer(i32* %0, i8* %9, i64* %8)
ret void
}