#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*/ find_probabilities(double *, double *, double);
int /*<<< orphan*/ generate_sequence(char *, int, double *);
void randomize(char *seq, int n) {
  int i;
  double fr[5] = {0.0}, pr[4] = {0.0}, q[4], delta = 0.0000001;
  for (i = 0; i < n; i++) {
    if (seq[i] >= 0 && seq[i] < 4) {
      ++fr[seq[i]];
      ++fr[4];
    }
  }
  for (i = 0; i < 3; ++i)
    fr[i] /= fr[4];
  fr[3] = 1.0 - fr[0] - fr[1] - fr[2];
  find_probabilities(fr, pr, delta);
  q[0] = pr[0];
  q[1] = q[0] + pr[1];
  q[2] = q[1] + pr[2];
  q[3] = 1.0;
  generate_sequence(seq, n, q);
}


x86 assembly (clang, -O0):
<randomize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
movsd  0xe96(%rip),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11f5 <randomize+0xc5>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jl     11e2 <randomize+0xb2>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x4,%eax
jge    11e2 <randomize+0xb2>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbq (%rax,%rcx,1),%rax
movsd  0xe44(%rip),%xmm0
addsd  -0x40(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x40(%rbp,%rax,8)
movsd  0xe30(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11e7 <randomize+0xb7>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1179 <randomize+0x49>
movl   $0x0,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jge    122d <randomize+0xfd>
movsd  -0x20(%rbp),%xmm1
movslq -0x10(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp,%rax,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11fc <randomize+0xcc>
movsd  0xdd3(%rip),%xmm0
subsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
movsd  -0x88(%rbp),%xmm0
ff
call   1050 <find_probabilities@plt>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xd7a(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x80(%rbp),%rdx
call   1040 <generate_sequence@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomize>:
push   %rbp
push   %rbx
sub    $0x78,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
xorpd  %xmm1,%xmm1
movapd %xmm1,0x10(%rsp)
movapd %xmm1,(%rsp)
movq   $0x0,0x20(%rsp)
movapd %xmm1,0x40(%rsp)
movapd %xmm1,0x30(%rsp)
test   %esi,%esi
jle    11a1 <randomize+0x81>
mov    %ebp,%eax
cmp    $0x1,%ebp
jne    123c <randomize+0x11c>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
test   $0x1,%al
je     1194 <randomize+0x74>
movzbl (%rbx,%rcx,1),%eax
cmp    $0x3,%rax
ja     1194 <randomize+0x74>
movsd  0xe86(%rip),%xmm0
movsd  (%rsp,%rax,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp,%rax,8)
addsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
movapd (%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
jmp    11a9 <randomize+0x89>
xorpd  %xmm2,%xmm2
xorpd  %xmm0,%xmm0
divsd  %xmm0,%xmm2
unpcklpd %xmm0,%xmm0
divpd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movsd  %xmm2,0x10(%rsp)
movsd  0xe38(%rip),%xmm0
subsd  %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
subsd  %xmm1,%xmm0
subsd  %xmm2,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    %rsp,%rdi
lea    0x30(%rsp),%rsi
movsd  0xe1a(%rip),%xmm0
call   1040 <find_probabilities@plt>
movsd  0x30(%rsp),%xmm0
movsd  %xmm0,0x50(%rsp)
addsd  0x38(%rsp),%xmm0
movsd  %xmm0,0x58(%rsp)
addsd  0x40(%rsp),%xmm0
movsd  %xmm0,0x60(%rsp)
movabs $0x3ff0000000000000,%rax
mov    %rax,0x68(%rsp)
lea    0x50(%rsp),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <generate_sequence@plt>
add    $0x78,%rsp
pop    %rbx
pop    %rbp
ret
mov    %eax,%edx
and    $0xfffffffe,%edx
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
movsd  0xdb1(%rip),%xmm1
jmp    126d <randomize+0x14d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x2,%rcx
cmp    %rcx,%rdx
je     1164 <randomize+0x44>
movzbl (%rbx,%rcx,1),%esi
cmp    $0x3,%rsi
ja     1295 <randomize+0x175>
movsd  (%rsp,%rsi,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp,%rsi,8)
movsd  0x20(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x20(%rsp)
movzbl 0x1(%rbx,%rcx,1),%esi
cmp    $0x3,%rsi
ja     1260 <randomize+0x140>
movsd  (%rsp,%rsi,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp,%rsi,8)
movsd  0x20(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x20(%rsp)
jmp    1260 <randomize+0x140>

LLVM IR (-O0):
define void @randomize(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [5 x double]
%7 = alloca [4 x double]
%8 = alloca [4 x double]
%9 = alloca double
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = bitcast [5 x double]* %6 to i8*
%11 = bitcast [4 x double]* %7 to i8*
store double 0x3E7AD7F29ABCAF48, double* %9
store i32 0, i32* %5
br label %12
12: ; preds = %46, %2
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %49
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %45
24: ; preds = %16
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp slt i32 %30, 4
br i1 %31, label %32, label %45
32: ; preds = %24
%33 = load i8*, i8** %3
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i64
%39 = getelementptr inbounds [5 x double], [5 x double]* %6, i64 0, i64 %38
%40 = load double, double* %39
%41 = fadd double %40, 1.000000e+00
store double %41, double* %39
%42 = getelementptr inbounds [5 x double], [5 x double]* %6, i64 0, i64 4
%43 = load double, double* %42
%44 = fadd double %43, 1.000000e+00
store double %44, double* %42
br label %45
45: ; preds = %32, %24, %16
br label %46
46: ; preds = %45
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
br label %12
49: ; preds = %12
store i32 0, i32* %5
br label %50
50: ; preds = %61, %49
%51 = load i32, i32* %5
%52 = icmp slt i32 %51, 3
br i1 %52, label %53, label %64
53: ; preds = %50
%54 = getelementptr inbounds [5 x double], [5 x double]* %6, i64 0, i64 4
%55 = load double, double* %54
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [5 x double], [5 x double]* %6, i64 0, i64 %57
%59 = load double, double* %58
%60 = fdiv double %59, %55
store double %60, double* %58
br label %61
61: ; preds = %53
%62 = load i32, i32* %5
%63 = add nsw i32 %62, 1
store i32 %63, i32* %5
br label %50
64: ; preds = %50
%65 = getelementptr inbounds [5 x double], [5 x double]* %6, i64 0, i64 0
%66 = load double, double* %65
%67 = fsub double 1.000000e+00, %66
%68 = getelementptr inbounds [5 x double], [5 x double]* %6, i64 0, i64 1
%69 = load double, double* %68
%70 = fsub double %67, %69
%71 = getelementptr inbounds [5 x double], [5 x double]* %6, i64 0, i64 2
%72 = load double, double* %71
%73 = fsub double %70, %72
%74 = getelementptr inbounds [5 x double], [5 x double]* %6, i64 0, i64 3
store double %73, double* %74
%75 = getelementptr inbounds [5 x double], [5 x double]* %6, i64 0, i64 0
%76 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 0
%77 = load double, double* %9
%78 = call i32 @find_probabilities(double* %75, double* %76, double %77)
%79 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 0
%80 = load double, double* %79
%81 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
store double %80, double* %81
%82 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%83 = load double, double* %82
%84 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 1
%85 = load double, double* %84
%86 = fadd double %83, %85
%87 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 1
store double %86, double* %87
%88 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 1
%89 = load double, double* %88
%90 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 2
%91 = load double, double* %90
%92 = fadd double %89, %91
%93 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 2
store double %92, double* %93
%94 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 3
store double 1.000000e+00, double* %94
%95 = load i8*, i8** %3
%96 = load i32, i32* %4
%97 = getelementptr inbounds [4 x double], [4 x double]* %8, i64 0, i64 0
%98 = call i32 @generate_sequence(i8* %95, i32 %96, double* %97)
ret void
}

LLVM IR (-O2):
define void @randomize(i8* %0, i32 %1) {
%3 = alloca [5 x double]
%4 = alloca [4 x double]
%5 = alloca [4 x double]
%6 = bitcast [5 x double]* %3 to i8*
%7 = bitcast [4 x double]* %4 to i8*
%8 = bitcast [4 x double]* %5 to i8*
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %39
10: ; preds = %2
%11 = getelementptr inbounds [5 x double], [5 x double]* %3, i64 0, i64 4
%12 = zext i32 %1 to i64
%13 = and i64 %12, 1
%14 = icmp eq i32 %1, 1
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = and i64 %12, 4294967294
br label %70
17: ; preds = %97, %10
%18 = phi double [ undef, %10 ], [ %98, %97 ]
%19 = phi double [ 0.000000e+00, %10 ], [ %98, %97 ]
%20 = phi i64 [ 0, %10 ], [ %99, %97 ]
%21 = icmp eq i64 %13, 0
br i1 %21, label %33, label %22
22: ; preds = %17
%23 = getelementptr inbounds i8, i8* %0, i64 %20
%24 = load i8, i8* %23
%25 = icmp ult i8 %24, 4
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = zext i8 %24 to i64
%28 = getelementptr inbounds [5 x double], [5 x double]* %3, i64 0, i64 %27
%29 = load double, double* %28
%30 = fadd double %29, 1.000000e+00
store double %30, double* %28
%31 = load double, double* %11
%32 = fadd double %31, 1.000000e+00
store double %32, double* %11
br label %33
33: ; preds = %22, %26, %17
%34 = phi double [ %18, %17 ], [ %19, %22 ], [ %32, %26 ]
%35 = bitcast [5 x double]* %3 to <2 x double>*
%36 = load <2 x double>, <2 x double>* %35
%37 = getelementptr inbounds [5 x double], [5 x double]* %3, i64 0, i64 2
%38 = load double, double* %37
br label %39
39: ; preds = %33, %2
%40 = phi double [ %38, %33 ], [ 0.000000e+00, %2 ]
%41 = phi double [ %34, %33 ], [ 0.000000e+00, %2 ]
%42 = phi <2 x double> [ %36, %33 ], [ zeroinitializer, %2 ]
%43 = getelementptr inbounds [5 x double], [5 x double]* %3, i64 0, i64 0
%44 = insertelement <2 x double> poison, double %41, i64 0
%45 = shufflevector <2 x double> %44, <2 x double> poison, <2 x i32> zeroinitializer
%46 = fdiv <2 x double> %42, %45
%47 = bitcast [5 x double]* %3 to <2 x double>*
store <2 x double> %46, <2 x double>* %47
%48 = getelementptr inbounds [5 x double], [5 x double]* %3, i64 0, i64 2
%49 = fdiv double %40, %41
store double %49, double* %48
%50 = extractelement <2 x double> %46, i64 0
%51 = fsub double 1.000000e+00, %50
%52 = extractelement <2 x double> %46, i64 1
%53 = fsub double %51, %52
%54 = fsub double %53, %49
%55 = getelementptr inbounds [5 x double], [5 x double]* %3, i64 0, i64 3
store double %54, double* %55
%56 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%57 = call i32 @find_probabilities(double* %43, double* %56, double 0x3E7AD7F29ABCAF48)
%58 = load double, double* %56
%59 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
store double %58, double* %59
%60 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 1
%61 = load double, double* %60
%62 = fadd double %58, %61
%63 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 1
store double %62, double* %63
%64 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 2
%65 = load double, double* %64
%66 = fadd double %62, %65
%67 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 2
store double %66, double* %67
%68 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 3
store double 1.000000e+00, double* %68
%69 = call i32 @generate_sequence(i8* %0, i32 %1, double* %59)
ret void
70: ; preds = %97, %15
%71 = phi double [ 0.000000e+00, %15 ], [ %98, %97 ]
%72 = phi i64 [ 0, %15 ], [ %99, %97 ]
%73 = phi i64 [ 0, %15 ], [ %100, %97 ]
%74 = getelementptr inbounds i8, i8* %0, i64 %72
%75 = load i8, i8* %74
%76 = icmp ult i8 %75, 4
br i1 %76, label %77, label %84
77: ; preds = %70
%78 = zext i8 %75 to i64
%79 = getelementptr inbounds [5 x double], [5 x double]* %3, i64 0, i64 %78
%80 = load double, double* %79
%81 = fadd double %80, 1.000000e+00
store double %81, double* %79
%82 = load double, double* %11
%83 = fadd double %82, 1.000000e+00
store double %83, double* %11
br label %84
84: ; preds = %70, %77
%85 = phi double [ %71, %70 ], [ %83, %77 ]
%86 = or i64 %72, 1
%87 = getelementptr inbounds i8, i8* %0, i64 %86
%88 = load i8, i8* %87
%89 = icmp ult i8 %88, 4
br i1 %89, label %90, label %97
90: ; preds = %84
%91 = zext i8 %88 to i64
%92 = getelementptr inbounds [5 x double], [5 x double]* %3, i64 0, i64 %91
%93 = load double, double* %92
%94 = fadd double %93, 1.000000e+00
store double %94, double* %92
%95 = load double, double* %11
%96 = fadd double %95, 1.000000e+00
store double %96, double* %11
br label %97
97: ; preds = %90, %84
%98 = phi double [ %85, %84 ], [ %96, %90 ]
%99 = add nuw nsw i64 %72, 2
%100 = add i64 %73, 2
%101 = icmp eq i64 %100, %16
br i1 %101, label %17, label %70
}