#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 /*<<< orphan*/ assert(int);
int aa_random_distribution(double rnd, double distribution[20]) {
  int aa;
  assert(rnd >= 0.0);
  assert(rnd <= 1.0);
  for (aa = 0; aa < 20; aa++) {
    rnd -= distribution[aa];
    if (rnd <= 0.0)
      return aa;
  }
  return -1;
}


x86 assembly (clang, -O0):
<aa_random_distribution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movsd  0xebe(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x14,-0x1c(%rbp)
jge    11ac <aa_random_distribution+0x9c>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1199 <aa_random_distribution+0x89>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <aa_random_distribution+0xa3>
jmp    119e <aa_random_distribution+0x8e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115b <aa_random_distribution+0x4b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aa_random_distribution>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm1,%xmm1
xor    %edi,%edi
ucomisd %xmm1,%xmm0
setae  %dil
call   1030 <assert@plt>
movsd  0xec7(%rip),%xmm0
xor    %edi,%edi
ucomisd 0x8(%rsp),%xmm0
setae  %dil
call   1030 <assert@plt>
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
subsd  (%rbx),%xmm1
xor    %eax,%eax
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x8(%rbx),%xmm1
mov    $0x1,%eax
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x10(%rbx),%xmm1
mov    $0x2,%eax
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x18(%rbx),%xmm1
mov    $0x3,%eax
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x20(%rbx),%xmm1
mov    $0x4,%eax
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x28(%rbx),%xmm1
mov    $0x5,%eax
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x30(%rbx),%xmm1
mov    $0x6,%eax
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x38(%rbx),%xmm1
mov    $0x7,%eax
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x40(%rbx),%xmm1
mov    $0x8,%eax
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x48(%rbx),%xmm1
mov    $0x9,%eax
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x50(%rbx),%xmm1
mov    $0xa,%eax
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x58(%rbx),%xmm1
mov    $0xb,%eax
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x60(%rbx),%xmm1
mov    $0xc,%eax
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x68(%rbx),%xmm1
mov    $0xd,%eax
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x70(%rbx),%xmm1
mov    $0xe,%eax
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x78(%rbx),%xmm1
mov    $0xf,%eax
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x80(%rbx),%xmm1
mov    $0x10,%eax
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x88(%rbx),%xmm1
mov    $0x11,%eax
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x90(%rbx),%xmm1
mov    $0x12,%eax
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
subsd  0x98(%rbx),%xmm1
mov    $0x13,%eax
ucomisd %xmm1,%xmm0
jae    12f9 <aa_random_distribution+0x1e9>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @aa_random_distribution(double %0, double* %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double*
%6 = alloca i32
store double %0, double* %4
store double* %1, double** %5
%7 = load double, double* %4
%8 = fcmp oge double %7, 0.000000e+00
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load double, double* %4
%12 = fcmp ole double %11, 1.000000e+00
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
store i32 0, i32* %6
br label %15
15: ; preds = %31, %2
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 20
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = load double*, double** %5
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = load double, double* %4
%25 = fsub double %24, %23
store double %25, double* %4
%26 = load double, double* %4
%27 = fcmp ole double %26, 0.000000e+00
br i1 %27, label %28, label %30
28: ; preds = %18
%29 = load i32, i32* %6
store i32 %29, i32* %3
br label %35
30: ; preds = %18
br label %31
31: ; preds = %30
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %15
34: ; preds = %15
store i32 -1, i32* %3
br label %35
35: ; preds = %34, %28
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
define i32 @aa_random_distribution(double %0, double* nocapture %1) {
%3 = fcmp oge double %0, 0.000000e+00
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = fcmp ole double %0, 1.000000e+00
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = load double, double* %1
%10 = fsub double %0, %9
%11 = fcmp ugt double %10, 0.000000e+00
br i1 %11, label %12, label %108
12: ; preds = %2
%13 = getelementptr inbounds double, double* %1, i64 1
%14 = load double, double* %13
%15 = fsub double %10, %14
%16 = fcmp ugt double %15, 0.000000e+00
br i1 %16, label %17, label %108
17: ; preds = %12
%18 = getelementptr inbounds double, double* %1, i64 2
%19 = load double, double* %18
%20 = fsub double %15, %19
%21 = fcmp ugt double %20, 0.000000e+00
br i1 %21, label %22, label %108
22: ; preds = %17
%23 = getelementptr inbounds double, double* %1, i64 3
%24 = load double, double* %23
%25 = fsub double %20, %24
%26 = fcmp ugt double %25, 0.000000e+00
br i1 %26, label %27, label %108
27: ; preds = %22
%28 = getelementptr inbounds double, double* %1, i64 4
%29 = load double, double* %28
%30 = fsub double %25, %29
%31 = fcmp ugt double %30, 0.000000e+00
br i1 %31, label %32, label %108
32: ; preds = %27
%33 = getelementptr inbounds double, double* %1, i64 5
%34 = load double, double* %33
%35 = fsub double %30, %34
%36 = fcmp ugt double %35, 0.000000e+00
br i1 %36, label %37, label %108
37: ; preds = %32
%38 = getelementptr inbounds double, double* %1, i64 6
%39 = load double, double* %38
%40 = fsub double %35, %39
%41 = fcmp ugt double %40, 0.000000e+00
br i1 %41, label %42, label %108
42: ; preds = %37
%43 = getelementptr inbounds double, double* %1, i64 7
%44 = load double, double* %43
%45 = fsub double %40, %44
%46 = fcmp ugt double %45, 0.000000e+00
br i1 %46, label %47, label %108
47: ; preds = %42
%48 = getelementptr inbounds double, double* %1, i64 8
%49 = load double, double* %48
%50 = fsub double %45, %49
%51 = fcmp ugt double %50, 0.000000e+00
br i1 %51, label %52, label %108
52: ; preds = %47
%53 = getelementptr inbounds double, double* %1, i64 9
%54 = load double, double* %53
%55 = fsub double %50, %54
%56 = fcmp ugt double %55, 0.000000e+00
br i1 %56, label %57, label %108
57: ; preds = %52
%58 = getelementptr inbounds double, double* %1, i64 10
%59 = load double, double* %58
%60 = fsub double %55, %59
%61 = fcmp ugt double %60, 0.000000e+00
br i1 %61, label %62, label %108
62: ; preds = %57
%63 = getelementptr inbounds double, double* %1, i64 11
%64 = load double, double* %63
%65 = fsub double %60, %64
%66 = fcmp ugt double %65, 0.000000e+00
br i1 %66, label %67, label %108
67: ; preds = %62
%68 = getelementptr inbounds double, double* %1, i64 12
%69 = load double, double* %68
%70 = fsub double %65, %69
%71 = fcmp ugt double %70, 0.000000e+00
br i1 %71, label %72, label %108
72: ; preds = %67
%73 = getelementptr inbounds double, double* %1, i64 13
%74 = load double, double* %73
%75 = fsub double %70, %74
%76 = fcmp ugt double %75, 0.000000e+00
br i1 %76, label %77, label %108
77: ; preds = %72
%78 = getelementptr inbounds double, double* %1, i64 14
%79 = load double, double* %78
%80 = fsub double %75, %79
%81 = fcmp ugt double %80, 0.000000e+00
br i1 %81, label %82, label %108
82: ; preds = %77
%83 = getelementptr inbounds double, double* %1, i64 15
%84 = load double, double* %83
%85 = fsub double %80, %84
%86 = fcmp ugt double %85, 0.000000e+00
br i1 %86, label %87, label %108
87: ; preds = %82
%88 = getelementptr inbounds double, double* %1, i64 16
%89 = load double, double* %88
%90 = fsub double %85, %89
%91 = fcmp ugt double %90, 0.000000e+00
br i1 %91, label %92, label %108
92: ; preds = %87
%93 = getelementptr inbounds double, double* %1, i64 17
%94 = load double, double* %93
%95 = fsub double %90, %94
%96 = fcmp ugt double %95, 0.000000e+00
br i1 %96, label %97, label %108
97: ; preds = %92
%98 = getelementptr inbounds double, double* %1, i64 18
%99 = load double, double* %98
%100 = fsub double %95, %99
%101 = fcmp ugt double %100, 0.000000e+00
br i1 %101, label %102, label %108
102: ; preds = %97
%103 = getelementptr inbounds double, double* %1, i64 19
%104 = load double, double* %103
%105 = fsub double %100, %104
%106 = fcmp ugt double %105, 0.000000e+00
br i1 %106, label %107, label %108
107: ; preds = %102
br label %108
108: ; preds = %107, %102, %97, %92, %87, %82, %77, %72, %67, %62, %57, %52, %47, %42, %37, %32, %27, %22, %17, %12, %2
%109 = phi i32 [ 0, %2 ], [ 1, %12 ], [ 2, %17 ], [ 3, %22 ], [ 4, %27 ], [ 5, %32 ], [ 6, %37 ], [ 7, %42 ], [ 8, %47 ], [ 9, %52 ], [ 10, %57 ], [ 11, %62 ], [ 12, %67 ], [ 13, %72 ], [ 14, %77 ], [ 15, %82 ], [ 16, %87 ], [ 17, %92 ], [ 18, %97 ], [ 19, %102 ], [ -1, %107 ]
ret i32 %109
}