#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 const fabs(double);
int /*<<< orphan*/ printf(char *, ...);
void test_precision(void) {
  double one = 1.0;
  double three = 3.0;
  double frac = 1.0;
  printf("1 = %02.32lf\n", frac);
  frac = one + one / three;
  printf("1+1/3 = %02.32lf\n", frac);
  frac = frac - one / three;
  printf("1+1/3-1/3 = %02.32lf\n", frac);
  if (frac == one) {
    printf("frac == one.\n");
  } else {
    printf("frac != one.\n");
  }
  const double EPSILON = 1e-6;
  if (fabs(frac - one) < EPSILON) {
    printf("difference between frac and one "
           "is NOT significant.\n");
  } else {
    printf("difference between frac and one "
           "IS significant.\n");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<test_precision>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  0xed0(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xecb(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xeb6(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xebd(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
divsd  -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xea0(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
divsd  -0x10(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe87(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
ucomisd -0x8(%rbp),%xmm0
jne    11e1 <test_precision+0xc1>
jp     11e1 <test_precision+0xc1>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ef <test_precision+0xcf>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  0xe19(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
call   1040 <fabs@plt>
movaps %xmm0,%xmm1
movsd  0xdfa(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1233 <test_precision+0x113>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1241 <test_precision+0x121>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_precision>:
push   %rax
lea    0xed8(%rip),%rdi
movsd  0xec0(%rip),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xed0(%rip),%rdi
movsd  0xeb2(%rip),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xecc(%rip),%rdi
movsd  0xe94(%rip),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xecc(%rip),%rdi
call   1040 <puts@plt>
lea    0xecd(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
pop    %rax
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"1 = %02.32lf\0A\00"
@.str.1 = [18 x i8] c"1+1/3 = %02.32lf\0A\00"
@.str.2 = [22 x i8] c"1+1/3-1/3 = %02.32lf\0A\00"
@.str.3 = [14 x i8] c"frac == one.\0A\00"
@.str.4 = [14 x i8] c"frac != one.\0A\00"
@.str.5 = [53 x i8] c"difference between frac and one is NOT significant.\0A\00"
@.str.6 = [49 x i8] c"difference between frac and one IS significant.\0A\00"
@.str.7 = [2 x i8] c"\0A\00"
define void @test_precision() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double 1.000000e+00, double* %1
store double 3.000000e+00, double* %2
store double 1.000000e+00, double* %3
%5 = load double, double* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double %5)
%7 = load double, double* %1
%8 = load double, double* %1
%9 = load double, double* %2
%10 = fdiv double %8, %9
%11 = fadd double %7, %10
store double %11, double* %3
%12 = load double, double* %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), double %12)
%14 = load double, double* %3
%15 = load double, double* %1
%16 = load double, double* %2
%17 = fdiv double %15, %16
%18 = fsub double %14, %17
store double %18, double* %3
%19 = load double, double* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), double %19)
%21 = load double, double* %3
%22 = load double, double* %1
%23 = fcmp oeq double %21, %22
br i1 %23, label %24, label %26
24: ; preds = %0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %28
26: ; preds = %0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %26, %24
store double 0x3EB0C6F7A0B5ED8D, double* %4
%29 = load double, double* %3
%30 = load double, double* %1
%31 = fsub double %29, %30
%32 = call double @fabs(double %31)
%33 = fcmp olt double %32, 0x3EB0C6F7A0B5ED8D
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0))
br label %38
36: ; preds = %28
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0))
br label %38
38: ; preds = %36, %34
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"1 = %02.32lf\0A\00"
@.str.1 = [18 x i8] c"1+1/3 = %02.32lf\0A\00"
@.str.2 = [22 x i8] c"1+1/3-1/3 = %02.32lf\0A\00"
@str = [13 x i8] c"frac == one.\00"
@str.8 = [52 x i8] c"difference between frac and one is NOT significant.\00"
define void @test_precision() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), double 1.000000e+00)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), double 0x3FF5555555555555)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), double 1.000000e+00)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.8, i64 0, i64 0))
%6 = tail call i32 @putchar(i32 10)
ret void
}