#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 fabs(double);
scalar_t__ unfair();
int test_unfair() {
  double heads = 0;
  double tails = 0;
  for (int i = 0; i < 1000000; i++) {
    if (unfair())
      heads++;
    else
      tails++;
  }
  heads /= 1000000;
  tails /= 1000000;
  return fabs(heads - 0.4) < 0.01 && fabs(tails - 0.6) < 0.01;
}


x86 assembly (clang, -O0):
<test_unfair>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xf4240,-0x14(%rbp)
jge    1189 <test_unfair+0x79>
mov    $0x0,%al
call   1030 <unfair@plt>
cmp    $0x0,%rax
je     1164 <test_unfair+0x54>
movsd  0xecb(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1176 <test_unfair+0x66>
movsd  0xeb4(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    117b <test_unfair+0x6b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112f <test_unfair+0x1f>
movsd  -0x8(%rbp),%xmm0
movsd  0xe7a(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe64(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  0xe46(%rip),%xmm0
subsd  %xmm0,%xmm1
movaps 0xe63(%rip),%xmm0
pand   %xmm0,%xmm1
xor    %eax,%eax
movsd  0xe25(%rip),%xmm0
ucomisd %xmm1,%xmm0
mov    %al,-0x15(%rbp)
jbe    1216 <test_unfair+0x106>
movsd  -0x10(%rbp),%xmm1
movsd  0xe23(%rip),%xmm0
subsd  %xmm0,%xmm1
movaps 0xe30(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xdf4(%rip),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_unfair>:
push   %rbx
sub    $0x20,%rsp
xorpd  %xmm0,%xmm0
movapd %xmm0,(%rsp)
mov    $0xf4240,%ebx
xorpd  %xmm0,%xmm0
movapd %xmm0,0x10(%rsp)
jmp    1149 <test_unfair+0x39>
nop
movapd 0x10(%rsp),%xmm0
addsd  0xec2(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
add    $0xffffffff,%ebx
je     116c <test_unfair+0x5c>
xor    %eax,%eax
call   1030 <unfair@plt>
test   %rax,%rax
jne    1130 <test_unfair+0x20>
movapd (%rsp),%xmm0
addsd  0xe9e(%rip),%xmm0
movapd %xmm0,(%rsp)
add    $0xffffffff,%ebx
jne    1149 <test_unfair+0x39>
movapd 0x10(%rsp),%xmm1
divsd  0xe8e(%rip),%xmm1
addsd  0xe8e(%rip),%xmm1
andpd  0xea6(%rip),%xmm1
xor    %eax,%eax
movsd  0xe84(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c0 <test_unfair+0xb0>
movapd (%rsp),%xmm1
divsd  0xe61(%rip),%xmm1
addsd  0xe71(%rip),%xmm1
andpd  0xe79(%rip),%xmm1
xor    %eax,%eax
ucomisd %xmm1,%xmm0
seta   %al
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @test_unfair() {
%1 = alloca double
%2 = alloca double
%3 = alloca i32
store double 0.000000e+00, double* %1
store double 0.000000e+00, double* %2
store i32 0, i32* %3
br label %4
4: ; preds = %17, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 1000000
br i1 %6, label %7, label %20
7: ; preds = %4
%8 = call i64 (...) @unfair()
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load double, double* %1
%12 = fadd double %11, 1.000000e+00
store double %12, double* %1
br label %16
13: ; preds = %7
%14 = load double, double* %2
%15 = fadd double %14, 1.000000e+00
store double %15, double* %2
br label %16
16: ; preds = %13, %10
br label %17
17: ; preds = %16
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %4
20: ; preds = %4
%21 = load double, double* %1
%22 = fdiv double %21, 1.000000e+06
store double %22, double* %1
%23 = load double, double* %2
%24 = fdiv double %23, 1.000000e+06
store double %24, double* %2
%25 = load double, double* %1
%26 = fsub double %25, 4.000000e-01
%27 = call double @llvm.fabs.f64(double %26)
%28 = fcmp olt double %27, 1.000000e-02
br i1 %28, label %29, label %34
29: ; preds = %20
%30 = load double, double* %2
%31 = fsub double %30, 6.000000e-01
%32 = call double @llvm.fabs.f64(double %31)
%33 = fcmp olt double %32, 1.000000e-02
br label %34
34: ; preds = %29, %20
%35 = phi i1 [ false, %20 ], [ %33, %29 ]
%36 = zext i1 %35 to i32
ret i32 %36
}

LLVM IR (-O2):
define i32 @test_unfair() {
br label %6
1: ; preds = %6
%2 = fdiv double %14, 1.000000e+06
%3 = fadd double %2, -4.000000e-01
%4 = tail call double @llvm.fabs.f64(double %3)
%5 = fcmp olt double %4, 1.000000e-02
br i1 %5, label %18, label %24
6: ; preds = %0, %6
%7 = phi i32 [ 0, %0 ], [ %16, %6 ]
%8 = phi double [ 0.000000e+00, %0 ], [ %15, %6 ]
%9 = phi double [ 0.000000e+00, %0 ], [ %14, %6 ]
%10 = tail call i64 (...) @unfair()
%11 = icmp eq i64 %10, 0
%12 = fadd double %9, 1.000000e+00
%13 = fadd double %8, 1.000000e+00
%14 = select i1 %11, double %9, double %12
%15 = select i1 %11, double %13, double %8
%16 = add nuw nsw i32 %7, 1
%17 = icmp eq i32 %16, 1000000
br i1 %17, label %1, label %6
18: ; preds = %1
%19 = fdiv double %15, 1.000000e+06
%20 = fadd double %19, -6.000000e-01
%21 = tail call double @llvm.fabs.f64(double %20)
%22 = fcmp olt double %21, 1.000000e-02
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %18, %1
%25 = phi i32 [ 0, %1 ], [ %23, %18 ]
ret i32 %25
}