#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
int main() {
  float x;
  double pi = 4.0000;
  printf("Num?");
  scanf("%f", &x);
  int sign = 0;
  for (int i = 3; i >= 0; i += 2) {
    double result = 4.000 / i;
    if (result < x)
      break;
    if (sign) {
      pi += result;
      sign = 0;
    } else {
      pi -= result;
      sign = 1;
    }
  }
  printf("%f", pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x3,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11f7 <main+0xd7>
cvtsi2sdl -0x18(%rbp),%xmm1
movsd  0xe81(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11a5 <main+0x85>
jmp    11f7 <main+0xd7>
cmpl   $0x0,-0x14(%rbp)
je     11ca <main+0xaa>
movsd  -0x20(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    11e4 <main+0xc4>
movsd  -0x20(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    11e9 <main+0xc9>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    1168 <main+0x48>
movsd  -0x10(%rbp),%xmm0
lea    0xe0a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xef4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee9(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm1
ucomisd 0xeb0(%rip),%xmm1
jbe    1178 <main+0x58>
movsd  0xe9e(%rip),%xmm0
lea    0xebc(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
movsd  0xe80(%rip),%xmm2
movsd  0xe80(%rip),%xmm4
mov    $0x5,%eax
movapd 0xe7b(%rip),%xmm3
movapd %xmm2,%xmm0
jmp    11bf <main+0x9f>
nopl   0x0(%rax,%rax,1)
addsd  %xmm4,%xmm0
xor    $0x1,%ebx
xorps  %xmm5,%xmm5
cvtsi2sd %eax,%xmm5
movapd %xmm2,%xmm4
divsd  %xmm5,%xmm4
add    $0x2,%eax
ucomisd %xmm4,%xmm1
ja     1162 <main+0x42>
test   %ebx,%ebx
jne    11a0 <main+0x80>
xorpd  %xmm3,%xmm4
jmp    11a0 <main+0x80>

LLVM IR (-O0):
@.str = [5 x i8] c"Num?\00"
@.str.1 = [3 x i8] c"%f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
store i32 0, i32* %1
store double 4.000000e+00, double* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %2)
store i32 0, i32* %4
store i32 3, i32* %5
br label %9
9: ; preds = %33, %0
%10 = load i32, i32* %5
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %36
12: ; preds = %9
%13 = load i32, i32* %5
%14 = sitofp i32 %13 to double
%15 = fdiv double 4.000000e+00, %14
store double %15, double* %6
%16 = load double, double* %6
%17 = load float, float* %2
%18 = fpext float %17 to double
%19 = fcmp olt double %16, %18
br i1 %19, label %20, label %21
20: ; preds = %12
br label %36
21: ; preds = %12
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load double, double* %6
%26 = load double, double* %3
%27 = fadd double %26, %25
store double %27, double* %3
store i32 0, i32* %4
br label %32
28: ; preds = %21
%29 = load double, double* %6
%30 = load double, double* %3
%31 = fsub double %30, %29
store double %31, double* %3
store i32 1, i32* %4
br label %32
32: ; preds = %28, %24
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 2
store i32 %35, i32* %5
br label %9
36: ; preds = %20, %9
%37 = load double, double* %3
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), double %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"Num?\00"
@.str.1 = [3 x i8] c"%f\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), float* %1)
%5 = load float, float* %1
%6 = fpext float %5 to double
%7 = fcmp ogt double %6, 0x3FF5555555555555
br i1 %7, label %22, label %8
8: ; preds = %0, %8
%9 = phi double [ %20, %8 ], [ 0x3FF5555555555555, %0 ]
%10 = phi i32 [ %18, %8 ], [ 3, %0 ]
%11 = phi i32 [ %17, %8 ], [ 0, %0 ]
%12 = phi double [ %16, %8 ], [ 4.000000e+00, %0 ]
%13 = icmp eq i32 %11, 0
%14 = fneg double %9
%15 = select i1 %13, double %14, double %9
%16 = fadd double %12, %15
%17 = xor i32 %11, 1
%18 = add nuw nsw i32 %10, 2
%19 = sitofp i32 %18 to double
%20 = fdiv double 4.000000e+00, %19
%21 = fcmp olt double %20, %6
br i1 %21, label %22, label %8
22: ; preds = %8, %0
%23 = phi double [ 4.000000e+00, %0 ], [ %16, %8 ]
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), double %23)
ret i32 0
}