#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 */
double M_PI;
double RAND_MAX;
int /*<<< orphan*/ printf(char *, float);
double rand();
float sin(float);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main(int argc, char **argv) {
  float x, y, above = 0, under = 0;
  int i;
  srand(time(0));
  for (i = 1; i < 10000000; i++) {
    x = (rand() / (1.0 + RAND_MAX) * M_PI);
    y = (rand() / (1.0 + RAND_MAX) * 1);
    if (sin(x) > y) {
      under++;
    } else {
      above++;
    }
  }
  printf("plocha pod funkci sinus: %f \n", under / (under + above) * M_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)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x1,-0x24(%rbp)
cmpl   $0x989680,-0x24(%rbp)
jge    124d <main+0xfd>
mov    $0x0,%al
call   1070 <rand@plt>
movsd  0xe59(%rip),%xmm1
mov    0x2e32(%rip),%rax
addsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
mov    0x2e2b(%rip),%rax
mulsd  (%rax),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
movsd  0xe27(%rip),%xmm1
mov    0x2e00(%rip),%rax
addsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe10(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
call   1050 <sin@plt>
ucomiss -0x18(%rbp),%xmm0
jbe    1228 <main+0xd8>
movss  0xdef(%rip),%xmm0
addss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
jmp    123a <main+0xea>
movss  0xdd8(%rip),%xmm0
addss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    123f <main+0xef>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118b <main+0x3b>
movss  -0x20(%rbp),%xmm0
movss  -0x20(%rbp),%xmm1
addss  -0x1c(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    0x2d7d(%rip),%rax
mulsd  (%rax),%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xd92(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xorps  %xmm1,%xmm1
mov    $0x98967f,%ebp
mov    0x2e6b(%rip),%rbx
mov    0x2e6c(%rip),%r14
xorpd  %xmm0,%xmm0
movapd %xmm0,0x10(%rsp)
jmp    11c8 <main+0x78>
nopl   0x0(%rax,%rax,1)
movaps 0x10(%rsp),%xmm1
movss  0xe6b(%rip),%xmm2
addss  %xmm2,%xmm1
movaps %xmm1,0x10(%rsp)
movaps 0x20(%rsp),%xmm3
movaps %xmm3,%xmm1
addss  %xmm2,%xmm1
cmpltss %xmm0,%xmm4
andps  %xmm4,%xmm1
andnps %xmm3,%xmm4
orps   %xmm1,%xmm4
movaps %xmm4,%xmm1
add    $0xffffffff,%ebp
je     123d <main+0xed>
movaps %xmm1,0x20(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
movsd  (%rbx),%xmm1
movsd  0xe20(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
mulsd  (%r14),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
movsd  (%rbx),%xmm1
addsd  0xdf6(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movss  0xc(%rsp),%xmm0
call   1050 <sin@plt>
movaps 0x30(%rsp),%xmm4
ucomiss %xmm4,%xmm0
jbe    1190 <main+0x40>
movss  0xdd0(%rip),%xmm2
jmp    11a6 <main+0x56>
movaps 0x10(%rsp),%xmm0
addss  %xmm4,%xmm0
divss  %xmm0,%xmm4
xorps  %xmm0,%xmm0
cvtss2sd %xmm4,%xmm0
mulsd  (%r14),%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xdab(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
@M_PI = global double 0.000000e+00
@.str = [30 x i8] c"plocha pod funkci sinus: %f \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store float 0.000000e+00, float* %8
store float 0.000000e+00, float* %9
%11 = call i32 @time(i32 0)
%12 = call i32 @srand(i32 %11)
store i32 1, i32* %10
br label %13
13: ; preds = %41, %2
%14 = load i32, i32* %10
%15 = icmp slt i32 %14, 10000000
br i1 %15, label %16, label %44
16: ; preds = %13
%17 = call double (...) @rand()
%18 = load double, double* @RAND_MAX
%19 = fadd double 1.000000e+00, %18
%20 = fdiv double %17, %19
%21 = load double, double* @M_PI
%22 = fmul double %20, %21
%23 = fptrunc double %22 to float
store float %23, float* %6
%24 = call double (...) @rand()
%25 = load double, double* @RAND_MAX
%26 = fadd double 1.000000e+00, %25
%27 = fdiv double %24, %26
%28 = fmul double %27, 1.000000e+00
%29 = fptrunc double %28 to float
store float %29, float* %7
%30 = load float, float* %6
%31 = call float @sin(float %30)
%32 = load float, float* %7
%33 = fcmp ogt float %31, %32
br i1 %33, label %34, label %37
34: ; preds = %16
%35 = load float, float* %9
%36 = fadd float %35, 1.000000e+00
store float %36, float* %9
br label %40
37: ; preds = %16
%38 = load float, float* %8
%39 = fadd float %38, 1.000000e+00
store float %39, float* %8
br label %40
40: ; preds = %37, %34
br label %41
41: ; preds = %40
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %13
44: ; preds = %13
%45 = load float, float* %9
%46 = load float, float* %9
%47 = load float, float* %8
%48 = fadd float %46, %47
%49 = fdiv float %45, %48
%50 = fpext float %49 to double
%51 = load double, double* @M_PI
%52 = fmul double %50, %51
%53 = fptrunc double %52 to float
%54 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), float %53)
ret i32 0
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
@M_PI = global double 0.000000e+00
@.str = [30 x i8] c"plocha pod funkci sinus: %f \0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @time(i32 0)
%4 = tail call i32 @srand(i32 %3)
br label %5
5: ; preds = %2, %5
%6 = phi i32 [ 1, %2 ], [ %27, %5 ]
%7 = phi float [ 0.000000e+00, %2 ], [ %26, %5 ]
%8 = phi float [ 0.000000e+00, %2 ], [ %25, %5 ]
%9 = tail call double (...) @rand()
%10 = load double, double* @RAND_MAX
%11 = fadd double %10, 1.000000e+00
%12 = fdiv double %9, %11
%13 = load double, double* @M_PI
%14 = fmul double %13, %12
%15 = fptrunc double %14 to float
%16 = tail call double (...) @rand()
%17 = load double, double* @RAND_MAX
%18 = fadd double %17, 1.000000e+00
%19 = fdiv double %16, %18
%20 = fptrunc double %19 to float
%21 = tail call float @sin(float %15)
%22 = fcmp ogt float %21, %20
%23 = fadd float %7, 1.000000e+00
%24 = fadd float %8, 1.000000e+00
%25 = select i1 %22, float %8, float %24
%26 = select i1 %22, float %23, float %7
%27 = add nuw nsw i32 %6, 1
%28 = icmp eq i32 %27, 10000000
br i1 %28, label %29, label %5
29: ; preds = %5
%30 = fadd float %25, %26
%31 = fdiv float %26, %30
%32 = fpext float %31 to double
%33 = load double, double* @M_PI
%34 = fmul double %33, %32
%35 = fptrunc double %34 to float
%36 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), float %35)
ret i32 0
}