#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 */
unsigned long long const random64();
int /*<<< orphan*/ randomExpDouble(double);
scalar_t__ rint(int /*<<< orphan*/);
unsigned long long getRandomInterval(const unsigned int distribution,
                                     const unsigned long long timeout) {
  unsigned long long newTimeout = 0;
  switch (distribution) {
  case 0:
    newTimeout = random64() % timeout;
    break;
  case 1:
    newTimeout = (unsigned long long)rint(randomExpDouble((double)timeout));
    break;
  }
  if (newTimeout < 500000) {
    newTimeout = 500000;
  }
  return (newTimeout);
}


x86 assembly (clang, -O0):
<getRandomInterval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     116b <getRandomInterval+0x3b>
jmp    115a <getRandomInterval+0x2a>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
je     1183 <getRandomInterval+0x53>
jmp    11ba <getRandomInterval+0x8a>
mov    $0x0,%al
call   1040 <random64@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    %rdx,-0x18(%rbp)
jmp    11ba <getRandomInterval+0x8a>
movaps 0xe76(%rip),%xmm1
movq   -0x10(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe75(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
call   1050 <randomExpDouble@plt>
mov    %eax,%edi
call   1030 <rint@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x7a120,-0x18(%rbp)
jae    11d0 <getRandomInterval+0xa0>
movq   $0x7a120,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getRandomInterval>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x1,%edi
je     115c <getRandomInterval+0x2c>
mov    $0x7a120,%eax
test   %edi,%edi
jne    11a2 <getRandomInterval+0x72>
xor    %eax,%eax
call   1040 <random64@plt>
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
je     118e <getRandomInterval+0x5e>
xor    %edx,%edx
div    %rbx
jmp    1192 <getRandomInterval+0x62>
movq   %rbx,%xmm1
punpckldq 0xe97(%rip),%xmm1
subpd  0xe9f(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
call   1050 <randomExpDouble@plt>
mov    %eax,%edi
call   1030 <rint@plt>
mov    %rax,%rdx
jmp    1192 <getRandomInterval+0x62>
xor    %edx,%edx
div    %ebx
cmp    $0x7a121,%rdx
mov    $0x7a120,%eax
cmovae %rdx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @getRandomInterval(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
store i32 %0, i32* %3
store i64 %1, i64* %4
store i64 0, i64* %5
%6 = load i32, i32* %3
switch i32 %6, label %16 [
i32 0, label %7
i32 1, label %11
]
7: ; preds = %2
%8 = call i64 (...) @random64()
%9 = load i64, i64* %4
%10 = urem i64 %8, %9
store i64 %10, i64* %5
br label %16
11: ; preds = %2
%12 = load i64, i64* %4
%13 = uitofp i64 %12 to double
%14 = call i32 @randomExpDouble(double %13)
%15 = call i64 @rint(i32 %14)
store i64 %15, i64* %5
br label %16
16: ; preds = %2, %11, %7
%17 = load i64, i64* %5
%18 = icmp ult i64 %17, 500000
br i1 %18, label %19, label %20
19: ; preds = %16
store i64 500000, i64* %5
br label %20
20: ; preds = %19, %16
%21 = load i64, i64* %5
ret i64 %21
}

LLVM IR (-O2):
define i64 @getRandomInterval(i32 %0, i64 %1) {
switch i32 %0, label %14 [
i32 0, label %3
i32 1, label %6
]
3: ; preds = %2
%4 = tail call i64 (...) @random64()
%5 = urem i64 %4, %1
br label %10
6: ; preds = %2
%7 = uitofp i64 %1 to double
%8 = tail call i32 @randomExpDouble(double %7)
%9 = tail call i64 @rint(i32 %8)
br label %10
10: ; preds = %6, %3
%11 = phi i64 [ %9, %6 ], [ %5, %3 ]
%12 = icmp ugt i64 %11, 500000
%13 = select i1 %12, i64 %11, i64 500000
br label %14
14: ; preds = %10, %2
%15 = phi i64 [ 500000, %2 ], [ %13, %10 ]
ret i64 %15
}