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

/* Variables and functions */
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void save_ivector(char filename[], int *V, int nl, int nh, const char *mode) {
  FILE *fp_v;
  int i;
  void exit();
  time_t now;
  if ((fp_v = fopen(filename, mode)) == NULL) {
    printf(" error: cannot open file: '%s' \n", filename);
    exit(1012);
  }
  (void)time(&now);
  fprintf(fp_v, "%% filename: %s - %s", filename, ctime(&now));
  fprintf(fp_v, "%% type: vector\n");
  fprintf(fp_v, "%% rows: %d\n", 1);
  fprintf(fp_v, "%% columns: %d\n", nh - nl + 1);
  for (i = nl; i <= nh; i++) {
    if (V[i] != 0)
      fprintf(fp_v, "%15d", V[i]);
    else
      fprintf(fp_v, "   0         ");
    fprintf(fp_v, "\n");
  }
  fclose(fp_v);
  return;
}


x86 assembly (clang, -O0):
<save_ivector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11bf <save_ivector+0x4f>
mov    -0x8(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1050 <printf@plt>
mov    $0x3f4,%edi
call   1090 <exit@plt>
lea    -0x30(%rbp),%rdi
call   1070 <time@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe30(%rip),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%edx
sub    -0x14(%rbp),%edx
add    $0x1,%edx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     12b6 <save_ivector+0x146>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     1284 <save_ivector+0x114>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1296 <save_ivector+0x126>
mov    -0x28(%rbp),%rdi
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xd7e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1244 <save_ivector+0xd4>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_ivector>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r12d
mov    %rsi,%r15
mov    %rdi,%rbp
mov    %r8,%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12b3 <save_ivector+0x123>
mov    %rax,%rbx
lea    0x4(%rsp),%r13
mov    %r13,%rdi
call   1080 <time@plt>
mov    %r13,%rdi
call   1040 <ctime@plt>
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe48(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe48(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14d,%edx
sub    %r12d,%edx
add    $0x1,%edx
lea    0xe36(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
sub    %r12d,%r14d
jge    1244 <save_ivector+0xb4>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movslq %r12d,%rax
lea    (%r15,%rax,4),%r13
add    $0x1,%r14d
lea    0xe13(%rip),%r15
lea    0xe07(%rip),%r12
xor    %ebp,%ebp
jmp    129b <save_ivector+0x10b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xd,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
add    $0x1,%rbp
cmp    %ebp,%r14d
je     122d <save_ivector+0x9d>
mov    0x0(%r13,%rbp,4),%edx
test   %edx,%edx
je     1270 <save_ivector+0xe0>
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1285 <save_ivector+0xf5>
lea    0xd46(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
mov    $0x3f4,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c" error: cannot open file: '%s' \0A\00"
@.str.1 = [21 x i8] c"%% filename: %s - %s\00"
@.str.2 = [17 x i8] c"%% type: vector\0A\00"
@.str.3 = [13 x i8] c"%% rows: %d\0A\00"
@.str.4 = [16 x i8] c"%% columns: %d\0A\00"
@.str.5 = [5 x i8] c"%15d\00"
@.str.6 = [14 x i8] c" 0 \00"
@.str.7 = [2 x i8] c"\0A\00"
define void @save_ivector(i8* %0, i32* %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%14 = load i8*, i8** %6
%15 = load i8*, i8** %10
%16 = call i32* @fopen(i8* %14, i8* %15)
store i32* %16, i32** %11
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %5
%19 = load i8*, i8** %6
%20 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %19)
unreachable
21: ; preds = %5
%22 = call i32 @time(i32* %13)
%23 = load i32*, i32** %11
%24 = load i8*, i8** %6
%25 = call i8* @ctime(i32* %13)
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %25)
%27 = load i32*, i32** %11
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32*, i32** %11
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 1)
%31 = load i32*, i32** %11
%32 = load i32, i32* %9
%33 = load i32, i32* %8
%34 = sub nsw i32 %32, %33
%35 = add nsw i32 %34, 1
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %8
store i32 %37, i32* %12
br label %38
38: ; preds = %63, %21
%39 = load i32, i32* %12
%40 = load i32, i32* %9
%41 = icmp sle i32 %39, %40
br i1 %41, label %42, label %66
42: ; preds = %38
%43 = load i32*, i32** %7
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
%47 = load i32, i32* %46
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %57
49: ; preds = %42
%50 = load i32*, i32** %11
%51 = load i32*, i32** %7
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
%55 = load i32, i32* %54
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %55)
br label %60
57: ; preds = %42
%58 = load i32*, i32** %11
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %60
60: ; preds = %57, %49
%61 = load i32*, i32** %11
%62 = call i32 (i32*, i8*, ...) @fprintf(i32* %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %63
63: ; preds = %60
%64 = load i32, i32* %12
%65 = add nsw i32 %64, 1
store i32 %65, i32* %12
br label %38
66: ; preds = %38
%67 = load i32*, i32** %11
%68 = call i32 @fclose(i32* %67)
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c" error: cannot open file: '%s' \0A\00"
@.str.1 = [21 x i8] c"%% filename: %s - %s\00"
@.str.2 = [17 x i8] c"%% type: vector\0A\00"
@.str.3 = [13 x i8] c"%% rows: %d\0A\00"
@.str.4 = [16 x i8] c"%% columns: %d\0A\00"
@.str.5 = [5 x i8] c"%15d\00"
@.str.6 = [14 x i8] c" 0 \00"
define void @save_ivector(i8* %0, i32* nocapture %1, i32 %2, i32 %3, i8* nocapture %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = tail call i32* @fopen(i8* %0, i8* %4)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
tail call void @exit(i32 1012)
unreachable
12: ; preds = %5
%13 = call i32 @time(i32* %6)
%14 = call i8* @ctime(i32* %6)
%15 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %14)
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 1)
%18 = sub i32 1, %2
%19 = add i32 %18, %3
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = icmp sgt i32 %2, %3
br i1 %21, label %39, label %22
22: ; preds = %12
%23 = sext i32 %2 to i64
%24 = add i32 %3, 1
br label %25
25: ; preds = %22, %34
%26 = phi i64 [ %23, %22 ], [ %36, %34 ]
%27 = getelementptr inbounds i32, i32* %1, i64 %26
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %25
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %28)
br label %34
32: ; preds = %25
%33 = call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i64 13, i64 1, i32* %8)
br label %34
34: ; preds = %32, %30
%35 = call i32 @fputc(i32 10, i32* %8)
%36 = add nsw i64 %26, 1
%37 = trunc i64 %36 to i32
%38 = icmp eq i32 %24, %37
br i1 %38, label %39, label %25
39: ; preds = %34, %12
%40 = call i32 @fclose(i32* %8)
ret void
}