#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*/ assert(int);
int fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fput32le(int /*<<< orphan*/ *, int const);
int /*<<< orphan*/ fputc(char const, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwriteieee754(float const, int /*<<< orphan*/ *,
                                 int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int const strlen(char const *);
int writematmatrix(const char *fname, const char *name, const float *data,
                   const int m, const int n, const int transpose) {
  FILE *fp;
  int i, ii;
  char buff[128];
  size_t bufflen;
  size_t totalsize;
  int err;
  assert(m > 0);
  assert(n > 0);
  assert((m * n) / n == m);
  fp = fopen(fname, "wb");
  if (!fp)
    return -1;
  sprintf(buff, "MATLAB matrix file of %s, generated by Malcolm McLean", name);
  bufflen = strlen(buff);
  for (i = 0; i < 123; i++)
    fputc(i < (int)bufflen ? buff[i] : ' ', fp);
  fputc(0, fp);
  fputc(0, fp);
  fputc(1, fp);
  fputc('I', fp);
  fputc('M', fp);
  totalsize = 8 + 8 + strlen(name) + (n * m * 8) + 8 * 4;
  if (strlen(name) % 8)
    totalsize += 8 - (strlen(name) % 8);
  fput32le(fp, 14);
  fput32le(fp, totalsize);
  fput32le(fp, 6);
  fput32le(fp, 8);
  fputc(6, fp);
  fputc(4, fp);
  fputc(0, fp);
  fputc(0, fp);
  fput32le(fp, 0);
  fput32le(fp, 5);
  fput32le(fp, 2 * 4);
  fput32le(fp, m);
  fput32le(fp, n);
  fput32le(fp, 1);
  fput32le(fp, strlen(name));
  for (i = 0; name[i]; i++)
    fputc(name[i], fp);
  while (i % 8) {
    fputc(0, fp);
    i++;
  }
  fput32le(fp, 9);
  fput32le(fp, m * n * 8);
  if (transpose) {
    for (i = 0; i < m; i++)
      for (ii = 0; ii < n; ii++)
        fwriteieee754(data[i * n + ii], fp, 0);
  } else {
    for (i = 0; i < n; i++)
      for (ii = 0; ii < m; ii++)
        fwriteieee754(data[ii * n + i], fp, 0);
  }
  if (ferror(fp)) {
    fclose(fp);
    return -1;
  }
  err = fclose(fp);
  if (err)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<writematmatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
cmpl   $0x0,-0x24(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
cmpl   $0x0,-0x28(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x24(%rbp),%eax
imul   -0x28(%rbp),%eax
cltd
idivl  -0x28(%rbp)
cmp    -0x24(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x10(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    121a <writematmatrix+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    15ff <writematmatrix+0x46f>
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdd7(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0xc0(%rbp),%rdi
call   1060 <strlen@plt>
cltq
mov    %rax,-0xc8(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x7b,-0x3c(%rbp)
jge    12b0 <writematmatrix+0x120>
mov    -0x3c(%rbp),%eax
mov    -0xc8(%rbp),%rcx
cmp    %ecx,%eax
jge    1280 <writematmatrix+0xf0>
movslq -0x3c(%rbp),%rax
movsbl -0xc0(%rbp,%rax,1),%eax
ff
mov    %eax,-0xd8(%rbp)
jmp    1290 <writematmatrix+0x100>
mov    $0x20,%eax
mov    %eax,-0xd8(%rbp)
jmp    1290 <writematmatrix+0x100>
mov    -0xd8(%rbp),%eax
mov    -0x38(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    124d <writematmatrix+0xbd>
mov    -0x38(%rbp),%rsi
xor    %edi,%edi
call   1070 <fputc@plt>
mov    -0x38(%rbp),%rsi
xor    %edi,%edi
call   1070 <fputc@plt>
mov    -0x38(%rbp),%rsi
mov    $0x1,%edi
call   1070 <fputc@plt>
mov    -0x38(%rbp),%rsi
mov    $0x49,%edi
call   1070 <fputc@plt>
mov    -0x38(%rbp),%rsi
mov    $0x4d,%edi
call   1070 <fputc@plt>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x10,%eax
mov    -0x28(%rbp),%ecx
imul   -0x24(%rbp),%ecx
shl    $0x3,%ecx
add    %ecx,%eax
add    $0x20,%eax
cltq
mov    %rax,-0xd0(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1356 <writematmatrix+0x1c6>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    $0x8,%eax
sub    %edx,%eax
cltq
add    -0xd0(%rbp),%rax
mov    %rax,-0xd0(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0xe,%esi
call   1030 <fput32le@plt>
mov    -0x38(%rbp),%rdi
mov    -0xd0(%rbp),%rax
mov    %eax,%esi
call   1030 <fput32le@plt>
mov    -0x38(%rbp),%rdi
mov    $0x6,%esi
call   1030 <fput32le@plt>
mov    -0x38(%rbp),%rdi
mov    $0x8,%esi
call   1030 <fput32le@plt>
mov    -0x38(%rbp),%rsi
mov    $0x6,%edi
call   1070 <fputc@plt>
mov    -0x38(%rbp),%rsi
mov    $0x4,%edi
call   1070 <fputc@plt>
mov    -0x38(%rbp),%rsi
xor    %edi,%edi
call   1070 <fputc@plt>
mov    -0x38(%rbp),%rsi
xor    %edi,%edi
call   1070 <fputc@plt>
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1030 <fput32le@plt>
mov    -0x38(%rbp),%rdi
mov    $0x5,%esi
call   1030 <fput32le@plt>
mov    -0x38(%rbp),%rdi
mov    $0x8,%esi
call   1030 <fput32le@plt>
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <fput32le@plt>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1030 <fput32le@plt>
mov    -0x38(%rbp),%rdi
mov    $0x1,%esi
call   1030 <fput32le@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xe0(%rbp),%rdi
mov    %eax,%esi
call   1030 <fput32le@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1471 <writematmatrix+0x2e1>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x38(%rbp),%rsi
movsbl %al,%edi
call   1070 <fputc@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    143a <writematmatrix+0x2aa>
jmp    1476 <writematmatrix+0x2e6>
mov    -0x3c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     14a3 <writematmatrix+0x313>
mov    -0x38(%rbp),%rsi
xor    %edi,%edi
call   1070 <fputc@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1476 <writematmatrix+0x2e6>
mov    -0x38(%rbp),%rdi
mov    $0x9,%esi
call   1030 <fput32le@plt>
mov    -0x38(%rbp),%rdi
mov    -0x24(%rbp),%esi
imul   -0x28(%rbp),%esi
shl    $0x3,%esi
call   1030 <fput32le@plt>
cmpl   $0x0,-0x2c(%rbp)
je     153b <writematmatrix+0x3ab>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1536 <writematmatrix+0x3a6>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1523 <writematmatrix+0x393>
mov    -0x20(%rbp),%rax
mov    -0x3c(%rbp),%ecx
imul   -0x28(%rbp),%ecx
add    -0x40(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
call   10b0 <fwriteieee754@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    14e8 <writematmatrix+0x358>
jmp    1528 <writematmatrix+0x398>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    14d5 <writematmatrix+0x345>
jmp    15a8 <writematmatrix+0x418>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    15a3 <writematmatrix+0x413>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1590 <writematmatrix+0x400>
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%ecx
imul   -0x28(%rbp),%ecx
add    -0x3c(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
call   10b0 <fwriteieee754@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1555 <writematmatrix+0x3c5>
jmp    1595 <writematmatrix+0x405>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1542 <writematmatrix+0x3b2>
jmp    15a8 <writematmatrix+0x418>
mov    -0x38(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     15d0 <writematmatrix+0x440>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15ff <writematmatrix+0x46f>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    %eax,-0xd4(%rbp)
cmpl   $0x0,-0xd4(%rbp)
je     15f8 <writematmatrix+0x468>
movl   $0xffffffff,-0x4(%rbp)
jmp    15ff <writematmatrix+0x46f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writematmatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %r9d,%r14d
mov    %r8d,%ebx
mov    %rdx,0x10(%rsp)
mov    %rsi,%r15
mov    %rdi,%rbp
xor    %edi,%edi
mov    %ecx,(%rsp)
test   %ecx,%ecx
setg   %dil
call   1080 <assert@plt>
xor    %edi,%edi
mov    %ebx,0x8(%rsp)
test   %ebx,%ebx
setg   %dil
call   1080 <assert@plt>
mov    $0x1,%edi
call   1080 <assert@plt>
lea    0xe1c(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
mov    $0xffffffff,%ecx
test   %rax,%rax
je     150b <writematmatrix+0x37b>
mov    %rax,%r13
mov    %r14d,%ebp
lea    0xdfc(%rip),%rsi
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %r15,%rdx
call   10a0 <sprintf@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
movslq %eax,%r14
xor    %ebx,%ebx
jmp    1245 <writematmatrix+0xb5>
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
add    $0x1,%rbx
cmp    $0x7b,%rbx
je     1253 <writematmatrix+0xc3>
mov    $0x20,%al
cmp    %r14,%rbx
jge    1230 <writematmatrix+0xa0>
movzbl 0x20(%rsp,%rbx,1),%eax
jmp    1230 <writematmatrix+0xa0>
xor    %edi,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
mov    $0x1,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
mov    $0x49,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
mov    $0x4d,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
mov    (%rsp),%eax
mov    %eax,%r12d
imul   0x8(%rsp),%r12d
mov    %r15,%rdi
call   1060 <strlen@plt>
test   $0x7,%al
je     12d7 <writematmatrix+0x147>
lea    (%r14,%r12,8),%ebx
add    $0x10,%ebx
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    0x7(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff8,%ecx
sub    %eax,%ecx
lea    (%rbx,%rcx,1),%r14d
add    $0x28,%r14d
jmp    12df <writematmatrix+0x14f>
lea    (%r14,%r12,8),%r14d
add    $0x30,%r14d
shl    $0x3,%r12d
mov    %r13,%rdi
mov    $0xe,%esi
call   1030 <fput32le@plt>
mov    %r13,%rdi
mov    %r14d,%esi
call   1030 <fput32le@plt>
mov    %r13,%rdi
mov    $0x6,%esi
call   1030 <fput32le@plt>
mov    %r13,%rdi
mov    $0x8,%esi
call   1030 <fput32le@plt>
mov    $0x6,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
mov    $0x4,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
xor    %edi,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1030 <fput32le@plt>
mov    %r13,%rdi
mov    $0x5,%esi
call   1030 <fput32le@plt>
mov    %r13,%rdi
mov    $0x8,%esi
call   1030 <fput32le@plt>
mov    %r13,%rdi
mov    (%rsp),%esi
call   1030 <fput32le@plt>
mov    %r13,%rdi
mov    0x8(%rsp),%esi
call   1030 <fput32le@plt>
mov    %r13,%rdi
mov    $0x1,%esi
call   1030 <fput32le@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1030 <fput32le@plt>
mov    (%r15),%al
test   %al,%al
mov    %ebp,%r14d
je     13f4 <writematmatrix+0x264>
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl %al,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
movzbl 0x1(%r15,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    13b0 <writematmatrix+0x220>
test   $0x7,%bl
je     13f4 <writematmatrix+0x264>
add    $0x1,%rbx
mov    %ebx,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edi,%edi
mov    %r13,%rsi
call   1070 <fputc@plt>
add    $0x1,%ebp
test   $0x7,%bl
mov    %ebp,%ebx
jne    13e0 <writematmatrix+0x250>
mov    %r13,%rdi
mov    $0x9,%esi
call   1030 <fput32le@plt>
mov    %r13,%rdi
mov    %r12d,%esi
call   1030 <fput32le@plt>
test   %r14d,%r14d
je     147c <writematmatrix+0x2ec>
cmpl   $0x0,(%rsp)
mov    0x10(%rsp),%rbp
jle    14ea <writematmatrix+0x35a>
mov    0x8(%rsp),%eax
movslq %eax,%r15
mov    (%rsp),%ecx
mov    %rcx,(%rsp)
mov    %eax,%ebx
shl    $0x2,%r15
xor    %r12d,%r12d
jmp    1451 <writematmatrix+0x2c1>
nopl   0x0(%rax)
add    $0x1,%r12
add    %r15,%rbp
cmp    (%rsp),%r12
je     14ea <writematmatrix+0x35a>
cmpl   $0x0,0x8(%rsp)
jle    1440 <writematmatrix+0x2b0>
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
movss  0x0(%rbp,%r14,4),%xmm0
mov    %r13,%rdi
xor    %esi,%esi
call   10b0 <fwriteieee754@plt>
add    $0x1,%r14
cmp    %r14,%rbx
jne    1460 <writematmatrix+0x2d0>
jmp    1440 <writematmatrix+0x2b0>
cmpl   $0x0,0x8(%rsp)
mov    0x10(%rsp),%rbp
jle    14ea <writematmatrix+0x35a>
mov    0x8(%rsp),%eax
mov    (%rsp),%ecx
mov    %rcx,0x18(%rsp)
mov    %rax,0x8(%rsp)
lea    0x0(,%rax,4),%rbx
xor    %r12d,%r12d
jmp    14bf <writematmatrix+0x32f>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r12
add    $0x4,%rbp
cmp    0x8(%rsp),%r12
je     14ea <writematmatrix+0x35a>
cmpl   $0x0,(%rsp)
jle    14b0 <writematmatrix+0x320>
mov    0x18(%rsp),%r14
mov    %rbp,%r15
nopl   (%rax)
movss  (%r15),%xmm0
mov    %r13,%rdi
xor    %esi,%esi
call   10b0 <fwriteieee754@plt>
add    %rbx,%r15
add    $0xffffffffffffffff,%r14
jne    14d0 <writematmatrix+0x340>
jmp    14b0 <writematmatrix+0x320>
mov    %r13,%rdi
call   1040 <ferror@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1050 <fclose@plt>
test   %rbx,%rbx
mov    $0xffffffff,%ecx
jne    150b <writematmatrix+0x37b>
neg    %eax
sbb    %ecx,%ecx
mov    %ecx,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [54 x i8] c"MATLAB matrix file of %s, generated by Malcolm McLean\00"
define i32 @writematmatrix(i8* %0, i8* %1, float* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca float*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
%17 = alloca [128 x i8]
%18 = alloca i64
%19 = alloca i64
%20 = alloca i32
store i8* %0, i8** %8
store i8* %1, i8** %9
store float* %2, float** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%21 = load i32, i32* %11
%22 = icmp sgt i32 %21, 0
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i32, i32* %12
%26 = icmp sgt i32 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i32, i32* %11
%30 = load i32, i32* %12
%31 = mul nsw i32 %29, %30
%32 = load i32, i32* %12
%33 = sdiv i32 %31, %32
%34 = load i32, i32* %11
%35 = icmp eq i32 %33, %34
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i8*, i8** %8
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %39, i32** %14
%40 = load i32*, i32** %14
%41 = icmp ne i32* %40, null
br i1 %41, label %43, label %42
42: ; preds = %6
store i32 -1, i32* %7
br label %256
43: ; preds = %6
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %17, i64 0, i64 0
%45 = load i8*, i8** %9
%46 = call i32 @sprintf(i8* %44, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %17, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = sext i32 %48 to i64
store i64 %49, i64* %18
store i32 0, i32* %15
br label %50
50: ; preds = %70, %43
%51 = load i32, i32* %15
%52 = icmp slt i32 %51, 123
br i1 %52, label %53, label %73
53: ; preds = %50
%54 = load i32, i32* %15
%55 = load i64, i64* %18
%56 = trunc i64 %55 to i32
%57 = icmp slt i32 %54, %56
br i1 %57, label %58, label %64
58: ; preds = %53
%59 = load i32, i32* %15
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [128 x i8], [128 x i8]* %17, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
br label %65
64: ; preds = %53
br label %65
65: ; preds = %64, %58
%66 = phi i32 [ %63, %58 ], [ 32, %64 ]
%67 = trunc i32 %66 to i8
%68 = load i32*, i32** %14
%69 = call i32 @fputc(i8 signext %67, i32* %68)
br label %70
70: ; preds = %65
%71 = load i32, i32* %15
%72 = add nsw i32 %71, 1
store i32 %72, i32* %15
br label %50
73: ; preds = %50
%74 = load i32*, i32** %14
%75 = call i32 @fputc(i8 signext 0, i32* %74)
%76 = load i32*, i32** %14
%77 = call i32 @fputc(i8 signext 0, i32* %76)
%78 = load i32*, i32** %14
%79 = call i32 @fputc(i8 signext 1, i32* %78)
%80 = load i32*, i32** %14
%81 = call i32 @fputc(i8 signext 73, i32* %80)
%82 = load i32*, i32** %14
%83 = call i32 @fputc(i8 signext 77, i32* %82)
%84 = load i8*, i8** %9
%85 = call i32 @strlen(i8* %84)
%86 = add nsw i32 16, %85
%87 = load i32, i32* %12
%88 = load i32, i32* %11
%89 = mul nsw i32 %87, %88
%90 = mul nsw i32 %89, 8
%91 = add nsw i32 %86, %90
%92 = add nsw i32 %91, 32
%93 = sext i32 %92 to i64
store i64 %93, i64* %19
%94 = load i8*, i8** %9
%95 = call i32 @strlen(i8* %94)
%96 = srem i32 %95, 8
%97 = icmp ne i32 %96, 0
br i1 %97, label %98, label %106
98: ; preds = %73
%99 = load i8*, i8** %9
%100 = call i32 @strlen(i8* %99)
%101 = srem i32 %100, 8
%102 = sub nsw i32 8, %101
%103 = sext i32 %102 to i64
%104 = load i64, i64* %19
%105 = add i64 %104, %103
store i64 %105, i64* %19
br label %106
106: ; preds = %98, %73
%107 = load i32*, i32** %14
%108 = call i32 @fput32le(i32* %107, i32 14)
%109 = load i32*, i32** %14
%110 = load i64, i64* %19
%111 = trunc i64 %110 to i32
%112 = call i32 @fput32le(i32* %109, i32 %111)
%113 = load i32*, i32** %14
%114 = call i32 @fput32le(i32* %113, i32 6)
%115 = load i32*, i32** %14
%116 = call i32 @fput32le(i32* %115, i32 8)
%117 = load i32*, i32** %14
%118 = call i32 @fputc(i8 signext 6, i32* %117)
%119 = load i32*, i32** %14
%120 = call i32 @fputc(i8 signext 4, i32* %119)
%121 = load i32*, i32** %14
%122 = call i32 @fputc(i8 signext 0, i32* %121)
%123 = load i32*, i32** %14
%124 = call i32 @fputc(i8 signext 0, i32* %123)
%125 = load i32*, i32** %14
%126 = call i32 @fput32le(i32* %125, i32 0)
%127 = load i32*, i32** %14
%128 = call i32 @fput32le(i32* %127, i32 5)
%129 = load i32*, i32** %14
%130 = call i32 @fput32le(i32* %129, i32 8)
%131 = load i32*, i32** %14
%132 = load i32, i32* %11
%133 = call i32 @fput32le(i32* %131, i32 %132)
%134 = load i32*, i32** %14
%135 = load i32, i32* %12
%136 = call i32 @fput32le(i32* %134, i32 %135)
%137 = load i32*, i32** %14
%138 = call i32 @fput32le(i32* %137, i32 1)
%139 = load i32*, i32** %14
%140 = load i8*, i8** %9
%141 = call i32 @strlen(i8* %140)
%142 = call i32 @fput32le(i32* %139, i32 %141)
store i32 0, i32* %15
br label %143
143: ; preds = %158, %106
%144 = load i8*, i8** %9
%145 = load i32, i32* %15
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds i8, i8* %144, i64 %146
%148 = load i8, i8* %147
%149 = icmp ne i8 %148, 0
br i1 %149, label %150, label %161
150: ; preds = %143
%151 = load i8*, i8** %9
%152 = load i32, i32* %15
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds i8, i8* %151, i64 %153
%155 = load i8, i8* %154
%156 = load i32*, i32** %14
%157 = call i32 @fputc(i8 signext %155, i32* %156)
br label %158
158: ; preds = %150
%159 = load i32, i32* %15
%160 = add nsw i32 %159, 1
store i32 %160, i32* %15
br label %143
161: ; preds = %143
br label %162
162: ; preds = %166, %161
%163 = load i32, i32* %15
%164 = srem i32 %163, 8
%165 = icmp ne i32 %164, 0
br i1 %165, label %166, label %171
166: ; preds = %162
%167 = load i32*, i32** %14
%168 = call i32 @fputc(i8 signext 0, i32* %167)
%169 = load i32, i32* %15
%170 = add nsw i32 %169, 1
store i32 %170, i32* %15
br label %162
171: ; preds = %162
%172 = load i32*, i32** %14
%173 = call i32 @fput32le(i32* %172, i32 9)
%174 = load i32*, i32** %14
%175 = load i32, i32* %11
%176 = load i32, i32* %12
%177 = mul nsw i32 %175, %176
%178 = mul nsw i32 %177, 8
%179 = call i32 @fput32le(i32* %174, i32 %178)
%180 = load i32, i32* %13
%181 = icmp ne i32 %180, 0
br i1 %181, label %182, label %212
182: ; preds = %171
store i32 0, i32* %15
br label %183
183: ; preds = %208, %182
%184 = load i32, i32* %15
%185 = load i32, i32* %11
%186 = icmp slt i32 %184, %185
br i1 %186, label %187, label %211
187: ; preds = %183
store i32 0, i32* %16
br label %188
188: ; preds = %204, %187
%189 = load i32, i32* %16
%190 = load i32, i32* %12
%191 = icmp slt i32 %189, %190
br i1 %191, label %192, label %207
192: ; preds = %188
%193 = load float*, float** %10
%194 = load i32, i32* %15
%195 = load i32, i32* %12
%196 = mul nsw i32 %194, %195
%197 = load i32, i32* %16
%198 = add nsw i32 %196, %197
%199 = sext i32 %198 to i64
%200 = getelementptr inbounds float, float* %193, i64 %199
%201 = load float, float* %200
%202 = load i32*, i32** %14
%203 = call i32 @fwriteieee754(float %201, i32* %202, i32 0)
br label %204
204: ; preds = %192
%205 = load i32, i32* %16
%206 = add nsw i32 %205, 1
store i32 %206, i32* %16
br label %188
207: ; preds = %188
br label %208
208: ; preds = %207
%209 = load i32, i32* %15
%210 = add nsw i32 %209, 1
store i32 %210, i32* %15
br label %183
211: ; preds = %183
br label %242
212: ; preds = %171
store i32 0, i32* %15
br label %213
213: ; preds = %238, %212
%214 = load i32, i32* %15
%215 = load i32, i32* %12
%216 = icmp slt i32 %214, %215
br i1 %216, label %217, label %241
217: ; preds = %213
store i32 0, i32* %16
br label %218
218: ; preds = %234, %217
%219 = load i32, i32* %16
%220 = load i32, i32* %11
%221 = icmp slt i32 %219, %220
br i1 %221, label %222, label %237
222: ; preds = %218
%223 = load float*, float** %10
%224 = load i32, i32* %16
%225 = load i32, i32* %12
%226 = mul nsw i32 %224, %225
%227 = load i32, i32* %15
%228 = add nsw i32 %226, %227
%229 = sext i32 %228 to i64
%230 = getelementptr inbounds float, float* %223, i64 %229
%231 = load float, float* %230
%232 = load i32*, i32** %14
%233 = call i32 @fwriteieee754(float %231, i32* %232, i32 0)
br label %234
234: ; preds = %222
%235 = load i32, i32* %16
%236 = add nsw i32 %235, 1
store i32 %236, i32* %16
br label %218
237: ; preds = %218
br label %238
238: ; preds = %237
%239 = load i32, i32* %15
%240 = add nsw i32 %239, 1
store i32 %240, i32* %15
br label %213
241: ; preds = %213
br label %242
242: ; preds = %241, %211
%243 = load i32*, i32** %14
%244 = call i64 @ferror(i32* %243)
%245 = icmp ne i64 %244, 0
br i1 %245, label %246, label %249
246: ; preds = %242
%247 = load i32*, i32** %14
%248 = call i32 @fclose(i32* %247)
store i32 -1, i32* %7
br label %256
249: ; preds = %242
%250 = load i32*, i32** %14
%251 = call i32 @fclose(i32* %250)
store i32 %251, i32* %20
%252 = load i32, i32* %20
%253 = icmp ne i32 %252, 0
br i1 %253, label %254, label %255
254: ; preds = %249
store i32 -1, i32* %7
br label %256
255: ; preds = %249
store i32 0, i32* %7
br label %256
256: ; preds = %255, %254, %246, %42
%257 = load i32, i32* %7
ret i32 %257
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [54 x i8] c"MATLAB matrix file of %s, generated by Malcolm McLean\00"
define i32 @writematmatrix(i8* nocapture %0, i8* %1, float* nocapture %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca [128 x i8]
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%9 = icmp sgt i32 %3, 0
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = icmp sgt i32 %4, 0
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32 @assert(i32 1)
%16 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %141, label %18
18: ; preds = %6
%19 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%20 = call i32 @strlen(i8* %8)
%21 = sext i32 %20 to i64
br label %22
22: ; preds = %18, %28
%23 = phi i64 [ 0, %18 ], [ %31, %28 ]
%24 = icmp slt i64 %23, %21
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %23
%27 = load i8, i8* %26
br label %28
28: ; preds = %22, %25
%29 = phi i8 [ %27, %25 ], [ 32, %22 ]
%30 = call i32 @fputc(i8 signext %29, i32* %16)
%31 = add nuw nsw i64 %23, 1
%32 = icmp eq i64 %31, 123
br i1 %32, label %33, label %22
33: ; preds = %28
%34 = call i32 @fputc(i8 signext 0, i32* %16)
%35 = call i32 @fputc(i8 signext 0, i32* %16)
%36 = call i32 @fputc(i8 signext 1, i32* %16)
%37 = call i32 @fputc(i8 signext 73, i32* %16)
%38 = call i32 @fputc(i8 signext 77, i32* %16)
%39 = call i32 @strlen(i8* %1)
%40 = shl i32 %3, 3
%41 = mul i32 %40, %4
%42 = add i32 %41, 16
%43 = add i32 %42, %39
%44 = add nsw i32 %43, 32
%45 = call i32 @strlen(i8* %1)
%46 = and i32 %45, 7
%47 = icmp eq i32 %46, 0
br i1 %47, label %53, label %48
48: ; preds = %33
%49 = call i32 @strlen(i8* %1)
%50 = srem i32 %49, 8
%51 = add i32 %43, 40
%52 = sub i32 %51, %50
br label %53
53: ; preds = %48, %33
%54 = phi i32 [ %52, %48 ], [ %44, %33 ]
%55 = call i32 @fput32le(i32* %16, i32 14)
%56 = call i32 @fput32le(i32* %16, i32 %54)
%57 = call i32 @fput32le(i32* %16, i32 6)
%58 = call i32 @fput32le(i32* %16, i32 8)
%59 = call i32 @fputc(i8 signext 6, i32* %16)
%60 = call i32 @fputc(i8 signext 4, i32* %16)
%61 = call i32 @fputc(i8 signext 0, i32* %16)
%62 = call i32 @fputc(i8 signext 0, i32* %16)
%63 = call i32 @fput32le(i32* %16, i32 0)
%64 = call i32 @fput32le(i32* %16, i32 5)
%65 = call i32 @fput32le(i32* %16, i32 8)
%66 = call i32 @fput32le(i32* %16, i32 %3)
%67 = call i32 @fput32le(i32* %16, i32 %4)
%68 = call i32 @fput32le(i32* %16, i32 1)
%69 = call i32 @strlen(i8* %1)
%70 = call i32 @fput32le(i32* %16, i32 %69)
%71 = load i8, i8* %1
%72 = icmp eq i8 %71, 0
br i1 %72, label %91, label %77
73: ; preds = %77
%74 = trunc i64 %81 to i32
%75 = and i32 %74, 7
%76 = icmp eq i32 %75, 0
br i1 %76, label %91, label %85
77: ; preds = %53, %77
%78 = phi i64 [ %81, %77 ], [ 0, %53 ]
%79 = phi i8 [ %83, %77 ], [ %71, %53 ]
%80 = call i32 @fputc(i8 signext %79, i32* %16)
%81 = add nuw i64 %78, 1
%82 = getelementptr inbounds i8, i8* %1, i64 %81
%83 = load i8, i8* %82
%84 = icmp eq i8 %83, 0
br i1 %84, label %73, label %77
85: ; preds = %73, %85
%86 = phi i32 [ %88, %85 ], [ %74, %73 ]
%87 = call i32 @fputc(i8 signext 0, i32* %16)
%88 = add i32 %86, 1
%89 = trunc i32 %88 to i3
%90 = icmp eq i3 %89, 0
br i1 %90, label %91, label %85
91: ; preds = %85, %53, %73
%92 = call i32 @fput32le(i32* %16, i32 9)
%93 = call i32 @fput32le(i32* %16, i32 %41)
%94 = icmp eq i32 %5, 0
br i1 %94, label %100, label %95
95: ; preds = %91
br i1 %9, label %96, label %134
96: ; preds = %95
%97 = sext i32 %4 to i64
%98 = zext i32 %3 to i64
%99 = zext i32 %4 to i64
br label %105
100: ; preds = %91
br i1 %12, label %101, label %134
101: ; preds = %100
%102 = zext i32 %4 to i64
%103 = zext i32 %4 to i64
%104 = zext i32 %3 to i64
br label %120
105: ; preds = %96, %117
%106 = phi i64 [ 0, %96 ], [ %118, %117 ]
br i1 %12, label %107, label %117
107: ; preds = %105
%108 = mul nsw i64 %106, %97
br label %109
109: ; preds = %107, %109
%110 = phi i64 [ 0, %107 ], [ %115, %109 ]
%111 = add nsw i64 %110, %108
%112 = getelementptr inbounds float, float* %2, i64 %111
%113 = load float, float* %112
%114 = call i32 @fwriteieee754(float %113, i32* %16, i32 0)
%115 = add nuw nsw i64 %110, 1
%116 = icmp eq i64 %115, %99
br i1 %116, label %117, label %109
117: ; preds = %109, %105
%118 = add nuw nsw i64 %106, 1
%119 = icmp eq i64 %118, %98
br i1 %119, label %134, label %105
120: ; preds = %101, %131
%121 = phi i64 [ 0, %101 ], [ %132, %131 ]
br i1 %9, label %122, label %131
122: ; preds = %120, %122
%123 = phi i64 [ %129, %122 ], [ 0, %120 ]
%124 = mul nsw i64 %123, %102
%125 = add nuw nsw i64 %124, %121
%126 = getelementptr inbounds float, float* %2, i64 %125
%127 = load float, float* %126
%128 = call i32 @fwriteieee754(float %127, i32* %16, i32 0)
%129 = add nuw nsw i64 %123, 1
%130 = icmp eq i64 %129, %104
br i1 %130, label %131, label %122
131: ; preds = %122, %120
%132 = add nuw nsw i64 %121, 1
%133 = icmp eq i64 %132, %103
br i1 %133, label %134, label %120
134: ; preds = %117, %131, %95, %100
%135 = call i64 @ferror(i32* %16)
%136 = icmp eq i64 %135, 0
%137 = call i32 @fclose(i32* %16)
br i1 %136, label %138, label %141
138: ; preds = %134
%139 = icmp ne i32 %137, 0
%140 = sext i1 %139 to i32
br label %141
141: ; preds = %134, %138, %6
%142 = phi i32 [ -1, %6 ], [ %140, %138 ], [ -1, %134 ]
ret i32 %142
}