#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 */
double RAND_MAX;
double dd_aint(double);
double dd_nint_d(double);
int /*<<< orphan*/ dd_split(double, double *, double *);
double dd_two_diff(double, double, double *);
double dd_two_prod(double, double, double *);
double dd_two_sum(double, double, double *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int basic_test(void) {
  double a, b, s, e, hi, lo;
  static const double _nan;
  printf("\ntesting some basic operations ...\n");
  srand(time(NULL));
  a = ((double)rand()) / RAND_MAX;
  b = ((double)rand()) / RAND_MAX;
  printf("  a = %21.14e\n  b = %21.14e\n", a, b);
  printf("nearest integer to a : %21.14e\n", dd_nint_d(a));
  printf("a truncated to integer : %21.14e\n", dd_aint(a));
  s = dd_two_sum(a, b, &e);
  printf("a+b = %21.14e  err = %21.14e\n", s, e);
  s = dd_two_diff(a, b, &e);
  printf("a-b = %21.14e  err = %21.14e\n", s, e);
  dd_split(a, &hi, &lo);
  printf("  a = %21.14e\n hi = %21.14e  lo = %21.14e\n", a, hi, lo);
  s = dd_two_prod(a, b, &e);
  printf("a*b = %21.14e  err = %21.14e\n", s, e);
  return 0;
}


x86 assembly (clang, -O0):
<basic_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x0,%al
call   10c0 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e0f(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   10c0 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2df3(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    0xe1d(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x8(%rbp),%xmm0
call   1090 <dd_nint_d@plt>
lea    0xe22(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x8(%rbp),%xmm0
call   10a0 <dd_aint@plt>
lea    0xe2a(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    -0x20(%rbp),%rdi
call   1080 <dd_two_sum@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xe1c(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    -0x20(%rbp),%rdi
call   1030 <dd_two_diff@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xe0a(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x8(%rbp),%xmm0
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   10b0 <dd_split@plt>
movsd  -0x8(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
lea    0xdf9(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
lea    -0x20(%rbp),%rdi
call   1050 <dd_two_prod@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xdf4(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basic_test>:
push   %rbx
sub    $0x30,%rsp
lea    0xf28(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
xor    %eax,%eax
call   10d0 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e06(%rip),%rbx
divsd  (%rbx),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   10d0 <rand@plt>
cvtsi2sd %rax,%xmm1
divsd  (%rbx),%xmm1
movsd  %xmm1,0x10(%rsp)
lea    0xdf7(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
call   10a0 <dd_nint_d@plt>
lea    0xdf5(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
call   10b0 <dd_aint@plt>
lea    0xdfc(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0x18(%rsp),%rbx
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %rbx,%rdi
call   1090 <dd_two_sum@plt>
movsd  0x18(%rsp),%xmm1
lea    0xdf1(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %rbx,%rdi
call   1040 <dd_two_diff@plt>
movsd  0x18(%rsp),%xmm1
lea    0xde7(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
lea    0x28(%rsp),%rdi
lea    0x20(%rsp),%rsi
movsd  0x8(%rsp),%xmm0
call   10c0 <dd_split@plt>
movsd  0x28(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
lea    0xdd6(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x3,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %rbx,%rdi
call   1060 <dd_two_prod@plt>
movsd  0x18(%rsp),%xmm1
lea    0xdd3(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@basic_test._nan = internal constant double 0.000000e+00
@.str = [36 x i8] c"\0Atesting some basic operations ...\0A\00"
@RAND_MAX = global double 0.000000e+00
@.str.1 = [29 x i8] c" a = %21.14e\0A b = %21.14e\0A\00"
@.str.2 = [32 x i8] c"nearest integer to a : %21.14e\0A\00"
@.str.3 = [34 x i8] c"a truncated to integer : %21.14e\0A\00"
@.str.4 = [30 x i8] c"a+b = %21.14e err = %21.14e\0A\00"
@.str.5 = [30 x i8] c"a-b = %21.14e err = %21.14e\0A\00"
@.str.6 = [43 x i8] c" a = %21.14e\0A hi = %21.14e lo = %21.14e\0A\00"
@.str.7 = [30 x i8] c"a*b = %21.14e err = %21.14e\0A\00"
define i32 @basic_test() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
%10 = call i64 (...) @rand()
%11 = sitofp i64 %10 to double
%12 = load double, double* @RAND_MAX
%13 = fdiv double %11, %12
store double %13, double* %1
%14 = call i64 (...) @rand()
%15 = sitofp i64 %14 to double
%16 = load double, double* @RAND_MAX
%17 = fdiv double %15, %16
store double %17, double* %2
%18 = load double, double* %1
%19 = load double, double* %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), double %18, double %19)
%21 = load double, double* %1
%22 = call double @dd_nint_d(double %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), double %22)
%24 = load double, double* %1
%25 = call double @dd_aint(double %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), double %25)
%27 = load double, double* %1
%28 = load double, double* %2
%29 = call double @dd_two_sum(double %27, double %28, double* %4)
store double %29, double* %3
%30 = load double, double* %3
%31 = load double, double* %4
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), double %30, double %31)
%33 = load double, double* %1
%34 = load double, double* %2
%35 = call double @dd_two_diff(double %33, double %34, double* %4)
store double %35, double* %3
%36 = load double, double* %3
%37 = load double, double* %4
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), double %36, double %37)
%39 = load double, double* %1
%40 = call i32 @dd_split(double %39, double* %5, double* %6)
%41 = load double, double* %1
%42 = load double, double* %5
%43 = load double, double* %6
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), double %41, double %42, double %43)
%45 = load double, double* %1
%46 = load double, double* %2
%47 = call double @dd_two_prod(double %45, double %46, double* %4)
store double %47, double* %3
%48 = load double, double* %3
%49 = load double, double* %4
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), double %48, double %49)
ret i32 0
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
@.str.1 = [29 x i8] c" a = %21.14e\0A b = %21.14e\0A\00"
@.str.2 = [32 x i8] c"nearest integer to a : %21.14e\0A\00"
@.str.3 = [34 x i8] c"a truncated to integer : %21.14e\0A\00"
@.str.4 = [30 x i8] c"a+b = %21.14e err = %21.14e\0A\00"
@.str.5 = [30 x i8] c"a-b = %21.14e err = %21.14e\0A\00"
@.str.6 = [43 x i8] c" a = %21.14e\0A hi = %21.14e lo = %21.14e\0A\00"
@.str.7 = [30 x i8] c"a*b = %21.14e err = %21.14e\0A\00"
@str = [35 x i8] c"\0Atesting some basic operations ...\00"
define i32 @basic_test() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = bitcast double* %1 to i8*
%5 = bitcast double* %2 to i8*
%6 = bitcast double* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @time(i32* null)
%9 = tail call i32 @srand(i32 %8)
%10 = tail call i64 (...) @rand()
%11 = sitofp i64 %10 to double
%12 = load double, double* @RAND_MAX
%13 = fdiv double %11, %12
%14 = tail call i64 (...) @rand()
%15 = sitofp i64 %14 to double
%16 = load double, double* @RAND_MAX
%17 = fdiv double %15, %16
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), double %13, double %17)
%19 = tail call double @dd_nint_d(double %13)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), double %19)
%21 = tail call double @dd_aint(double %13)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), double %21)
%23 = call double @dd_two_sum(double %13, double %17, double* %1)
%24 = load double, double* %1
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), double %23, double %24)
%26 = call double @dd_two_diff(double %13, double %17, double* %1)
%27 = load double, double* %1
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), double %26, double %27)
%29 = call i32 @dd_split(double %13, double* %2, double* %3)
%30 = load double, double* %2
%31 = load double, double* %3
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), double %13, double %30, double %31)
%33 = call double @dd_two_prod(double %13, double %17, double* %1)
%34 = load double, double* %1
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), double %33, double %34)
ret i32 0
}