#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int oct_save_short(short *a, short *b, int len) {
  FILE *file;
  int k;
  if (!(file = fopen("error.dat", "w")))
    return 1;
  fprintf(file, "# Not created by Octave\n");
  fprintf(file, "# name: a\n");
  fprintf(file, "# type: matrix\n");
  fprintf(file, "# rows: %d\n", len);
  fprintf(file, "# columns: 1\n");
  for (k = 0; k < len; k++)
    fprintf(file, "% d\n", a[k]);
  fprintf(file, "# name: b\n");
  fprintf(file, "# type: matrix\n");
  fprintf(file, "# rows: %d\n", len);
  fprintf(file, "# columns: 1\n");
  for (k = 0; k < len; k++)
    fprintf(file, "% d\n", b[k]);
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<oct_save_short>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
lea    0xeb6(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1170 <oct_save_short+0x40>
movl   $0x1,-0x4(%rbp)
jmp    12a6 <oct_save_short+0x176>
mov    -0x28(%rbp),%rdi
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe8c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    120c <oct_save_short+0xdc>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movswl (%rax,%rcx,2),%edx
lea    0xe63(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d4 <oct_save_short+0xa4>
mov    -0x28(%rbp),%rdi
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1296 <oct_save_short+0x166>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movswl (%rax,%rcx,2),%edx
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    125e <oct_save_short+0x12e>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oct_save_short>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xea6(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     12bd <oct_save_short+0x17d>
mov    %rax,%r13
lea    0xe93(%rip),%rdi
mov    $0x18,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
lea    0xe93(%rip),%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1060 <fwrite@plt>
lea    0xe85(%rip),%rdi
mov    $0xf,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1060 <fwrite@plt>
lea    0xe7c(%rip),%rsi
mov    %r13,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe75(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1060 <fwrite@plt>
test   %ebx,%ebx
jle    12c4 <oct_save_short+0x184>
mov    %ebx,0x4(%rsp)
mov    %ebx,%ebx
lea    0xe5c(%rip),%rbp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movswl (%r12,%r14,2),%edx
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%r14
cmp    %r14,%rbx
jne    1210 <oct_save_short+0xd0>
lea    0xe2d(%rip),%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1060 <fwrite@plt>
lea    0xde5(%rip),%rdi
mov    $0xf,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1060 <fwrite@plt>
lea    0xddc(%rip),%rsi
mov    %r13,%rdi
mov    0x4(%rsp),%ebp
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xdd1(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1060 <fwrite@plt>
test   %ebp,%ebp
jle    1322 <oct_save_short+0x1e2>
lea    0xdbe(%rip),%r14
xor    %ebp,%ebp
xchg   %ax,%ax
movswl (%r15,%rbp,2),%edx
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    12a0 <oct_save_short+0x160>
jmp    1322 <oct_save_short+0x1e2>
mov    $0x1,%eax
jmp    132c <oct_save_short+0x1ec>
lea    0xd94(%rip),%rdi
mov    $0xa,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1060 <fwrite@plt>
lea    0xd4c(%rip),%rdi
mov    $0xf,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1060 <fwrite@plt>
lea    0xd43(%rip),%rsi
mov    %r13,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xd3c(%rip),%rdi
mov    $0xd,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1060 <fwrite@plt>
mov    %r13,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"error.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [25 x i8] c"# Not created by Octave\0A\00"
@.str.3 = [11 x i8] c"# name: a\0A\00"
@.str.4 = [16 x i8] c"# type: matrix\0A\00"
@.str.5 = [12 x i8] c"# rows: %d\0A\00"
@.str.6 = [14 x i8] c"# columns: 1\0A\00"
@.str.7 = [5 x i8] c"% d\0A\00"
@.str.8 = [11 x i8] c"# name: b\0A\00"
define i32 @oct_save_short(i16* %0, i16* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i16*
%6 = alloca i16*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i16* %0, i16** %5
store i16* %1, i16** %6
store i32 %2, i32* %7
%10 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %8
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %3
store i32 1, i32* %4
br label %70
13: ; preds = %3
%14 = load i32*, i32** %8
%15 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32*, i32** %8
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%18 = load i32*, i32** %8
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%20 = load i32*, i32** %8
%21 = load i32, i32* %7
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%23 = load i32*, i32** %8
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %9
br label %25
25: ; preds = %38, %13
%26 = load i32, i32* %9
%27 = load i32, i32* %7
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %41
29: ; preds = %25
%30 = load i32*, i32** %8
%31 = load i16*, i16** %5
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i16, i16* %31, i64 %33
%35 = load i16, i16* %34
%36 = sext i16 %35 to i32
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %29
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %25
41: ; preds = %25
%42 = load i32*, i32** %8
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%44 = load i32*, i32** %8
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%46 = load i32*, i32** %8
%47 = load i32, i32* %7
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %47)
%49 = load i32*, i32** %8
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %9
br label %51
51: ; preds = %64, %41
%52 = load i32, i32* %9
%53 = load i32, i32* %7
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %67
55: ; preds = %51
%56 = load i32*, i32** %8
%57 = load i16*, i16** %6
%58 = load i32, i32* %9
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i16, i16* %57, i64 %59
%61 = load i16, i16* %60
%62 = sext i16 %61 to i32
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %62)
br label %64
64: ; preds = %55
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
br label %51
67: ; preds = %51
%68 = load i32*, i32** %8
%69 = call i32 @fclose(i32* %68)
store i32 0, i32* %4
br label %70
70: ; preds = %67, %12
%71 = load i32, i32* %4
ret i32 %71
}

LLVM IR (-O2):
@.str = [10 x i8] c"error.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [25 x i8] c"# Not created by Octave\0A\00"
@.str.3 = [11 x i8] c"# name: a\0A\00"
@.str.4 = [16 x i8] c"# type: matrix\0A\00"
@.str.5 = [12 x i8] c"# rows: %d\0A\00"
@.str.6 = [14 x i8] c"# columns: 1\0A\00"
@.str.7 = [5 x i8] c"% d\0A\00"
@.str.8 = [11 x i8] c"# name: b\0A\00"
define i32 @oct_save_short(i16* nocapture %0, i16* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %45, label %6
6: ; preds = %3
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 24, i64 1, i32* %4)
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 10, i64 1, i32* %4)
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i64 15, i64 1, i32* %4)
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %2)
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i64 13, i64 1, i32* %4)
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %38
13: ; preds = %6
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %21, %15 ]
%17 = getelementptr inbounds i16, i16* %0, i64 %16
%18 = load i16, i16* %17
%19 = sext i16 %18 to i32
%20 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %19)
%21 = add nuw nsw i64 %16, 1
%22 = icmp eq i64 %21, %14
br i1 %22, label %23, label %15
23: ; preds = %15
%24 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i64 10, i64 1, i32* %4)
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i64 15, i64 1, i32* %4)
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %2)
%27 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i64 13, i64 1, i32* %4)
br i1 %12, label %28, label %43
28: ; preds = %23
%29 = zext i32 %2 to i64
br label %30
30: ; preds = %28, %30
%31 = phi i64 [ 0, %28 ], [ %36, %30 ]
%32 = getelementptr inbounds i16, i16* %1, i64 %31
%33 = load i16, i16* %32
%34 = sext i16 %33 to i32
%35 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %34)
%36 = add nuw nsw i64 %31, 1
%37 = icmp eq i64 %36, %29
br i1 %37, label %43, label %30
38: ; preds = %6
%39 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i64 10, i64 1, i32* %4)
%40 = tail call i64 @fwrite(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i64 15, i64 1, i32* %4)
%41 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %2)
%42 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i64 13, i64 1, i32* %4)
br label %43
43: ; preds = %30, %38, %23
%44 = tail call i32 @fclose(i32* %4)
br label %45
45: ; preds = %3, %43
%46 = phi i32 [ 0, %43 ], [ 1, %3 ]
ret i32 %46
}