#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*/ exactK(double, double, double *, double *, int);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, double *);
int main() {
  double z, t, TT, FF;
  int scanret;
  const double secpera = 31556926.0;
  const double H0 = 3000.0, B0 = -1000.0;
  printf("Enter t in years:\n");
  scanret = scanf("%lf", &t);
  if (scanret != 1) {
    printf("... input error; exiting\n");
    return 1;
  }
  printf(
      "Enter z in m (0 < z < %4.0f for ice and %5.0f < z < 0 for bedrock):\n",
      H0, B0);
  scanret = scanf("%lf", &z);
  if (scanret != 1) {
    printf("... input error; exiting\n");
    return 1;
  }
  if (t >= 0) {
    exactK(t * secpera, z, &TT, &FF, 0);
  } else {
    exactK(-t * secpera, z, &TT, &FF, 1);
  }
  printf("Results from Test K:\n");
  printf("     T = %11.5f (K) = %11.5f (deg C)   [absolute temperature]\n", TT,
         TT - 273.15);
  printf("     F = %11.5f (W m-2)                     [upward heat flux]\n",
         FF);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xeb4(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe9f(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
je     11ab <main+0x7b>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c3 <main+0x193>
lea    0xe9f(%rip),%rdi
movsd  0xe4e(%rip),%xmm0
movsd  0xe3e(%rip),%xmm1
mov    $0x2,%al
call   1040 <printf@plt>
lea    0xe63(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
je     1200 <main+0xd0>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c3 <main+0x193>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1238 <main+0x108>
movsd  0xdf6(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1030 <exactK@plt>
jmp    1277 <main+0x147>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xdb4(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1030 <exactK@plt>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xd81(%rip),%xmm2
subsd  %xmm2,%xmm1
lea    0xe0a(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x28(%rbp),%xmm0
lea    0xe36(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
lea    0xfa5(%rip),%rdi
call   1030 <puts@plt>
lea    0xed1(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    11c9 <main+0x89>
lea    0xebf(%rip),%rdi
movsd  0xe8b(%rip),%xmm0
movsd  0xe8b(%rip),%xmm1
mov    $0x2,%al
call   1050 <printf@plt>
lea    0xe9d(%rip),%rdi
lea    0x18(%rsp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    11c9 <main+0x89>
movsd  0x20(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jae    11df <main+0x9f>
mulsd  0xe66(%rip),%xmm0
movsd  0x18(%rsp),%xmm1
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
jmp    11f9 <main+0xb9>
lea    0xf47(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x28,%rsp
ret
mulsd  0xe29(%rip),%xmm0
movsd  0x18(%rsp),%xmm1
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <exactK@plt>
lea    0xefd(%rip),%rdi
call   1030 <puts@plt>
movsd  0x10(%rsp),%xmm0
movsd  0xe08(%rip),%xmm1
addsd  %xmm0,%xmm1
lea    0xe4e(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
lea    0xe79(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Enter t in years:\0A\00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [26 x i8] c"... input error; exiting\0A\00"
@.str.3 = [69 x i8] c"Enter z in m (0 < z < %4.0f for ice and %5.0f < z < 0 for bedrock):\0A\00"
@.str.4 = [22 x i8] c"Results from Test K:\0A\00"
@.str.5 = [63 x i8] c" T = %11.5f (K) = %11.5f (deg C) [absolute temperature]\0A\00"
@.str.6 = [64 x i8] c" F = %11.5f (W m-2) [upward heat flux]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i32 0, i32* %1
store double 0x417E1853E0000000, double* %7
store double 3.000000e+03, double* %8
store double -1.000000e+03, double* %9
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %3)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %45
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.3, i64 0, i64 0), double 3.000000e+03, double -1.000000e+03)
%18 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 1
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %45
23: ; preds = %16
%24 = load double, double* %3
%25 = fcmp oge double %24, 0.000000e+00
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load double, double* %3
%28 = fmul double %27, 0x417E1853E0000000
%29 = load double, double* %2
%30 = call i32 @exactK(double %28, double %29, double* %4, double* %5, i32 0)
br label %37
31: ; preds = %23
%32 = load double, double* %3
%33 = fneg double %32
%34 = fmul double %33, 0x417E1853E0000000
%35 = load double, double* %2
%36 = call i32 @exactK(double %34, double %35, double* %4, double* %5, i32 1)
br label %37
37: ; preds = %31, %26
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%39 = load double, double* %4
%40 = load double, double* %4
%41 = fsub double %40, 2.731500e+02
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.5, i64 0, i64 0), double %39, double %41)
%43 = load double, double* %5
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.6, i64 0, i64 0), double %43)
store i32 0, i32* %1
br label %45
45: ; preds = %37, %21, %14
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%lf\00"
@.str.3 = [69 x i8] c"Enter z in m (0 < z < %4.0f for ice and %5.0f < z < 0 for bedrock):\0A\00"
@.str.5 = [63 x i8] c" T = %11.5f (K) = %11.5f (deg C) [absolute temperature]\0A\00"
@.str.6 = [64 x i8] c" F = %11.5f (W m-2) [upward heat flux]\0A\00"
@str = [18 x i8] c"Enter t in years:\00"
@str.7 = [21 x i8] c"Results from Test K:\00"
@str.9 = [25 x i8] c"... input error; exiting\00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = bitcast double* %1 to i8*
%6 = bitcast double* %2 to i8*
%7 = bitcast double* %3 to i8*
%8 = bitcast double* %4 to i8*
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%11 = icmp eq i32 %10, 1
br i1 %11, label %14, label %12
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.9, i64 0, i64 0))
br label %38
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str.3, i64 0, i64 0), double 3.000000e+03, double -1.000000e+03)
%16 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%17 = icmp eq i32 %16, 1
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.9, i64 0, i64 0))
br label %38
20: ; preds = %14
%21 = load double, double* %2
%22 = fcmp ult double %21, 0.000000e+00
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = fmul double %21, 0x417E1853E0000000
%25 = load double, double* %1
%26 = call i32 @exactK(double %24, double %25, double* %3, double* %4, i32 0)
br label %31
27: ; preds = %20
%28 = fmul double %21, 0xC17E1853E0000000
%29 = load double, double* %1
%30 = call i32 @exactK(double %28, double %29, double* %3, double* %4, i32 1)
br label %31
31: ; preds = %27, %23
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0))
%33 = load double, double* %3
%34 = fadd double %33, -2.731500e+02
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.5, i64 0, i64 0), double %33, double %34)
%36 = load double, double* %4
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.6, i64 0, i64 0), double %36)
br label %38
38: ; preds = %31, %18, %12
%39 = phi i32 [ 1, %12 ], [ 1, %18 ], [ 0, %31 ]
ret i32 %39
}