#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*/ closeParameterFile();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getParValue(char *, double *, char *);
int /*<<< orphan*/ openParameterFile(char *);
double pow(double, double);
int /*<<< orphan*/ printf(char *);
double getKT(int iteration, int nAtoms) {
  static int firsttime = 1;
  double kt;
  static int annealLength, startAnneal;
  static double annealScale, endKt, startKt;
  if (firsttime) {
    int error;
    double temp;
    firsttime = 0;
    openParameterFile("main.par");
    error = getParValue("startKt", &startKt, "%lf");
    startKt *= 9.648539724213475e+03;
    error += getParValue("endKt", &endKt, "%lf");
    endKt *= 9.648539724213475e+03;
    error += getParValue("annealScale", &annealScale, "%lf");
    error += getParValue("annealLength", &temp, "%lf");
    annealLength = (int)(temp * nAtoms) + 1;
    error += getParValue("startAnneal", &temp, "%lf");
    startAnneal = (int)(temp * nAtoms);
    closeParameterFile();
    if (error > 0) {
      printf("could not read cooling schedule from main.par\n");
      exit(0);
    }
  }
  if (iteration < startAnneal)
    kt = startKt;
  else
    kt = pow(annealScale, (double)((iteration - startAnneal) / annealLength)) *
         startKt;
  if (kt < endKt)
    return -1.0;
  else
    return kt;
}


x86 assembly (clang, -O0):
<getKT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
cmpl   $0x0,0x2edb(%rip)
je     12b4 <getKT+0x154>
movl   $0x0,0x2ecb(%rip)
lea    0xe84(%rip),%rdi
call   1080 <openParameterFile@plt>
lea    0xe81(%rip),%rdi
lea    0x2ed9(%rip),%rsi
lea    0xe7b(%rip),%rdx
call   1040 <getParValue@plt>
mov    %eax,-0x1c(%rbp)
movsd  0xe4a(%rip),%xmm0
mulsd  0x2eba(%rip),%xmm0
movsd  %xmm0,0x2eb2(%rip)
lea    0xe58(%rip),%rdi
lea    0x2e9c(%rip),%rsi
lea    0xe46(%rip),%rdx
call   1040 <getParValue@plt>
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movsd  0xe12(%rip),%xmm0
mulsd  0x2e7a(%rip),%xmm0
movsd  %xmm0,0x2e72(%rip)
lea    0xe26(%rip),%rdi
lea    0x2e5c(%rip),%rsi
lea    0xe0e(%rip),%rdx
call   1040 <getParValue@plt>
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    0xe12(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    0xdf1(%rip),%rdx
call   1040 <getParValue@plt>
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x1,%eax
mov    %eax,0x2e0a(%rip)
lea    0xde7(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    0xdb9(%rip),%rdx
call   1040 <getParValue@plt>
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x10(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,0x2dd9(%rip)
mov    $0x0,%al
call   1050 <closeParameterFile@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    12af <getKT+0x14f>
lea    0xdad(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    12b4 <getKT+0x154>
mov    -0xc(%rbp),%eax
cmp    0x2da7(%rip),%eax
jge    12d5 <getKT+0x175>
movsd  0x2dad(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1303 <getKT+0x1a3>
movsd  0x2d8b(%rip),%xmm0
mov    -0xc(%rbp),%eax
sub    0x2d7e(%rip),%eax
cltd
idivl  0x2d73(%rip)
cvtsi2sd %eax,%xmm1
call   1060 <pow@plt>
mulsd  0x2d7a(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  0x2d60(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    132c <getKT+0x1cc>
movsd  0xce6(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1336 <getKT+0x1d6>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getKT>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r13d
cmpb   $0x0,0x2ee0(%rip)
jne    128b <getKT+0x12b>
mov    %esi,%r14d
movb   $0x1,0x2ed0(%rip)
lea    0xedd(%rip),%rdi
call   1080 <openParameterFile@plt>
lea    0xe75(%rip),%rdi
lea    0x2ed6(%rip),%rsi
lea    0xe6f(%rip),%r15
mov    %r15,%rdx
call   1040 <getParValue@plt>
mov    %eax,%r12d
movsd  0x2ebc(%rip),%xmm0
mulsd  0xe3c(%rip),%xmm0
movsd  %xmm0,0x2eac(%rip)
lea    0xe49(%rip),%rdi
lea    0x2e96(%rip),%rsi
mov    %r15,%rdx
call   1040 <getParValue@plt>
mov    %eax,%ebp
add    %r12d,%ebp
movsd  0xe11(%rip),%xmm0
mulsd  0x2e79(%rip),%xmm0
movsd  %xmm0,0x2e71(%rip)
lea    0xe1c(%rip),%rdi
lea    0x2e5b(%rip),%rsi
mov    %r15,%rdx
call   1040 <getParValue@plt>
mov    %eax,%ebx
add    %ebp,%ebx
lea    0xe0e(%rip),%rdi
lea    0x8(%rsp),%r12
mov    %r12,%rsi
mov    %r15,%rdx
call   1040 <getParValue@plt>
mov    %eax,%ebp
add    %ebx,%ebp
cvtsi2sd %r14d,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x1,%eax
mov    %eax,0x2e06(%rip)
lea    0xdde(%rip),%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1040 <getParValue@plt>
movsd  0x10(%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
mov    %eax,%ebx
cvttsd2si %xmm0,%eax
mov    %eax,0x2de0(%rip)
xor    %eax,%eax
call   1050 <closeParameterFile@plt>
add    %ebp,%ebx
jg     12fd <getKT+0x19d>
mov    0x2dcf(%rip),%eax
cmp    %r13d,%eax
jle    12a0 <getKT+0x140>
movsd  0x2dda(%rip),%xmm0
jmp    12c9 <getKT+0x169>
movsd  0x2dc0(%rip),%xmm0
sub    %eax,%r13d
mov    %r13d,%eax
cltd
idivl  0x2da7(%rip)
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
call   1060 <pow@plt>
mulsd  0x2daf(%rip),%xmm0
movapd %xmm0,%xmm1
cmpltsd 0x2d9a(%rip),%xmm1
movsd  0xd2a(%rip),%xmm2
andpd  %xmm1,%xmm2
andnpd %xmm0,%xmm1
orpd   %xmm2,%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd43(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@getKT.firsttime = internal global i32 1
@getKT.annealLength = internal global i32 0
@getKT.startAnneal = internal global i32 0
@getKT.annealScale = internal global double 0.000000e+00
@getKT.endKt = internal global double 0.000000e+00
@getKT.startKt = internal global double 0.000000e+00
@.str = [9 x i8] c"main.par\00"
@.str.1 = [8 x i8] c"startKt\00"
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [6 x i8] c"endKt\00"
@.str.4 = [12 x i8] c"annealScale\00"
@.str.5 = [13 x i8] c"annealLength\00"
@.str.6 = [12 x i8] c"startAnneal\00"
@.str.7 = [47 x i8] c"could not read cooling schedule from main.par\0A\00"
define double @getKT(i32 %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca double
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = load i32, i32* @getKT.firsttime
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %48
11: ; preds = %2
store i32 0, i32* @getKT.firsttime
%12 = call i32 @openParameterFile(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @getParValue(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double* @getKT.startKt, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32 %13, i32* %7
%14 = load double, double* @getKT.startKt
%15 = fmul double %14, 0x40C2D84515AEDADE
store double %15, double* @getKT.startKt
%16 = call i32 @getParValue(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double* @getKT.endKt, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* %7
%18 = add nsw i32 %17, %16
store i32 %18, i32* %7
%19 = load double, double* @getKT.endKt
%20 = fmul double %19, 0x40C2D84515AEDADE
store double %20, double* @getKT.endKt
%21 = call i32 @getParValue(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), double* @getKT.annealScale, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* %7
%23 = add nsw i32 %22, %21
store i32 %23, i32* %7
%24 = call i32 @getParValue(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), double* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* %7
%26 = add nsw i32 %25, %24
store i32 %26, i32* %7
%27 = load double, double* %8
%28 = load i32, i32* %5
%29 = sitofp i32 %28 to double
%30 = fmul double %27, %29
%31 = fptosi double %30 to i32
%32 = add nsw i32 %31, 1
store i32 %32, i32* @getKT.annealLength
%33 = call i32 @getParValue(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), double* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* %7
%35 = add nsw i32 %34, %33
store i32 %35, i32* %7
%36 = load double, double* %8
%37 = load i32, i32* %5
%38 = sitofp i32 %37 to double
%39 = fmul double %36, %38
%40 = fptosi double %39 to i32
store i32 %40, i32* @getKT.startAnneal
%41 = call i32 (...) @closeParameterFile()
%42 = load i32, i32* %7
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %11
%45 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0))
%46 = call i32 @exit(i32 0)
unreachable
47: ; preds = %11
br label %48
48: ; preds = %47, %2
%49 = load i32, i32* %4
%50 = load i32, i32* @getKT.startAnneal
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = load double, double* @getKT.startKt
store double %53, double* %6
br label %65
54: ; preds = %48
%55 = load double, double* @getKT.annealScale
%56 = load i32, i32* %4
%57 = load i32, i32* @getKT.startAnneal
%58 = sub nsw i32 %56, %57
%59 = load i32, i32* @getKT.annealLength
%60 = sdiv i32 %58, %59
%61 = sitofp i32 %60 to double
%62 = call double @pow(double %55, double %61)
%63 = load double, double* @getKT.startKt
%64 = fmul double %62, %63
store double %64, double* %6
br label %65
65: ; preds = %54, %52
%66 = load double, double* %6
%67 = load double, double* @getKT.endKt
%68 = fcmp olt double %66, %67
br i1 %68, label %69, label %70
69: ; preds = %65
store double -1.000000e+00, double* %3
br label %72
70: ; preds = %65
%71 = load double, double* %6
store double %71, double* %3
br label %72
72: ; preds = %70, %69
%73 = load double, double* %3
ret double %73
}

LLVM IR (-O2):
@getKT.firsttime = internal unnamed_addr global i1 false
@getKT.annealLength = internal unnamed_addr global i32 0
@getKT.startAnneal = internal unnamed_addr global i32 0
@getKT.annealScale = internal global double 0.000000e+00
@getKT.endKt = internal global double 0.000000e+00
@getKT.startKt = internal global double 0.000000e+00
@.str = [9 x i8] c"main.par\00"
@.str.1 = [8 x i8] c"startKt\00"
@.str.2 = [4 x i8] c"%lf\00"
@.str.3 = [6 x i8] c"endKt\00"
@.str.4 = [12 x i8] c"annealScale\00"
@.str.5 = [13 x i8] c"annealLength\00"
@.str.6 = [12 x i8] c"startAnneal\00"
@str = [46 x i8] c"could not read cooling schedule from main.par\00"
define double @getKT(i32 %0, i32 %1) {
%3 = alloca double
%4 = load i1, i1* @getKT.firsttime
br i1 %4, label %35, label %5
5: ; preds = %2
%6 = bitcast double* %3 to i8*
store i1 true, i1* @getKT.firsttime
%7 = tail call i32 @openParameterFile(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @getParValue(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double* @getKT.startKt, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%9 = load double, double* @getKT.startKt
%10 = fmul double %9, 0x40C2D84515AEDADE
store double %10, double* @getKT.startKt
%11 = tail call i32 @getParValue(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double* @getKT.endKt, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%12 = add nsw i32 %11, %8
%13 = load double, double* @getKT.endKt
%14 = fmul double %13, 0x40C2D84515AEDADE
store double %14, double* @getKT.endKt
%15 = tail call i32 @getParValue(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), double* @getKT.annealScale, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%16 = add nsw i32 %12, %15
%17 = call i32 @getParValue(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), double* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%18 = add nsw i32 %16, %17
%19 = load double, double* %3
%20 = sitofp i32 %1 to double
%21 = fmul double %19, %20
%22 = fptosi double %21 to i32
%23 = add nsw i32 %22, 1
store i32 %23, i32* @getKT.annealLength
%24 = call i32 @getParValue(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), double* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%25 = add nsw i32 %18, %24
%26 = load double, double* %3
%27 = fmul double %26, %20
%28 = fptosi double %27 to i32
store i32 %28, i32* @getKT.startAnneal
%29 = call i32 (...) @closeParameterFile()
%30 = icmp sgt i32 %25, 0
br i1 %30, label %31, label %34
31: ; preds = %5
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %5
br label %35
35: ; preds = %34, %2
%36 = load i32, i32* @getKT.startAnneal
%37 = icmp sgt i32 %36, %0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = load double, double* @getKT.startKt
br label %49
40: ; preds = %35
%41 = load double, double* @getKT.annealScale
%42 = sub nsw i32 %0, %36
%43 = load i32, i32* @getKT.annealLength
%44 = sdiv i32 %42, %43
%45 = sitofp i32 %44 to double
%46 = call double @pow(double %41, double %45)
%47 = load double, double* @getKT.startKt
%48 = fmul double %46, %47
br label %49
49: ; preds = %40, %38
%50 = phi double [ %39, %38 ], [ %48, %40 ]
%51 = load double, double* @getKT.endKt
%52 = fcmp olt double %50, %51
%53 = select i1 %52, double -1.000000e+00, double %50
ret double %53
}