#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();
char getCharacterImputeBIN(int *input) {
  char states[2] = {'0', '1'};
  int total = input[0] + input[1];
  int rn = rand() % total + 1;
  int j = 0;
  int current = input[j];
  while (rn > current)
    current += input[++j];
  return states[j];
}


x86 assembly (clang, -O0):
<getCharacterImputeBIN>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xedd(%rip),%ax
mov    %ax,-0xa(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
add    0x4(%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
cltd
idivl  -0x10(%rbp)
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    1187 <getCharacterImputeBIN+0x77>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    115d <getCharacterImputeBIN+0x4d>
movslq -0x18(%rbp),%rax
movsbl -0xa(%rbp,%rax,1),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCharacterImputeBIN>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x4(%rdi),%ebp
add    (%rdi),%ebp
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <rand@plt>
cltd
idiv   %ebp
mov    (%rbx),%eax
cmp    %eax,%edx
jl     114f <getCharacterImputeBIN+0x3f>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    0x4(%rbx,%rcx,4),%eax
add    $0x1,%rcx
cmp    %eax,%edx
jge    1140 <getCharacterImputeBIN+0x30>
mov    %ecx,%r14d
lea    0xeaa(%rip),%rax
mov    (%r14,%rax,1),%al
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.getCharacterImputeBIN.states = [2 x i8] c"01"
define signext i8 @getCharacterImputeBIN(i32* %0) {
%2 = alloca i32*
%3 = alloca [2 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %2
%8 = bitcast [2 x i8]* %3 to i8*
%9 = load i32*, i32** %2
%10 = getelementptr inbounds i32, i32* %9, i64 0
%11 = load i32, i32* %10
%12 = load i32*, i32** %2
%13 = getelementptr inbounds i32, i32* %12, i64 1
%14 = load i32, i32* %13
%15 = add nsw i32 %11, %14
store i32 %15, i32* %4
%16 = call i32 (...) @rand()
%17 = load i32, i32* %4
%18 = srem i32 %16, %17
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
store i32 0, i32* %6
%20 = load i32*, i32** %2
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
store i32 %24, i32* %7
br label %25
25: ; preds = %29, %1
%26 = load i32, i32* %5
%27 = load i32, i32* %7
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %38
29: ; preds = %25
%30 = load i32*, i32** %2
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %30, i64 %33
%35 = load i32, i32* %34
%36 = load i32, i32* %7
%37 = add nsw i32 %36, %35
store i32 %37, i32* %7
br label %25
38: ; preds = %25
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 %40
%42 = load i8, i8* %41
ret i8 %42
}

LLVM IR (-O2):
@__const.getCharacterImputeBIN.states = [2 x i8] c"01"
define signext i8 @getCharacterImputeBIN(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = getelementptr inbounds i32, i32* %0, i64 1
%4 = load i32, i32* %3
%5 = add nsw i32 %4, %2
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, %5
%8 = load i32, i32* %0
%9 = icmp slt i32 %7, %8
br i1 %9, label %20, label %10
10: ; preds = %1, %10
%11 = phi i64 [ %13, %10 ], [ 0, %1 ]
%12 = phi i32 [ %16, %10 ], [ %8, %1 ]
%13 = add nuw nsw i64 %11, 1
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = add nsw i32 %15, %12
%17 = icmp slt i32 %7, %16
br i1 %17, label %18, label %10
18: ; preds = %10
%19 = and i64 %13, 4294967295
br label %20
20: ; preds = %18, %1
%21 = phi i64 [ 0, %1 ], [ %19, %18 ]
%22 = getelementptr inbounds [2 x i8], [2 x i8]* @__const.getCharacterImputeBIN.states, i64 0, i64 %21
%23 = load i8, i8* %22
ret i8 %23
}