#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 rand();
int randomloss(double lossprob) {
  int loss = 0;
  double msb;
  double lsb;
  double tmp;
  if (lossprob == 0.0) {
    return loss;
  }
  msb = (double)(rand() % 100);
  lsb = (double)(rand() % 10);
  tmp = msb + (double)(lsb / (double)10);
  if (tmp < lossprob) {
    loss = 1;
  }
  return loss;
}


x86 assembly (clang, -O0):
<randomloss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1147 <randomloss+0x37>
jp     1147 <randomloss+0x37>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <randomloss+0xa7>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
cvtsi2sd %edx,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
cvtsi2sd %edx,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe77(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b1 <randomloss+0xa1>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomloss>:
xor    %eax,%eax
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    111f <randomloss+0xf>
jp     111f <randomloss+0xf>
ret
sub    $0x18,%rsp
xor    %eax,%eax
movsd  %xmm0,0x10(%rsp)
call   1030 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xe75(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
xor    %eax,%eax
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
seta   %al
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @randomloss(double %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %3
store i32 0, i32* %4
%8 = load double, double* %3
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %4
store i32 %11, i32* %2
br label %29
12: ; preds = %1
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 100
%15 = sitofp i32 %14 to double
store double %15, double* %5
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 10
%18 = sitofp i32 %17 to double
store double %18, double* %6
%19 = load double, double* %5
%20 = load double, double* %6
%21 = fdiv double %20, 1.000000e+01
%22 = fadd double %19, %21
store double %22, double* %7
%23 = load double, double* %7
%24 = load double, double* %3
%25 = fcmp olt double %23, %24
br i1 %25, label %26, label %27
26: ; preds = %12
store i32 1, i32* %4
br label %27
27: ; preds = %26, %12
%28 = load i32, i32* %4
store i32 %28, i32* %2
br label %29
29: ; preds = %27, %10
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @randomloss(double %0) {
%2 = fcmp oeq double %0, 0.000000e+00
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, 100
%6 = sitofp i32 %5 to double
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 10
%9 = sitofp i32 %8 to double
%10 = fdiv double %9, 1.000000e+01
%11 = fadd double %10, %6
%12 = fcmp olt double %11, %0
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %1, %3
%15 = phi i32 [ %13, %3 ], [ 0, %1 ]
ret i32 %15
}