#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*/ exit(int);
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_vector(char filename[], float *V, int nl, int nh, const char *mode) {
  FILE *fp_v;
  int i;
  time_t now;
  if ((fp_v = fopen(filename, mode)) == NULL) {
    printf(" error: cannot open file: '%s' \n", filename);
    exit(1011);
  }
  (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, "%15.6e", V[i]);
    else
      fprintf(fp_v, "    0         ");
    fprintf(fp_v, "\n");
  }
  fclose(fp_v);
  return;
}


x86 assembly (clang, -O0):
<save_vector>:
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_vector+0x4f>
mov    -0x8(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1050 <printf@plt>
mov    $0x3f3,%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     12ce <save_vector+0x15e>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1274 <save_vector+0x104>
jp     1274 <save_vector+0x104>
jmp    129c <save_vector+0x12c>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdd4(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
jmp    12ae <save_vector+0x13e>
mov    -0x28(%rbp),%rdi
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xd66(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1244 <save_vector+0xd4>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_vector>:
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     12c0 <save_vector+0x130>
mov    %rax,%rbx
lea    0x4(%rsp),%r13
mov    %r13,%rdi
call   1080 <time@plt>
mov    %r13,%rdi
call   1040 <ctime@plt>
lea    0xe4e(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe4c(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe4c(%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    0xe3a(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
sub    %r12d,%r14d
jge    1244 <save_vector+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
xor    %ebp,%ebp
lea    0xe10(%rip),%r12
lea    0xe10(%rip),%r15
jmp    129b <save_vector+0x10b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xe,%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_vector+0x9d>
movss  0x0(%r13,%rbp,4),%xmm0
ucomiss 0xd57(%rip),%xmm0
jne    12ad <save_vector+0x11d>
jnp    1270 <save_vector+0xe0>
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
jmp    1285 <save_vector+0xf5>
lea    0xd3d(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
mov    $0x3f3,%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 = [7 x i8] c"%15.6e\00"
@.str.6 = [15 x i8] c" 0 \00"
@.str.7 = [2 x i8] c"\0A\00"
define void @save_vector(i8* %0, float* %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca float*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %6
store float* %1, float** %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 %22
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)
%21 = call i32 @exit(i32 1011)
unreachable
22: ; preds = %5
%23 = call i32 @time(i32* %13)
%24 = load i32*, i32** %11
%25 = load i8*, i8** %6
%26 = call i8* @ctime(i32* %13)
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* %26)
%28 = load i32*, i32** %11
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32*, i32** %11
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 1)
%32 = load i32*, i32** %11
%33 = load i32, i32* %9
%34 = load i32, i32* %8
%35 = sub nsw i32 %33, %34
%36 = add nsw i32 %35, 1
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %8
store i32 %38, i32* %12
br label %39
39: ; preds = %65, %22
%40 = load i32, i32* %12
%41 = load i32, i32* %9
%42 = icmp sle i32 %40, %41
br i1 %42, label %43, label %68
43: ; preds = %39
%44 = load float*, float** %7
%45 = load i32, i32* %12
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds float, float* %44, i64 %46
%48 = load float, float* %47
%49 = fcmp une float %48, 0.000000e+00
br i1 %49, label %50, label %59
50: ; preds = %43
%51 = load i32*, i32** %11
%52 = load float*, float** %7
%53 = load i32, i32* %12
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds float, float* %52, i64 %54
%56 = load float, float* %55
%57 = fpext float %56 to double
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double %57)
br label %62
59: ; preds = %43
%60 = load i32*, i32** %11
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %62
62: ; preds = %59, %50
%63 = load i32*, i32** %11
%64 = call i32 (i32*, i8*, ...) @fprintf(i32* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %65
65: ; preds = %62
%66 = load i32, i32* %12
%67 = add nsw i32 %66, 1
store i32 %67, i32* %12
br label %39
68: ; preds = %39
%69 = load i32*, i32** %11
%70 = call i32 @fclose(i32* %69)
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 = [7 x i8] c"%15.6e\00"
@.str.6 = [15 x i8] c" 0 \00"
define void @save_vector(i8* %0, float* 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 %13
10: ; preds = %5
%11 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = tail call i32 @exit(i32 1011)
unreachable
13: ; preds = %5
%14 = call i32 @time(i32* %6)
%15 = call i8* @ctime(i32* %6)
%16 = 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* %15)
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 1)
%19 = sub i32 1, %2
%20 = add i32 %19, %3
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = icmp sgt i32 %2, %3
br i1 %22, label %41, label %23
23: ; preds = %13
%24 = sext i32 %2 to i64
%25 = add i32 %3, 1
br label %26
26: ; preds = %23, %36
%27 = phi i64 [ %24, %23 ], [ %38, %36 ]
%28 = getelementptr inbounds float, float* %1, i64 %27
%29 = load float, float* %28
%30 = fcmp une float %29, 0.000000e+00
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = fpext float %29 to double
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double %32)
br label %36
34: ; preds = %26
%35 = call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i64 14, i64 1, i32* %8)
br label %36
36: ; preds = %34, %31
%37 = call i32 @fputc(i32 10, i32* %8)
%38 = add nsw i64 %27, 1
%39 = trunc i64 %38 to i32
%40 = icmp eq i32 %25, %39
br i1 %40, label %41, label %26
41: ; preds = %36, %13
%42 = call i32 @fclose(i32* %8)
ret void
}