#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 */
scalar_t__ RAND_MAX;
scalar_t__ rand();
int gen(int nOfQ, float p) {
  float f;
  f = (float)rand() / ((float)RAND_MAX + 1);
  if (f >= 0 && f < p / nOfQ)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<gen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2eb5(%rip),%rax
cvtsi2ssq (%rax),%xmm1
movss  0xec0(%rip),%xmm2
addss  %xmm2,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     1186 <gen+0x76>
movss  -0x10(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
cvtsi2ssl -0x8(%rbp),%xmm2
divss  %xmm2,%xmm0
ucomiss %xmm1,%xmm0
jbe    1186 <gen+0x76>
movl   $0x1,-0x4(%rbp)
jmp    118d <gen+0x7d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm0,0xc(%rsp)
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
mov    0x2eb5(%rip),%rax
cvtsi2ssq (%rax),%xmm1
addss  0xec0(%rip),%xmm1
divss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     1167 <gen+0x57>
xorps  %xmm1,%xmm1
cvtsi2ss %ebx,%xmm1
movss  0xc(%rsp),%xmm2
divss  %xmm1,%xmm2
mov    $0x1,%eax
ucomiss %xmm0,%xmm2
ja     1169 <gen+0x59>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define i32 @gen(i32 %0, float %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca float
store i32 %0, i32* %4
store float %1, float* %5
%7 = call i64 (...) @rand()
%8 = sitofp i64 %7 to float
%9 = load i64, i64* @RAND_MAX
%10 = sitofp i64 %9 to float
%11 = fadd float %10, 1.000000e+00
%12 = fdiv float %8, %11
store float %12, float* %6
%13 = load float, float* %6
%14 = fcmp oge float %13, 0.000000e+00
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = load float, float* %6
%17 = load float, float* %5
%18 = load i32, i32* %4
%19 = sitofp i32 %18 to float
%20 = fdiv float %17, %19
%21 = fcmp olt float %16, %20
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 1, i32* %3
br label %24
23: ; preds = %15, %2
store i32 0, i32* %3
br label %24
24: ; preds = %23, %22
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define i32 @gen(i32 %0, float %1) {
%3 = tail call i64 (...) @rand()
%4 = sitofp i64 %3 to float
%5 = load i64, i64* @RAND_MAX
%6 = sitofp i64 %5 to float
%7 = fadd float %6, 1.000000e+00
%8 = fdiv float %4, %7
%9 = fcmp ult float %8, 0.000000e+00
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = sitofp i32 %0 to float
%12 = fdiv float %1, %11
%13 = fcmp olt float %8, %12
br i1 %13, label %15, label %14
14: ; preds = %10, %2
br label %15
15: ; preds = %10, %14
%16 = phi i32 [ 0, %14 ], [ 1, %10 ]
ret i32 %16
}