#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 *, double);
double random(double);
double sqrt(long);
int main(void) {
  long t = 1000000;
  double r = 10000;
  double r2 = r / 2;
  long k = 0, i;
  for (i = 0; i < t; i++) {
    long a = random(r) - r2 + 1;
    long b = random(r) - r2 + 1;
    if (sqrt(a * a + b * b) <= r2)
      k++;
  }
  printf("Приближение на p = %.2f\n", (4.0 * k) / t);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0xf4240,-0x10(%rbp)
movsd  0xeb9(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe9f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    121e <main+0xee>
movsd  -0x18(%rbp),%xmm0
call   1040 <random@plt>
subsd  -0x20(%rbp),%xmm0
movsd  0xe79(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <random@plt>
subsd  -0x20(%rbp),%xmm0
movsd  0xe55(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
imul   -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
imul   -0x40(%rbp),%rax
add    %rax,%rdi
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1208 <main+0xd8>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    120d <main+0xdd>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    117a <main+0x4a>
cvtsi2sdq -0x28(%rbp),%xmm1
movsd  0xde4(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdq -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xddf(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0xf4240,%r14d
xor    %r15d,%r15d
xchg   %ax,%ax
movsd  0xeb8(%rip),%xmm0
call   1040 <random@plt>
movsd  0xeb3(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xeaf(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rbx
movsd  0xe8e(%rip),%xmm0
call   1040 <random@plt>
addsd  0xe89(%rip),%xmm0
addsd  0xe89(%rip),%xmm0
cvttsd2si %xmm0,%rdi
imul   %rbx,%rbx
imul   %rdi,%rdi
add    %rbx,%rdi
call   1050 <sqrt@plt>
movsd  0xe74(%rip),%xmm1
ucomisd %xmm0,%xmm1
sbb    $0xffffffffffffffff,%r15
add    $0xffffffffffffffff,%r14
jne    1140 <main+0x10>
xorps  %xmm0,%xmm0
cvtsi2sd %r15,%xmm0
mulsd  0xe5e(%rip),%xmm0
divsd  0xe5e(%rip),%xmm0
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [38 x i8] c"\D0\9F\D1\80\D0\B8\D0\B1\D0\BB\D0\B8\D0\B6\D0\B5\D0\BD\D0\B8\D0\B5 \D0\BD\D0\B0 p = %.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca double
%4 = alloca double
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %1
store i64 1000000, i64* %2
store double 1.000000e+04, double* %3
%9 = load double, double* %3
%10 = fdiv double %9, 2.000000e+00
store double %10, double* %4
store i64 0, i64* %5
store i64 0, i64* %6
br label %11
11: ; preds = %42, %0
%12 = load i64, i64* %6
%13 = load i64, i64* %2
%14 = icmp slt i64 %12, %13
br i1 %14, label %15, label %45
15: ; preds = %11
%16 = load double, double* %3
%17 = call double @random(double %16)
%18 = load double, double* %4
%19 = fsub double %17, %18
%20 = fadd double %19, 1.000000e+00
%21 = fptosi double %20 to i64
store i64 %21, i64* %7
%22 = load double, double* %3
%23 = call double @random(double %22)
%24 = load double, double* %4
%25 = fsub double %23, %24
%26 = fadd double %25, 1.000000e+00
%27 = fptosi double %26 to i64
store i64 %27, i64* %8
%28 = load i64, i64* %7
%29 = load i64, i64* %7
%30 = mul nsw i64 %28, %29
%31 = load i64, i64* %8
%32 = load i64, i64* %8
%33 = mul nsw i64 %31, %32
%34 = add nsw i64 %30, %33
%35 = call double @sqrt(i64 %34)
%36 = load double, double* %4
%37 = fcmp ole double %35, %36
br i1 %37, label %38, label %41
38: ; preds = %15
%39 = load i64, i64* %5
%40 = add nsw i64 %39, 1
store i64 %40, i64* %5
br label %41
41: ; preds = %38, %15
br label %42
42: ; preds = %41
%43 = load i64, i64* %6
%44 = add nsw i64 %43, 1
store i64 %44, i64* %6
br label %11
45: ; preds = %11
%46 = load i64, i64* %5
%47 = sitofp i64 %46 to double
%48 = fmul double 4.000000e+00, %47
%49 = load i64, i64* %2
%50 = sitofp i64 %49 to double
%51 = fdiv double %48, %50
%52 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), double %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [38 x i8] c"\D0\9F\D1\80\D0\B8\D0\B1\D0\BB\D0\B8\D0\B6\D0\B5\D0\BD\D0\B8\D0\B5 \D0\BD\D0\B0 p = %.2f\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i64 [ 0, %0 ], [ %18, %1 ]
%3 = phi i64 [ 0, %0 ], [ %19, %1 ]
%4 = tail call double @random(double 1.000000e+04)
%5 = fadd double %4, -5.000000e+03
%6 = fadd double %5, 1.000000e+00
%7 = fptosi double %6 to i64
%8 = tail call double @random(double 1.000000e+04)
%9 = fadd double %8, -5.000000e+03
%10 = fadd double %9, 1.000000e+00
%11 = fptosi double %10 to i64
%12 = mul nsw i64 %7, %7
%13 = mul nsw i64 %11, %11
%14 = add nuw nsw i64 %13, %12
%15 = tail call double @sqrt(i64 %14)
%16 = fcmp ole double %15, 5.000000e+03
%17 = zext i1 %16 to i64
%18 = add nuw nsw i64 %2, %17
%19 = add nuw nsw i64 %3, 1
%20 = icmp eq i64 %19, 1000000
br i1 %20, label %21, label %1
21: ; preds = %1
%22 = sitofp i64 %18 to double
%23 = fmul double %22, 4.000000e+00
%24 = fdiv double %23, 1.000000e+06
%25 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), double %24)
ret i32 0
}