#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 getCharacterImputeDNA(int *input) {
  char states[4] = {'A', 'C', 'G', 'T'};
  int total = input[3] + input[4] + input[5] + input[6];
  int rn = rand() % total + 1;
  int j = 3;
  int current = input[j];
  while (rn > current)
    current += input[++j];
  return states[j - 3];
}


x86 assembly (clang, -O0):
<getCharacterImputeDNA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xede(%rip),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%eax
mov    -0x8(%rbp),%rcx
add    0x10(%rcx),%eax
mov    -0x8(%rbp),%rcx
add    0x14(%rcx),%eax
mov    -0x8(%rbp),%rcx
add    0x18(%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   $0x3,-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    1194 <getCharacterImputeDNA+0x84>
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    116a <getCharacterImputeDNA+0x5a>
mov    -0x18(%rbp),%eax
sub    $0x3,%eax
cltq
movsbl -0xc(%rbp,%rax,1),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCharacterImputeDNA>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
movdqu 0xc(%rdi),%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%ebp
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <rand@plt>
cltd
idiv   %ebp
mov    0xc(%rbx),%eax
cmp    %eax,%edx
jl     1171 <getCharacterImputeDNA+0x61>
add    $0x10,%rbx
xor    %r14d,%r14d
movabs $0x100000000,%rcx
nopw   0x0(%rax,%rax,1)
add    %rcx,%r14
add    (%rbx),%eax
add    $0x4,%rbx
cmp    %eax,%edx
jge    1160 <getCharacterImputeDNA+0x50>
sar    $0x20,%r14
lea    0xe88(%rip),%rax
mov    (%r14,%rax,1),%al
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@__const.getCharacterImputeDNA.states = [4 x i8] c"ACGT"
define signext i8 @getCharacterImputeDNA(i32* nocapture %0) {
%2 = getelementptr inbounds i32, i32* %0, i64 3
%3 = bitcast i32* %2 to <4 x i32>*
%4 = load <4 x i32>, <4 x i32>* %3
%5 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %4)
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, %5
%8 = load i32, i32* %2
%9 = icmp slt i32 %7, %8
br i1 %9, label %22, label %10
10: ; preds = %1, %10
%11 = phi i64 [ %13, %10 ], [ 3, %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 = shl i64 %11, 32
%20 = add i64 %19, -8589934592
%21 = ashr exact i64 %20, 32
br label %22
22: ; preds = %18, %1
%23 = phi i64 [ 0, %1 ], [ %21, %18 ]
%24 = getelementptr inbounds [4 x i8], [4 x i8]* @__const.getCharacterImputeDNA.states, i64 0, i64 %23
%25 = load i8, i8* %24
ret i8 %25
}