#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
double fabs(double);
int /*<<< orphan*/ printf(char *, ...);
double sqrt(double);
void random_start_vector(int numSD, double *start_vec) {
  int phase, loop;
  double *ptr, value, norm;
  ptr = start_vec;
  phase = +1;
  norm = 0.0;
  for (loop = 0; loop < numSD; loop++) {
    *(ptr++) = (value = 1.0 + ((double)loop) / numSD, value * phase);
    norm += value * value;
    phase = -phase;
  }
  if (fabs(norm) < 1.0E-10) {
    printf("\n\nError in function  random_start_vector():");
    printf("\nNorm of the initial random lanczos vector is below");
    printf(" accepted limit: norm = %E", norm);
    exit(1);
  }
  norm = 1.0 / sqrt(norm);
  ptr = start_vec;
  for (loop = 0; loop < numSD; loop++) {
    *(ptr++) *= norm;
  }
}


x86 assembly (clang, -O0):
<random_start_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11db <random_start_vector+0xab>
cvtsi2sdl -0x18(%rbp),%xmm1
cvtsi2sdl -0x4(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe89(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x20(%rbp)
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
xor    %eax,%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115d <random_start_vector+0x2d>
movsd  -0x30(%rbp),%xmm1
movaps 0xe29(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe0d(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1236 <random_start_vector+0x106>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm0
lea    0xe5b(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movsd  -0x30(%rbp),%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xdbd(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1299 <random_start_vector+0x169>
movsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x20(%rbp)
mulsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1263 <random_start_vector+0x133>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_start_vector>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
test   %edi,%edi
jle    1166 <random_start_vector+0x36>
cvtsi2sd %r14d,%xmm7
cmp    $0x1,%r14d
jne    116f <random_start_vector+0x3f>
xorpd  %xmm0,%xmm0
mov    %rbx,%rax
xorpd  %xmm1,%xmm1
test   $0x1,%r14b
jne    11fb <random_start_vector+0xcb>
jmp    1213 <random_start_vector+0xe3>
xorpd  %xmm0,%xmm0
jmp    1213 <random_start_vector+0xe3>
mov    %r14d,%edx
and    $0xfffffffe,%edx
xor    %ecx,%ecx
xorpd  %xmm0,%xmm0
movsd  0xe7d(%rip),%xmm1
movapd 0xe95(%rip),%xmm2
movsd  0xe75(%rip),%xmm3
mov    %rbx,%rax
xorpd  %xmm4,%xmm4
nopw   0x0(%rax,%rax,1)
movapd %xmm4,%xmm5
divsd  %xmm7,%xmm5
addsd  %xmm1,%xmm5
movsd  %xmm5,(%rax)
mulsd  %xmm5,%xmm5
addsd  %xmm0,%xmm5
lea    0x1(%rcx),%esi
xorps  %xmm0,%xmm0
cvtsi2sd %esi,%xmm0
divsd  %xmm7,%xmm0
addsd  %xmm1,%xmm0
movapd %xmm0,%xmm6
xorpd  %xmm2,%xmm6
movlpd %xmm6,0x8(%rax)
add    $0x10,%rax
mulsd  %xmm0,%xmm0
addsd  %xmm5,%xmm0
addsd  %xmm3,%xmm4
add    $0x2,%ecx
cmp    %ecx,%edx
jne    11a0 <random_start_vector+0x70>
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
test   $0x1,%r14b
je     1213 <random_start_vector+0xe3>
divsd  %xmm7,%xmm1
addsd  0xdf9(%rip),%xmm1
movsd  %xmm1,(%rax)
mulsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
movapd 0xe15(%rip),%xmm2
andpd  %xmm0,%xmm2
movsd  0xde9(%rip),%xmm1
ucomisd %xmm2,%xmm1
ja     1359 <random_start_vector+0x229>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1249 <random_start_vector+0x119>
sqrtsd %xmm0,%xmm0
test   %r14d,%r14d
jg     1257 <random_start_vector+0x127>
jmp    1347 <random_start_vector+0x217>
call   1040 <sqrt@plt>
test   %r14d,%r14d
jle    1347 <random_start_vector+0x217>
movsd  0xda1(%rip),%xmm1
divsd  %xmm0,%xmm1
lea    -0x1(%r14),%ecx
xor    %eax,%eax
cmp    $0x3,%ecx
jb     1325 <random_start_vector+0x1f5>
add    $0x1,%rcx
mov    %rcx,%rax
and    $0xfffffffffffffffc,%rax
movapd %xmm1,%xmm0
unpcklpd %xmm1,%xmm0
lea    -0x4(%rax),%rdx
mov    %rdx,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
test   %rdx,%rdx
je     134f <random_start_vector+0x21f>
mov    %rsi,%rdi
and    $0xfffffffffffffffe,%rdi
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
movupd (%rbx,%rdx,8),%xmm2
movupd 0x10(%rbx,%rdx,8),%xmm3
movupd 0x20(%rbx,%rdx,8),%xmm4
movupd 0x30(%rbx,%rdx,8),%xmm5
mulpd  %xmm0,%xmm2
mulpd  %xmm0,%xmm3
movupd %xmm2,(%rbx,%rdx,8)
movupd %xmm3,0x10(%rbx,%rdx,8)
mulpd  %xmm0,%xmm4
mulpd  %xmm0,%xmm5
movupd %xmm4,0x20(%rbx,%rdx,8)
movupd %xmm5,0x30(%rbx,%rdx,8)
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rdi
jne    12b0 <random_start_vector+0x180>
test   $0x1,%sil
je     131c <random_start_vector+0x1ec>
movupd (%rbx,%rdx,8),%xmm2
movupd 0x10(%rbx,%rdx,8),%xmm3
mulpd  %xmm0,%xmm2
mulpd  %xmm0,%xmm3
movupd %xmm2,(%rbx,%rdx,8)
movupd %xmm3,0x10(%rbx,%rdx,8)
cmp    %rax,%rcx
je     1347 <random_start_vector+0x217>
lea    (%rbx,%rax,8),%rbx
sub    %eax,%r14d
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movsd  (%rbx,%rax,8),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%rax,8)
add    $0x1,%rax
cmp    %eax,%r14d
jne    1330 <random_start_vector+0x200>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
xor    %edx,%edx
test   $0x1,%sil
jne    12fe <random_start_vector+0x1ce>
jmp    131c <random_start_vector+0x1ec>
lea    0xce0(%rip),%rdi
xor    %eax,%eax
movapd %xmm0,(%rsp)
call   1030 <printf@plt>
lea    0xcf9(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xd1f(%rip),%rdi
movaps (%rsp),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"\0A\0AError in function random_start_vector():\00"
@.str.1 = [52 x i8] c"\0ANorm of the initial random lanczos vector is below\00"
@.str.2 = [27 x i8] c" accepted limit: norm = %E\00"
define void @random_start_vector(i32 %0, double* %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca double
%9 = alloca double
store i32 %0, i32* %3
store double* %1, double** %4
%10 = load double*, double** %4
store double* %10, double** %7
store i32 1, i32* %5
store double 0.000000e+00, double* %9
store i32 0, i32* %6
br label %11
11: ; preds = %34, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %37
15: ; preds = %11
%16 = load i32, i32* %6
%17 = sitofp i32 %16 to double
%18 = load i32, i32* %3
%19 = sitofp i32 %18 to double
%20 = fdiv double %17, %19
%21 = fadd double 1.000000e+00, %20
store double %21, double* %8
%22 = load double, double* %8
%23 = load i32, i32* %5
%24 = sitofp i32 %23 to double
%25 = fmul double %22, %24
%26 = load double*, double** %7
%27 = getelementptr inbounds double, double* %26, i32 1
store double* %27, double** %7
store double %25, double* %26
%28 = load double, double* %8
%29 = load double, double* %8
%30 = load double, double* %9
%31 = call double @llvm.fmuladd.f64(double %28, double %29, double %30)
store double %31, double* %9
%32 = load i32, i32* %5
%33 = sub nsw i32 0, %32
store i32 %33, i32* %5
br label %34
34: ; preds = %15
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %11
37: ; preds = %11
%38 = load double, double* %9
%39 = call double @llvm.fabs.f64(double %38)
%40 = fcmp olt double %39, 1.000000e-10
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%44 = load double, double* %9
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), double %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %37
%48 = load double, double* %9
%49 = call double @sqrt(double %48)
%50 = fdiv double 1.000000e+00, %49
store double %50, double* %9
%51 = load double*, double** %4
store double* %51, double** %7
store i32 0, i32* %6
br label %52
52: ; preds = %62, %47
%53 = load i32, i32* %6
%54 = load i32, i32* %3
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %65
56: ; preds = %52
%57 = load double, double* %9
%58 = load double*, double** %7
%59 = getelementptr inbounds double, double* %58, i32 1
store double* %59, double** %7
%60 = load double, double* %58
%61 = fmul double %60, %57
store double %61, double* %58
br label %62
62: ; preds = %56
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %52
65: ; preds = %52
ret void
}

LLVM IR (-O2):
@.str = [44 x i8] c"\0A\0AError in function random_start_vector():\00"
@.str.1 = [52 x i8] c"\0ANorm of the initial random lanczos vector is below\00"
@.str.2 = [27 x i8] c" accepted limit: norm = %E\00"
define void @random_start_vector(i32 %0, double* nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %42
4: ; preds = %2
%5 = sitofp i32 %0 to double
%6 = and i32 %0, 1
%7 = icmp eq i32 %0, 1
br i1 %7, label %32, label %8
8: ; preds = %4
%9 = and i32 %0, -2
br label %10
10: ; preds = %10, %8
%11 = phi double [ 0.000000e+00, %8 ], [ %26, %10 ]
%12 = phi double* [ %1, %8 ], [ %25, %10 ]
%13 = phi i32 [ 0, %8 ], [ %27, %10 ]
%14 = phi i32 [ 0, %8 ], [ %28, %10 ]
%15 = sitofp i32 %13 to double
%16 = fdiv double %15, %5
%17 = fadd double %16, 1.000000e+00
%18 = getelementptr inbounds double, double* %12, i64 1
store double %17, double* %12
%19 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %11)
%20 = or i32 %13, 1
%21 = sitofp i32 %20 to double
%22 = fdiv double %21, %5
%23 = fadd double %22, 1.000000e+00
%24 = fneg double %23
%25 = getelementptr inbounds double, double* %12, i64 2
store double %24, double* %18
%26 = tail call double @llvm.fmuladd.f64(double %23, double %23, double %19)
%27 = add nuw nsw i32 %13, 2
%28 = add i32 %14, 2
%29 = icmp eq i32 %28, %9
br i1 %29, label %30, label %10
30: ; preds = %10
%31 = sitofp i32 %27 to double
br label %32
32: ; preds = %30, %4
%33 = phi double [ undef, %4 ], [ %26, %30 ]
%34 = phi double [ 0.000000e+00, %4 ], [ %26, %30 ]
%35 = phi double* [ %1, %4 ], [ %25, %30 ]
%36 = phi double [ 0.000000e+00, %4 ], [ %31, %30 ]
%37 = icmp eq i32 %6, 0
br i1 %37, label %42, label %38
38: ; preds = %32
%39 = fdiv double %36, %5
%40 = fadd double %39, 1.000000e+00
store double %40, double* %35
%41 = tail call double @llvm.fmuladd.f64(double %40, double %40, double %34)
br label %42
42: ; preds = %38, %32, %2
%43 = phi double [ 0.000000e+00, %2 ], [ %33, %32 ], [ %41, %38 ]
%44 = tail call double @llvm.fabs.f64(double %43)
%45 = fcmp olt double %44, 1.000000e-10
br i1 %45, label %46, label %51
46: ; preds = %42
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), double %43)
%50 = tail call i32 @exit(i32 1)
unreachable
51: ; preds = %42
%52 = tail call double @sqrt(double %43)
%53 = fdiv double 1.000000e+00, %52
br i1 %3, label %54, label %128
54: ; preds = %51
%55 = add i32 %0, -1
%56 = zext i32 %55 to i64
%57 = add nuw nsw i64 %56, 1
%58 = icmp ult i32 %55, 3
br i1 %58, label %117, label %59
59: ; preds = %54
%60 = and i64 %57, 8589934588
%61 = getelementptr double, double* %1, i64 %60
%62 = trunc i64 %60 to i32
%63 = insertelement <2 x double> poison, double %53, i64 0
%64 = shufflevector <2 x double> %63, <2 x double> poison, <2 x i32> zeroinitializer
%65 = insertelement <2 x double> poison, double %53, i64 0
%66 = shufflevector <2 x double> %65, <2 x double> poison, <2 x i32> zeroinitializer
%67 = add nsw i64 %60, -4
%68 = lshr exact i64 %67, 2
%69 = add nuw nsw i64 %68, 1
%70 = and i64 %69, 1
%71 = icmp eq i64 %67, 0
br i1 %71, label %101, label %72
72: ; preds = %59
%73 = and i64 %69, 9223372036854775806
br label %74
74: ; preds = %74, %72
%75 = phi i64 [ 0, %72 ], [ %98, %74 ]
%76 = phi i64 [ 0, %72 ], [ %99, %74 ]
%77 = getelementptr double, double* %1, i64 %75
%78 = bitcast double* %77 to <2 x double>*
%79 = load <2 x double>, <2 x double>* %78
%80 = getelementptr double, double* %77, i64 2
%81 = bitcast double* %80 to <2 x double>*
%82 = load <2 x double>, <2 x double>* %81
%83 = fmul <2 x double> %64, %79
%84 = fmul <2 x double> %66, %82
%85 = bitcast double* %77 to <2 x double>*
store <2 x double> %83, <2 x double>* %85
%86 = bitcast double* %80 to <2 x double>*
store <2 x double> %84, <2 x double>* %86
%87 = or i64 %75, 4
%88 = getelementptr double, double* %1, i64 %87
%89 = bitcast double* %88 to <2 x double>*
%90 = load <2 x double>, <2 x double>* %89
%91 = getelementptr double, double* %88, i64 2
%92 = bitcast double* %91 to <2 x double>*
%93 = load <2 x double>, <2 x double>* %92
%94 = fmul <2 x double> %64, %90
%95 = fmul <2 x double> %66, %93
%96 = bitcast double* %88 to <2 x double>*
store <2 x double> %94, <2 x double>* %96
%97 = bitcast double* %91 to <2 x double>*
store <2 x double> %95, <2 x double>* %97
%98 = add nuw i64 %75, 8
%99 = add i64 %76, 2
%100 = icmp eq i64 %99, %73
br i1 %100, label %101, label %74
101: ; preds = %74, %59
%102 = phi i64 [ 0, %59 ], [ %98, %74 ]
%103 = icmp eq i64 %70, 0
br i1 %103, label %115, label %104
104: ; preds = %101
%105 = getelementptr double, double* %1, i64 %102
%106 = bitcast double* %105 to <2 x double>*
%107 = load <2 x double>, <2 x double>* %106
%108 = getelementptr double, double* %105, i64 2
%109 = bitcast double* %108 to <2 x double>*
%110 = load <2 x double>, <2 x double>* %109
%111 = fmul <2 x double> %64, %107
%112 = fmul <2 x double> %66, %110
%113 = bitcast double* %105 to <2 x double>*
store <2 x double> %111, <2 x double>* %113
%114 = bitcast double* %108 to <2 x double>*
store <2 x double> %112, <2 x double>* %114
br label %115
115: ; preds = %101, %104
%116 = icmp eq i64 %57, %60
br i1 %116, label %128, label %117
117: ; preds = %54, %115
%118 = phi double* [ %1, %54 ], [ %61, %115 ]
%119 = phi i32 [ 0, %54 ], [ %62, %115 ]
br label %120
120: ; preds = %117, %120
%121 = phi double* [ %123, %120 ], [ %118, %117 ]
%122 = phi i32 [ %126, %120 ], [ %119, %117 ]
%123 = getelementptr inbounds double, double* %121, i64 1
%124 = load double, double* %121
%125 = fmul double %53, %124
store double %125, double* %121
%126 = add nuw nsw i32 %122, 1
%127 = icmp eq i32 %126, %0
br i1 %127, label %128, label %120
128: ; preds = %120, %115, %51
ret void
}