#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_vector(char filename[], float *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(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 %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 = %64, %21
%39 = load i32, i32* %12
%40 = load i32, i32* %9
%41 = icmp sle i32 %39, %40
br i1 %41, label %42, label %67
42: ; preds = %38
%43 = load float*, float** %7
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds float, float* %43, i64 %45
%47 = load float, float* %46
%48 = fcmp une float %47, 0.000000e+00
br i1 %48, label %49, label %58
49: ; preds = %42
%50 = load i32*, i32** %11
%51 = load float*, float** %7
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds float, float* %51, i64 %53
%55 = load float, float* %54
%56 = fpext float %55 to double
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double %56)
br label %61
58: ; preds = %42
%59 = load i32*, i32** %11
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %61
61: ; preds = %58, %49
%62 = load i32*, i32** %11
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %64
64: ; preds = %61
%65 = load i32, i32* %12
%66 = add nsw i32 %65, 1
store i32 %66, i32* %12
br label %38
67: ; preds = %38
%68 = load i32*, i32** %11
%69 = call i32 @fclose(i32* %68)
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 %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 1011)
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 %40, label %22
22: ; preds = %12
%23 = sext i32 %2 to i64
%24 = add i32 %3, 1
br label %25
25: ; preds = %22, %35
%26 = phi i64 [ %23, %22 ], [ %37, %35 ]
%27 = getelementptr inbounds float, float* %1, i64 %26
%28 = load float, float* %27
%29 = fcmp une float %28, 0.000000e+00
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = fpext float %28 to double
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), double %31)
br label %35
33: ; preds = %25
%34 = 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 %35
35: ; preds = %33, %30
%36 = call i32 @fputc(i32 10, i32* %8)
%37 = add nsw i64 %26, 1
%38 = trunc i64 %37 to i32
%39 = icmp eq i32 %24, %38
br i1 %39, label %40, label %25
40: ; preds = %35, %12
%41 = call i32 @fclose(i32* %8)
ret void
}