#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 */
scalar_t__ floor(int /*<<< orphan*/);
int /*<<< orphan*/ log10(double);
int /*<<< orphan*/ printf(char *, double, ...);
void printLog(double precision, double pi, double error, unsigned long i) {
  if (i % (1024) == 0 || error < precision || i == 1024 * 1024) {
    printf("Iteration\t%ld\n", i);
    printf("Precision\t%d (%s)\n", (unsigned int)floor(-log10(error)),
           i == 1024 * 1024    ? "Timeout"
           : error > precision ? "Still Working"
                               : "Reached");
    printf("PI\t\t%.100f\n", pi);
    printf("Error\t\t%.100f\n", error);
  }
}


x86 assembly (clang, -O0):
<printLog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
mov    -0x20(%rbp),%rax
and    $0x3ff,%rax
cmp    $0x0,%rax
je     1181 <printLog+0x51>
movsd  -0x18(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     1181 <printLog+0x51>
cmpq   $0x100000,-0x20(%rbp)
jne    1254 <printLog+0x124>
movaps 0xe78(%rip),%xmm1
movq   -0x20(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe77(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
lea    0xe71(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
call   1040 <log10@plt>
mov    %eax,%edi
neg    %edi
call   1050 <floor@plt>
mov    %eax,%eax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpq   $0x100000,-0x20(%rbp)
jne    11f3 <printLog+0xc3>
lea    0xe58(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1217 <printLog+0xe7>
movsd  -0x18(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
lea    0xe54(%rip),%rax
lea    0xe3f(%rip),%rcx
ucomisd %xmm1,%xmm0
cmova  %rcx,%rax
mov    %rax,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x30(%rbp),%rsi
lea    0xe08(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
lea    0xe26(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xe1f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printLog>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
test   $0x3ff,%ebx
je     1155 <printLog+0x25>
ucomisd %xmm2,%xmm0
ja     1155 <printLog+0x25>
cmp    $0x100000,%rbx
je     1155 <printLog+0x25>
add    $0x20,%rsp
pop    %rbx
ret
movsd  %xmm1,0x18(%rsp)
movq   %rbx,%xmm1
punpckldq 0xe98(%rip),%xmm1
subpd  0xea0(%rip),%xmm1
movsd  %xmm0,0x10(%rsp)
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
lea    0xe97(%rip),%rdi
mov    $0x1,%al
movsd  %xmm2,0x8(%rsp)
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
call   1040 <log10@plt>
neg    %eax
mov    %eax,%edi
call   1050 <floor@plt>
mov    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd 0x10(%rsp),%xmm1
lea    0xe83(%rip),%rax
lea    0xe8a(%rip),%rcx
cmova  %rax,%rcx
cmp    $0x100000,%rbx
lea    0xe62(%rip),%rsi
cmovne %rcx,%rsi
lea    0xe44(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xe67(%rip),%rdi
movsd  0x18(%rsp),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xe5f(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
add    $0x20,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"Iteration\09%ld\0A\00"
@.str.1 = [19 x i8] c"Precision\09%d (%s)\0A\00"
@.str.2 = [8 x i8] c"Timeout\00"
@.str.3 = [14 x i8] c"Still Working\00"
@.str.4 = [8 x i8] c"Reached\00"
@.str.5 = [12 x i8] c"PI\09\09%.100f\0A\00"
@.str.6 = [15 x i8] c"Error\09\09%.100f\0A\00"
define void @printLog(double %0, double %1, double %2, i64 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i64
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store i64 %3, i64* %8
%9 = load i64, i64* %8
%10 = urem i64 %9, 1024
%11 = icmp eq i64 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %4
%13 = load double, double* %7
%14 = load double, double* %5
%15 = fcmp olt double %13, %14
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = load i64, i64* %8
%18 = icmp eq i64 %17, 1048576
br i1 %18, label %19, label %45
19: ; preds = %16, %12, %4
%20 = load i64, i64* %8
%21 = uitofp i64 %20 to double
%22 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %21)
%23 = load double, double* %7
%24 = call i32 @log10(double %23)
%25 = sub nsw i32 0, %24
%26 = call i64 @floor(i32 %25)
%27 = trunc i64 %26 to i32
%28 = uitofp i32 %27 to double
%29 = load i64, i64* %8
%30 = icmp eq i64 %29, 1048576
br i1 %30, label %31, label %32
31: ; preds = %19
br label %38
32: ; preds = %19
%33 = load double, double* %7
%34 = load double, double* %5
%35 = fcmp ogt double %33, %34
%36 = zext i1 %35 to i64
%37 = select i1 %35, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0)
br label %38
38: ; preds = %32, %31
%39 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %31 ], [ %37, %32 ]
%40 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), double %28, i8* %39)
%41 = load double, double* %6
%42 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), double %41)
%43 = load double, double* %7
%44 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), double %43)
br label %45
45: ; preds = %38, %16
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"Iteration\09%ld\0A\00"
@.str.1 = [19 x i8] c"Precision\09%d (%s)\0A\00"
@.str.2 = [8 x i8] c"Timeout\00"
@.str.3 = [14 x i8] c"Still Working\00"
@.str.4 = [8 x i8] c"Reached\00"
@.str.5 = [12 x i8] c"PI\09\09%.100f\0A\00"
@.str.6 = [15 x i8] c"Error\09\09%.100f\0A\00"
define void @printLog(double %0, double %1, double %2, i64 %3) {
%5 = and i64 %3, 1023
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = fcmp olt double %2, %0
%9 = icmp eq i64 %3, 1048576
%10 = or i1 %8, %9
br i1 %10, label %11, label %26
11: ; preds = %7, %4
%12 = uitofp i64 %3 to double
%13 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %12)
%14 = tail call i32 @log10(double %2)
%15 = sub nsw i32 0, %14
%16 = tail call i64 @floor(i32 %15)
%17 = trunc i64 %16 to i32
%18 = uitofp i32 %17 to double
%19 = icmp eq i64 %3, 1048576
%20 = fcmp ogt double %2, %0
%21 = select i1 %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0)
%22 = select i1 %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %21
%23 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), double %18, i8* %22)
%24 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), double %1)
%25 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), double %2)
br label %26
26: ; preds = %7, %11
ret void
}