#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 *, int *);
int main(void) {
  int terms = 0;
  const double dividend = 4;
  int divisor = 1;
  double coefficient = 0;
  int number = 0;
  printf("Please Enter number of terms you want:");
  scanf("%d", &number);
  for (terms = 1; terms <= number; terms++) {
    if (terms % 2 == 0) {
      coefficient = +(dividend) / (divisor + 2) + coefficient;
    } else {
      coefficient = -(dividend) / (divisor + 2) + coefficient;
    }
    divisor = divisor + 2;
    printf("The value of PI is :%f and terms number is :%d \n", 4 + coefficient,
           terms);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movsd  0xec2(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec9(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     1218 <main+0xf8>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c3 <main+0xa3>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe50(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11e3 <main+0xc3>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe33(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
movsd  0xe0c(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%esi
lea    0xe37(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117e <main+0x5e>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0xc(%rsp)
lea    0xedf(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef6(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11cd <main+0xad>
xorpd  %xmm2,%xmm2
mov    $0x3,%ebp
lea    0xe96(%rip),%r15
lea    0xed1(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
xor    %eax,%eax
test   $0x1,%bl
sete   %al
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  (%r15,%rax,8),%xmm1
divsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%rsp)
movapd %xmm2,%xmm0
addsd  0xe5e(%rip),%xmm0
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0x10(%rsp),%xmm2
add    $0x2,%ebp
cmp    0xc(%rsp),%ebx
jl     1180 <main+0x60>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Please Enter number of terms you want:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [49 x i8] c"The value of PI is :%f and terms number is :%d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store double 4.000000e+00, double* %3
store i32 1, i32* %4
store double 0.000000e+00, double* %5
store i32 0, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 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), i32* %6)
store i32 1, i32* %2
br label %9
9: ; preds = %38, %0
%10 = load i32, i32* %2
%11 = load i32, i32* %6
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %41
13: ; preds = %9
%14 = load i32, i32* %2
%15 = srem i32 %14, 2
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 2
%20 = sitofp i32 %19 to double
%21 = fdiv double 4.000000e+00, %20
%22 = load double, double* %5
%23 = fadd double %21, %22
store double %23, double* %5
br label %31
24: ; preds = %13
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 2
%27 = sitofp i32 %26 to double
%28 = fdiv double -4.000000e+00, %27
%29 = load double, double* %5
%30 = fadd double %28, %29
store double %30, double* %5
br label %31
31: ; preds = %24, %17
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 2
store i32 %33, i32* %4
%34 = load double, double* %5
%35 = fadd double 4.000000e+00, %34
%36 = load i32, i32* %2
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), double %35, i32 %36)
br label %38
38: ; preds = %31
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
br label %9
41: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [39 x i8] c"Please Enter number of terms you want:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [49 x i8] c"The value of PI is :%f and terms number is :%d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 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), i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 1
br i1 %6, label %23, label %7
7: ; preds = %0, %7
%8 = phi double [ %17, %7 ], [ 0.000000e+00, %0 ]
%9 = phi i32 [ %13, %7 ], [ 1, %0 ]
%10 = phi i32 [ %20, %7 ], [ 1, %0 ]
%11 = and i32 %10, 1
%12 = icmp eq i32 %11, 0
%13 = add nuw nsw i32 %9, 2
%14 = sitofp i32 %13 to double
%15 = select i1 %12, double 4.000000e+00, double -4.000000e+00
%16 = fdiv double %15, %14
%17 = fadd double %8, %16
%18 = fadd double %17, 4.000000e+00
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), double %18, i32 %10)
%20 = add nuw nsw i32 %10, 1
%21 = load i32, i32* %1
%22 = icmp slt i32 %10, %21
br i1 %22, label %7, label %23
23: ; preds = %7, %0
ret i32 0
}