#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 atoi(char *);
double pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("%s\n", "You must input a valid number");
    return -1;
  }
  int size = atoi(argv[1]);
  if (size < 1) {
    printf("Input a valid number between 1 and %d", 48);
    return -1;
  } else if (size > 48) {
    size = 48;
  }
  double pi = 0.0;
  double decimal = 0.0;
  int i;
  for (i = 0; i < size; i++) {
    decimal = pow(16, -i) * (4.0 / (8 * i + 1) - 2.0 / (8 * i + 4) -
                             1.0 / (8 * i + 5) - 1.0 / (8 * i + 6));
    pi += decimal;
  }
  printf("π with %d decimals is: %.*f\n", size, size, pi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1171 <main+0x41>
lea    0xec1(%rip),%rdi
lea    0xebe(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a8 <main+0x178>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    11aa <main+0x7a>
lea    0xea8(%rip),%rdi
mov    $0x30,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a8 <main+0x178>
cmpl   $0x30,-0x14(%rbp)
jle    11bb <main+0x8b>
movl   $0x30,-0x14(%rbp)
jmp    11c0 <main+0x90>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1288 <main+0x158>
xor    %esi,%esi
sub    -0x2c(%rbp),%esi
mov    $0x10,%edi
call   1040 <pow@plt>
mov    -0x2c(%rbp),%eax
shl    $0x3,%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm2
movsd  0xe09(%rip),%xmm1
divsd  %xmm2,%xmm1
mov    -0x2c(%rbp),%eax
shl    $0x3,%eax
add    $0x4,%eax
cvtsi2sd %eax,%xmm3
movsd  0xde8(%rip),%xmm2
divsd  %xmm3,%xmm2
subsd  %xmm2,%xmm1
mov    -0x2c(%rbp),%eax
shl    $0x3,%eax
add    $0x5,%eax
cvtsi2sd %eax,%xmm3
movsd  0xdc3(%rip),%xmm2
divsd  %xmm3,%xmm2
subsd  %xmm2,%xmm1
mov    -0x2c(%rbp),%eax
shl    $0x3,%eax
add    $0x6,%eax
cvtsi2sd %eax,%xmm3
movsd  0xda6(%rip),%xmm2
divsd  %xmm3,%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d7 <main+0xa7>
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
movsd  -0x20(%rbp),%xmm0
lea    0xdc6(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     115d <main+0x1d>
lea    0xeed(%rip),%rdi
call   1030 <puts@plt>
jmp    1239 <main+0xf9>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    1226 <main+0xe6>
cmp    $0x30,%eax
mov    $0x30,%r14d
cmovb  %eax,%r14d
mov    %r14d,%r15d
neg    %r15d
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
movsd  %xmm0,(%rsp)
mov    $0x10,%edi
mov    %ebp,%esi
call   1050 <pow@plt>
movd   %ebx,%xmm1
pshufd $0x50,%xmm1,%xmm1
movdqa %xmm1,%xmm2
por    0xe4a(%rip),%xmm2
cvtdq2pd %xmm2,%xmm2
movapd 0xe4e(%rip),%xmm3
por    0xe56(%rip),%xmm1
cvtdq2pd %xmm1,%xmm1
divpd  %xmm2,%xmm3
movapd 0xe56(%rip),%xmm2
divpd  %xmm1,%xmm2
movapd %xmm3,%xmm1
unpckhpd %xmm3,%xmm1
subsd  %xmm1,%xmm3
subsd  %xmm2,%xmm3
unpckhpd %xmm2,%xmm2
subsd  %xmm2,%xmm3
mulsd  %xmm0,%xmm3
movsd  (%rsp),%xmm0
addsd  %xmm3,%xmm0
add    $0xffffffff,%ebp
add    $0x8,%ebx
cmp    %ebp,%r15d
jne    1190 <main+0x50>
lea    0xe6f(%rip),%rdi
mov    %r14d,%esi
mov    %r14d,%edx
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
jmp    123e <main+0xfe>
lea    0xe31(%rip),%rdi
mov    $0x30,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [30 x i8] c"You must input a valid number\00"
@.str.2 = [38 x i8] c"Input a valid number between 1 and %d\00"
@.str.3 = [30 x i8] c"\CF\80 with %d decimals is: %.*f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %72
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 1
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 48)
store i32 -1, i32* %3
br label %72
23: ; preds = %14
%24 = load i32, i32* %6
%25 = icmp sgt i32 %24, 48
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 48, i32* %6
br label %27
27: ; preds = %26, %23
br label %28
28: ; preds = %27
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store i32 0, i32* %9
br label %29
29: ; preds = %64, %28
%30 = load i32, i32* %9
%31 = load i32, i32* %6
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %67
33: ; preds = %29
%34 = load i32, i32* %9
%35 = sub nsw i32 0, %34
%36 = call double @pow(i32 16, i32 %35)
%37 = load i32, i32* %9
%38 = mul nsw i32 8, %37
%39 = add nsw i32 %38, 1
%40 = sitofp i32 %39 to double
%41 = fdiv double 4.000000e+00, %40
%42 = load i32, i32* %9
%43 = mul nsw i32 8, %42
%44 = add nsw i32 %43, 4
%45 = sitofp i32 %44 to double
%46 = fdiv double 2.000000e+00, %45
%47 = fsub double %41, %46
%48 = load i32, i32* %9
%49 = mul nsw i32 8, %48
%50 = add nsw i32 %49, 5
%51 = sitofp i32 %50 to double
%52 = fdiv double 1.000000e+00, %51
%53 = fsub double %47, %52
%54 = load i32, i32* %9
%55 = mul nsw i32 8, %54
%56 = add nsw i32 %55, 6
%57 = sitofp i32 %56 to double
%58 = fdiv double 1.000000e+00, %57
%59 = fsub double %53, %58
%60 = fmul double %36, %59
store double %60, double* %8
%61 = load double, double* %8
%62 = load double, double* %7
%63 = fadd double %62, %61
store double %63, double* %7
br label %64
64: ; preds = %33
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
br label %29
67: ; preds = %29
%68 = load i32, i32* %6
%69 = load i32, i32* %6
%70 = load double, double* %7
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %68, i32 %69, double %70)
store i32 0, i32* %3
br label %72
72: ; preds = %67, %21, %12
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"You must input a valid number\00"
@.str.2 = [38 x i8] c"Input a valid number between 1 and %d\00"
@.str.3 = [30 x i8] c"\CF\80 with %d decimals is: %.*f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %42
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 48)
br label %42
13: ; preds = %6
%14 = icmp ult i32 %9, 48
%15 = select i1 %14, i32 %9, i32 48
br label %16
16: ; preds = %13, %16
%17 = phi i32 [ 0, %13 ], [ %38, %16 ]
%18 = phi double [ 0.000000e+00, %13 ], [ %37, %16 ]
%19 = sub nsw i32 0, %17
%20 = tail call double @pow(i32 16, i32 %19)
%21 = shl nsw i32 %17, 3
%22 = insertelement <2 x i32> poison, i32 %21, i64 0
%23 = shufflevector <2 x i32> %22, <2 x i32> poison, <2 x i32> zeroinitializer
%24 = or <2 x i32> %23, <i32 1, i32 4>
%25 = sitofp <2 x i32> %24 to <2 x double>
%26 = fdiv <2 x double> <double 4.000000e+00, double 2.000000e+00>, %25
%27 = shufflevector <2 x double> %26, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%28 = fsub <2 x double> %26, %27
%29 = or <2 x i32> %23, <i32 5, i32 6>
%30 = sitofp <2 x i32> %29 to <2 x double>
%31 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %30
%32 = fsub <2 x double> %28, %31
%33 = shufflevector <2 x double> %31, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%34 = fsub <2 x double> %32, %33
%35 = extractelement <2 x double> %34, i64 0
%36 = fmul double %35, %20
%37 = fadd double %18, %36
%38 = add nuw nsw i32 %17, 1
%39 = icmp eq i32 %38, %15
br i1 %39, label %40, label %16
40: ; preds = %16
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %15, i32 %15, double %37)
br label %42
42: ; preds = %11, %40, %4
%43 = phi i32 [ -1, %4 ], [ -1, %11 ], [ 0, %40 ]
ret i32 %43
}