#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 /*<<< orphan*/);
void octave_save_int(FILE *f, char name[], int data[], int rows, int cols) {
  int r, c;
  char buffer[2048];
  size_t buf_idx = 0;
  printf_header(f, buffer, 2048, &buf_idx, name, "matrix", rows, cols, 0);
  for (r = 0; r < rows; r++) {
    for (c = 0; c < cols; c++)
      printf_buffer(f, buffer, 2048, &buf_idx, " %d", data[r * cols + 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_int>:
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)
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    0xe7e(%rip),%r9
xor    %r11d,%r11d
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
movl   $0x0,0x10(%rsp)
call   1030 <printf_header@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    123b <octave_save_int+0x10b>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1208 <octave_save_int+0xd8>
mov    -0x8(%rbp),%rdi
lea    -0x830(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x20(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%r9d
mov    $0x800,%edx
lea    -0x838(%rbp),%rcx
lea    0xe14(%rip),%r8
mov    $0x0,%al
call   1040 <printf_buffer@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11b4 <octave_save_int+0x84>
mov    -0x8(%rbp),%rdi
lea    -0x830(%rbp),%rsi
mov    $0x800,%edx
lea    -0x838(%rbp),%rcx
lea    0xde6(%rip),%r8
mov    $0x0,%al
call   1040 <printf_buffer@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a1 <octave_save_int+0x71>
mov    -0x8(%rbp),%rdi
lea    -0x830(%rbp),%rsi
mov    $0x800,%edx
lea    -0x838(%rbp),%rcx
lea    0xdb2(%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_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x848,%rsp
mov    %r8d,%ebp
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %rsi,%r8
mov    %rdi,%r12
movq   $0x0,0x8(%rsp)
sub    $0x8,%rsp
lea    0xe9c(%rip),%r9
lea    0x48(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    $0x800,%edx
push   $0x0
mov    %rbp,0x20(%rsp)
push   %rbp
push   %r14
call   1030 <printf_header@plt>
add    $0x20,%rsp
test   %r14d,%r14d
jle    1265 <octave_save_int+0x135>
mov    0x10(%rsp),%rax
movslq %eax,%rcx
mov    %r14d,%edx
mov    %rdx,0x28(%rsp)
mov    %eax,%eax
mov    %rax,0x20(%rsp)
shl    $0x2,%rcx
mov    %rcx,0x30(%rsp)
lea    0x40(%rsp),%rbp
lea    0x8(%rsp),%r14
xor    %eax,%eax
mov    0x20(%rsp),%r13
jmp    120c <octave_save_int+0xdc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%r12
mov    %rbp,%rdi
mov    %rax,%rbp
mov    %rax,%rsi
mov    $0x800,%edx
mov    %r14,%rcx
lea    0xe21(%rip),%r8
xor    %eax,%eax
call   1040 <printf_buffer@plt>
mov    0x38(%rsp),%rax
add    $0x1,%rax
mov    0x18(%rsp),%rbx
add    0x30(%rsp),%rbx
cmp    0x28(%rsp),%rax
je     1265 <octave_save_int+0x135>
mov    %rbx,0x18(%rsp)
mov    %rax,0x38(%rsp)
cmpl   $0x0,0x10(%rsp)
lea    0xde5(%rip),%rbx
mov    %rbp,%rax
mov    %r12,%rbp
jle    11d0 <octave_save_int+0xa0>
xor    %r12d,%r12d
nopl   (%rax)
mov    0x18(%rsp),%rcx
mov    (%rcx,%r12,4),%r9d
mov    %rbp,%rdi
mov    %rax,%r15
mov    %rax,%rsi
mov    $0x800,%edx
mov    %r14,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1040 <printf_buffer@plt>
mov    %r15,%rax
add    $0x1,%r12
cmp    %r12,%r13
jne    1230 <octave_save_int+0x100>
jmp    11d0 <octave_save_int+0xa0>
lea    0xd9f(%rip),%r8
lea    0x40(%rsp),%rbx
lea    0x8(%rsp),%rbp
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x800,%edx
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <printf_buffer@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1050 <flush_buffer@plt>
add    $0x848,%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" %d\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [3 x i8] c"\0A\0A\00"
define void @octave_save_int(i32* %0, i8* %1, i32* %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [2048 x i8]
%14 = alloca i64
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i64 0, i64* %14
%15 = load i32*, i32** %6
%16 = getelementptr inbounds [2048 x i8], [2048 x i8]* %13, i64 0, i64 0
%17 = load i8*, i8** %7
%18 = load i32, i32* %9
%19 = load i32, i32* %10
%20 = call i32 @printf_header(i32* %15, i8* %16, i32 2048, i64* %14, i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19, i32 0)
store i32 0, i32* %11
br label %21
21: ; preds = %50, %5
%22 = load i32, i32* %11
%23 = load i32, i32* %9
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %53
25: ; preds = %21
store i32 0, i32* %12
br label %26
26: ; preds = %43, %25
%27 = load i32, i32* %12
%28 = load i32, i32* %10
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %46
30: ; preds = %26
%31 = load i32*, i32** %6
%32 = getelementptr inbounds [2048 x i8], [2048 x i8]* %13, i64 0, i64 0
%33 = load i32*, i32** %8
%34 = load i32, i32* %11
%35 = load i32, i32* %10
%36 = mul nsw i32 %34, %35
%37 = load i32, i32* %12
%38 = add nsw i32 %36, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %33, i64 %39
%41 = load i32, i32* %40
%42 = call i32 (i32*, i8*, i32, i64*, i8*, ...) @printf_buffer(i32* %31, i8* %32, i32 2048, i64* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %30
%44 = load i32, i32* %12
%45 = add nsw i32 %44, 1
store i32 %45, i32* %12
br label %26
46: ; preds = %26
%47 = load i32*, i32** %6
%48 = getelementptr inbounds [2048 x i8], [2048 x i8]* %13, i64 0, i64 0
%49 = call i32 (i32*, i8*, i32, i64*, i8*, ...) @printf_buffer(i32* %47, i8* %48, i32 2048, i64* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %46
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %21
53: ; preds = %21
%54 = load i32*, i32** %6
%55 = getelementptr inbounds [2048 x i8], [2048 x i8]* %13, i64 0, i64 0
%56 = call i32 (i32*, i8*, i32, i64*, i8*, ...) @printf_buffer(i32* %54, i8* %55, i32 2048, i64* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%57 = load i32*, i32** %6
%58 = getelementptr inbounds [2048 x i8], [2048 x i8]* %13, i64 0, i64 0
%59 = call i32 @flush_buffer(i32* %57, i8* %58, i64* %14)
ret void
}

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