#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 genrand_real1();
void rndChoice(int randomArray[], int nn, int NN) {
  int in, im;
  int rn, rm;
  im = 0;
  for (in = 0; in < NN && im < nn; in++) {
    rn = NN - in;
    rm = nn - im;
    if (genrand_real1() * rn < rm) {
      randomArray[im] = in;
      im += 1;
    }
  }
}


x86 assembly (clang, -O0):
<rndChoice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
xor    %eax,%eax
cmp    -0x10(%rbp),%ecx
mov    %al,-0x21(%rbp)
jge    114d <rndChoice+0x3d>
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    115d <rndChoice+0x4d>
jmp    11ad <rndChoice+0x9d>
mov    -0x10(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <genrand_real1@plt>
imul   -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    119a <rndChoice+0x8a>
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119f <rndChoice+0x8f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1130 <rndChoice+0x20>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rndChoice>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,(%rsp)
test   %edx,%edx
jle    1176 <rndChoice+0x66>
mov    %esi,%r14d
test   %esi,%esi
jle    1176 <rndChoice+0x66>
mov    %edx,%r15d
mov    $0x1,%ebx
mov    %edx,%ebp
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
mov    %r14d,%r12d
sub    %r13d,%r12d
xor    %eax,%eax
call   1030 <genrand_real1@plt>
imul   %ebp,%eax
cmp    %r12d,%eax
jge    1166 <rndChoice+0x56>
lea    -0x1(%rbx),%eax
movslq %r13d,%rcx
mov    (%rsp),%rdx
mov    %eax,(%rdx,%rcx,4)
add    $0x1,%r13d
cmp    %r15d,%ebx
jge    1176 <rndChoice+0x66>
add    $0x1,%ebx
add    $0xffffffff,%ebp
cmp    %r14d,%r13d
jl     1140 <rndChoice+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @rndChoice(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
store i32 0, i32* %7
br label %11
11: ; preds = %42, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32, i32* %8
%17 = load i32, i32* %5
%18 = icmp slt i32 %16, %17
br label %19
19: ; preds = %15, %11
%20 = phi i1 [ false, %11 ], [ %18, %15 ]
br i1 %20, label %21, label %45
21: ; preds = %19
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = sub nsw i32 %22, %23
store i32 %24, i32* %9
%25 = load i32, i32* %5
%26 = load i32, i32* %8
%27 = sub nsw i32 %25, %26
store i32 %27, i32* %10
%28 = call i32 (...) @genrand_real1()
%29 = load i32, i32* %9
%30 = mul nsw i32 %28, %29
%31 = load i32, i32* %10
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %41
33: ; preds = %21
%34 = load i32, i32* %7
%35 = load i32*, i32** %4
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
store i32 %34, i32* %38
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %41
41: ; preds = %33, %21
br label %42
42: ; preds = %41
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %11
45: ; preds = %19
ret void
}

LLVM IR (-O2):
define void @rndChoice(i32* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
%5 = icmp sgt i32 %1, 0
%6 = and i1 %4, %5
br i1 %6, label %7, label %25
7: ; preds = %3, %19
%8 = phi i32 [ %21, %19 ], [ 0, %3 ]
%9 = phi i32 [ %20, %19 ], [ 0, %3 ]
%10 = sub nsw i32 %2, %8
%11 = sub nsw i32 %1, %9
%12 = tail call i32 (...) @genrand_real1()
%13 = mul nsw i32 %12, %10
%14 = icmp slt i32 %13, %11
br i1 %14, label %15, label %19
15: ; preds = %7
%16 = sext i32 %9 to i64
%17 = getelementptr inbounds i32, i32* %0, i64 %16
store i32 %8, i32* %17
%18 = add nsw i32 %9, 1
br label %19
19: ; preds = %7, %15
%20 = phi i32 [ %18, %15 ], [ %9, %7 ]
%21 = add nuw nsw i32 %8, 1
%22 = icmp slt i32 %21, %2
%23 = icmp slt i32 %20, %1
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %7, label %25
25: ; preds = %19, %3
ret void
}