#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 rand();
int random_register(int **);
int random_operand(int definition[2][3][5]) {
  int operand_index;
  int register_type;
  int dice_roll;
  dice_roll = rand() % 100;
  if (dice_roll < *definition[0][2]) {
    register_type = 0;
  } else {
    if (dice_roll < *definition[1][2]) {
      register_type = 1;
    } else {
      register_type = 2;
    }
  }
  operand_index = random_register(definition[register_type]);
  return operand_index;
}


x86 assembly (clang, -O0):
<random_operand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    0x28(%rcx),%eax
jge    115a <random_operand+0x3a>
movl   $0x0,-0x10(%rbp)
jmp    1182 <random_operand+0x62>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    0x64(%rcx),%eax
jge    1176 <random_operand+0x56>
movl   $0x1,-0x10(%rbp)
jmp    117d <random_operand+0x5d>
movl   $0x2,-0x10(%rbp)
jmp    1182 <random_operand+0x62>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
imul   $0x3c,%rax,%rax
add    %rax,%rdi
call   1030 <random_register@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_operand>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
cmp    0x28(%rbx),%eax
jl     1162 <random_operand+0x42>
xor    %ecx,%ecx
cmp    0x64(%rbx),%eax
setl   %cl
mov    $0x2,%r14d
sub    %rcx,%r14
imul   $0x3c,%r14,%rax
add    %rax,%rbx
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <random_register@plt>

LLVM IR (-O0):
define i32 @random_operand([3 x [5 x i32]]* %0) {
%2 = alloca [3 x [5 x i32]]*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store [3 x [5 x i32]]* %0, [3 x [5 x i32]]** %2
%6 = call i32 (...) @rand()
%7 = srem i32 %6, 100
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = load [3 x [5 x i32]]*, [3 x [5 x i32]]** %2
%10 = getelementptr inbounds [3 x [5 x i32]], [3 x [5 x i32]]* %9, i64 0
%11 = getelementptr inbounds [3 x [5 x i32]], [3 x [5 x i32]]* %10, i64 0, i64 2
%12 = getelementptr inbounds [5 x i32], [5 x i32]* %11, i64 0, i64 0
%13 = load i32, i32* %12
%14 = icmp slt i32 %8, %13
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 0, i32* %4
br label %27
16: ; preds = %1
%17 = load i32, i32* %5
%18 = load [3 x [5 x i32]]*, [3 x [5 x i32]]** %2
%19 = getelementptr inbounds [3 x [5 x i32]], [3 x [5 x i32]]* %18, i64 1
%20 = getelementptr inbounds [3 x [5 x i32]], [3 x [5 x i32]]* %19, i64 0, i64 2
%21 = getelementptr inbounds [5 x i32], [5 x i32]* %20, i64 0, i64 0
%22 = load i32, i32* %21
%23 = icmp slt i32 %17, %22
br i1 %23, label %24, label %25
24: ; preds = %16
store i32 1, i32* %4
br label %26
25: ; preds = %16
store i32 2, i32* %4
br label %26
26: ; preds = %25, %24
br label %27
27: ; preds = %26, %15
%28 = load [3 x [5 x i32]]*, [3 x [5 x i32]]** %2
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [3 x [5 x i32]], [3 x [5 x i32]]* %28, i64 %30
%32 = getelementptr inbounds [3 x [5 x i32]], [3 x [5 x i32]]* %31, i64 0, i64 0
%33 = bitcast [5 x i32]* %32 to i32**
%34 = call i32 @random_register(i32** %33)
store i32 %34, i32* %3
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @random_operand([3 x [5 x i32]]* %0) {
%2 = tail call i32 (...) @rand()
%3 = srem i32 %2, 100
%4 = getelementptr inbounds [3 x [5 x i32]], [3 x [5 x i32]]* %0, i64 0, i64 2, i64 0
%5 = load i32, i32* %4
%6 = icmp slt i32 %3, %5
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = getelementptr inbounds [3 x [5 x i32]], [3 x [5 x i32]]* %0, i64 1, i64 2, i64 0
%9 = load i32, i32* %8
%10 = icmp slt i32 %3, %9
%11 = select i1 %10, i64 1, i64 2
br label %12
12: ; preds = %7, %1
%13 = phi i64 [ 0, %1 ], [ %11, %7 ]
%14 = getelementptr inbounds [3 x [5 x i32]], [3 x [5 x i32]]* %0, i64 %13, i64 0
%15 = bitcast [5 x i32]* %14 to i32**
%16 = tail call i32 @random_register(i32** %15)
ret i32 %16
}