#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__ GenerateUniformRandomNumber(int /*<<< orphan*/, int);
int get_valid_index_for_output(int n_columns, int n_rows, int n_input_values) {
  double input_proba =
      (double)n_input_values /
      ((double)n_input_values + ((double)n_columns * (double)n_rows));
  if (GenerateUniformRandomNumber(0, 1) < 0) {
    return (int)GenerateUniformRandomNumber(0, n_input_values);
  } else {
    return (int)GenerateUniformRandomNumber(0, n_columns * n_rows) +
           n_input_values;
  }
}


x86 assembly (clang, -O0):
<get_valid_index_for_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm0
cvtsi2sdl -0x10(%rbp),%xmm2
cvtsi2sdl -0x8(%rbp),%xmm1
cvtsi2sdl -0xc(%rbp),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <GenerateUniformRandomNumber@plt>
cmp    $0x0,%rax
jge    116e <get_valid_index_for_output+0x5e>
mov    -0x10(%rbp),%esi
xor    %edi,%edi
call   1030 <GenerateUniformRandomNumber@plt>
mov    %eax,-0x4(%rbp)
jmp    1182 <get_valid_index_for_output+0x72>
mov    -0x8(%rbp),%esi
imul   -0xc(%rbp),%esi
xor    %edi,%edi
call   1030 <GenerateUniformRandomNumber@plt>
add    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_valid_index_for_output>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <GenerateUniformRandomNumber@plt>
test   %rax,%rax
js     113d <get_valid_index_for_output+0x2d>
imul   %ebx,%ebp
xor    %edi,%edi
mov    %ebp,%esi
call   1030 <GenerateUniformRandomNumber@plt>
add    %r14d,%eax
jmp    1147 <get_valid_index_for_output+0x37>
xor    %edi,%edi
mov    %r14d,%esi
call   1030 <GenerateUniformRandomNumber@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_valid_index_for_output(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = sitofp i32 %9 to double
%11 = load i32, i32* %7
%12 = sitofp i32 %11 to double
%13 = load i32, i32* %5
%14 = sitofp i32 %13 to double
%15 = load i32, i32* %6
%16 = sitofp i32 %15 to double
%17 = call double @llvm.fmuladd.f64(double %14, double %16, double %12)
%18 = fdiv double %10, %17
store double %18, double* %8
%19 = call i64 @GenerateUniformRandomNumber(i32 0, i32 1)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %3
%22 = load i32, i32* %7
%23 = call i64 @GenerateUniformRandomNumber(i32 0, i32 %22)
%24 = trunc i64 %23 to i32
store i32 %24, i32* %4
br label %33
25: ; preds = %3
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = mul nsw i32 %26, %27
%29 = call i64 @GenerateUniformRandomNumber(i32 0, i32 %28)
%30 = trunc i64 %29 to i32
%31 = load i32, i32* %7
%32 = add nsw i32 %30, %31
store i32 %32, i32* %4
br label %33
33: ; preds = %25, %21
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
define i32 @get_valid_index_for_output(i32 %0, i32 %1, i32 %2) {
%4 = tail call i64 @GenerateUniformRandomNumber(i32 0, i32 1)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i64 @GenerateUniformRandomNumber(i32 0, i32 %2)
%8 = trunc i64 %7 to i32
br label %14
9: ; preds = %3
%10 = mul nsw i32 %1, %0
%11 = tail call i64 @GenerateUniformRandomNumber(i32 0, i32 %10)
%12 = trunc i64 %11 to i32
%13 = add nsw i32 %12, %2
br label %14
14: ; preds = %9, %6
%15 = phi i32 [ %8, %6 ], [ %13, %9 ]
ret i32 %15
}