#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 */
typedef int /*<<< orphan*/ tmp;
typedef scalar_t__ int64_t;
typedef scalar_t__ int32_t;

/* Variables and functions */
int /*<<< orphan*/ AMCReadRandomByteArray(scalar_t__ *, int);
int32_t AMCRealRandomInt32(int32_t min, int32_t max) {
  int32_t ret = 0;
  if (min == max) {
    return min;
  } else {
    int32_t tmp;
    int64_t result;
    double resultFloat, minFloat, maxFloat, tmpFloat;
    if (min > max) {
      tmp = min;
      min = max;
      max = tmp;
    }
    tmp = 0;
    AMCReadRandomByteArray(&tmp, sizeof(tmp));
    minFloat = min;
    maxFloat = max;
    tmpFloat = (double)((int64_t)tmp + 0x80000000);
    resultFloat = minFloat + (maxFloat - minFloat + 1.0) *
                                 (tmpFloat / ((double)0x100000000));
    ret = (int32_t)resultFloat;
    ;
  }
  return ret;
}


x86 assembly (clang, -O0):
<AMCRealRandomInt32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    1143 <AMCRealRandomInt32+0x33>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f8 <AMCRealRandomInt32+0xe8>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jle    1169 <AMCRealRandomInt32+0x59>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0x8,%esi
call   1030 <AMCReadRandomByteArray@plt>
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movabs $0x80000000,%rax
add    -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  0xe44(%rip),%xmm2
addsd  %xmm2,%xmm0
movsd  -0x50(%rbp),%xmm2
movsd  0xe2b(%rip),%xmm3
divsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvttsd2si -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AMCRealRandomInt32>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmp    %rsi,%rdi
je     1175 <AMCRealRandomInt32+0x65>
mov    %rsi,%r14
cmovg  %rbx,%r14
cmovg  %rsi,%rbx
movq   $0x0,(%rsp)
mov    %rsp,%rdi
mov    $0x8,%esi
call   1030 <AMCReadRandomByteArray@plt>
cvtsi2sd %rbx,%xmm0
cvtsi2sd %r14,%xmm1
mov    $0x80000000,%eax
add    (%rsp),%rax
cvtsi2sd %rax,%xmm2
subsd  %xmm0,%xmm1
addsd  0xea0(%rip),%xmm1
mulsd  0xea0(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
cvttsd2si %xmm2,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @AMCRealRandomInt32(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
store i64 %0, i64* %4
store i64 %1, i64* %5
store i64 0, i64* %6
%13 = load i64, i64* %4
%14 = load i64, i64* %5
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i64, i64* %4
store i64 %17, i64* %3
br label %47
18: ; preds = %2
%19 = load i64, i64* %4
%20 = load i64, i64* %5
%21 = icmp sgt i64 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i64, i64* %4
store i64 %23, i64* %7
%24 = load i64, i64* %5
store i64 %24, i64* %4
%25 = load i64, i64* %7
store i64 %25, i64* %5
br label %26
26: ; preds = %22, %18
store i64 0, i64* %7
%27 = call i32 @AMCReadRandomByteArray(i64* %7, i32 8)
%28 = load i64, i64* %4
%29 = sitofp i64 %28 to double
store double %29, double* %10
%30 = load i64, i64* %5
%31 = sitofp i64 %30 to double
store double %31, double* %11
%32 = load i64, i64* %7
%33 = add nsw i64 %32, 2147483648
%34 = sitofp i64 %33 to double
store double %34, double* %12
%35 = load double, double* %10
%36 = load double, double* %11
%37 = load double, double* %10
%38 = fsub double %36, %37
%39 = fadd double %38, 1.000000e+00
%40 = load double, double* %12
%41 = fdiv double %40, 0x41F0000000000000
%42 = call double @llvm.fmuladd.f64(double %39, double %41, double %35)
store double %42, double* %9
%43 = load double, double* %9
%44 = fptosi double %43 to i64
store i64 %44, i64* %6
br label %45
45: ; preds = %26
%46 = load i64, i64* %6
store i64 %46, i64* %3
br label %47
47: ; preds = %45, %16
%48 = load i64, i64* %3
ret i64 %48
}

LLVM IR (-O2):
define i64 @AMCRealRandomInt32(i64 %0, i64 %1) {
%3 = alloca i64
%4 = icmp eq i64 %0, %1
br i1 %4, label %21, label %5
5: ; preds = %2
%6 = bitcast i64* %3 to i8*
%7 = icmp sgt i64 %0, %1
%8 = select i1 %7, i64 %0, i64 %1
%9 = select i1 %7, i64 %1, i64 %0
store i64 0, i64* %3
%10 = call i32 @AMCReadRandomByteArray(i64* %3, i32 8)
%11 = sitofp i64 %9 to double
%12 = sitofp i64 %8 to double
%13 = load i64, i64* %3
%14 = add nsw i64 %13, 2147483648
%15 = sitofp i64 %14 to double
%16 = fsub double %12, %11
%17 = fadd double %16, 1.000000e+00
%18 = fmul double %15, 0x3DF0000000000000
%19 = call double @llvm.fmuladd.f64(double %17, double %18, double %11)
%20 = fptosi double %19 to i64
br label %21
21: ; preds = %2, %5
%22 = phi i64 [ %20, %5 ], [ %0, %2 ]
ret i64 %22
}