#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 */
double RA();
double DP(double *prob, int nval) {
  int i;
  double c;
  c = RA();
  i = 0;
  while ((i < nval - 1) && (c > prob[i]))
    i++;
  return ((double)(i));
}


x86 assembly (clang, -O0):
<DP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1030 <RA@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x19(%rbp)
jge    1160 <DP+0x50>
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
ucomisd (%rax,%rcx,8),%xmm0
seta   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1170 <DP+0x60>
jmp    117e <DP+0x6e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1132 <DP+0x22>
cvtsi2sdl -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DP>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <RA@plt>
cmp    $0x2,%r14d
jl     1153 <DP+0x43>
add    $0xffffffff,%r14d
mov    %r14d,%eax
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
ucomisd (%rbx,%rbp,8),%xmm0
jbe    1153 <DP+0x43>
add    $0x1,%rbp
cmp    %rbp,%rax
jne    1140 <DP+0x30>
mov    %r14d,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @DP(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
store double* %0, double** %3
store i32 %1, i32* %4
%7 = call double (...) @RA()
store double %7, double* %6
store i32 0, i32* %5
br label %8
8: ; preds = %23, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %21
13: ; preds = %8
%14 = load double, double* %6
%15 = load double*, double** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
%20 = fcmp ogt double %14, %19
br label %21
21: ; preds = %13, %8
%22 = phi i1 [ false, %8 ], [ %20, %13 ]
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %8
26: ; preds = %21
%27 = load i32, i32* %5
%28 = sitofp i32 %27 to double
ret double %28
}

LLVM IR (-O2):
define double @DP(double* nocapture %0, i32 %1) {
%3 = tail call double (...) @RA()
%4 = add i32 %1, -1
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %18
6: ; preds = %2
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %13
%9 = phi i64 [ 0, %6 ], [ %14, %13 ]
%10 = getelementptr inbounds double, double* %0, i64 %9
%11 = load double, double* %10
%12 = fcmp ogt double %3, %11
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %7
br i1 %15, label %18, label %8
16: ; preds = %8
%17 = trunc i64 %9 to i32
br label %18
18: ; preds = %13, %16, %2
%19 = phi i32 [ 0, %2 ], [ %17, %16 ], [ %4, %13 ]
%20 = sitofp i32 %19 to double
ret double %20
}