#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double Frequency(long, int);
double Runs(unsigned long *, unsigned long, int);
scalar_t__ count(unsigned int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned int);
int rand();
scalar_t__ sum(unsigned int, int);
void generator_rand_hi(FILE *file, unsigned int n, double result[2]) {
  unsigned int i;
  unsigned int r;
  unsigned long numOnes = 0;
  long convertedSum = 0;
  unsigned long tab[1024];
  for (i = 0; i < n; i++) {
    r = rand() >> 27;
    tab[i] = r;
    numOnes += count(r, 4);
    convertedSum += sum(r, 4);
    fprintf(file, "%u ", r);
  }
  result[0] = Frequency(convertedSum, 4);
  result[1] = Runs(tab, numOnes, 4);
}


x86 assembly (clang, -O0):
<generator_rand_hi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1201 <generator_rand_hi+0xa1>
mov    $0x0,%al
call   1080 <rand@plt>
sar    $0x1b,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
mov    %rcx,-0x2030(%rbp,%rax,8)
ff
mov    -0x20(%rbp),%edi
mov    $0x4,%esi
call   1030 <count@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%edi
mov    $0x4,%esi
call   1060 <sum@plt>
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xe12(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118d <generator_rand_hi+0x2d>
mov    -0x30(%rbp),%rdi
mov    $0x4,%esi
call   1070 <Frequency@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
lea    -0x2030(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1040 <Runs@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generator_rand_hi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2018,%rsp
mov    %rdx,0x8(%rsp)
test   %esi,%esi
je     11db <generator_rand_hi+0x7b>
mov    %rdi,%r15
mov    %esi,%r14d
xor    %r13d,%r13d
xor    %ebx,%ebx
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <rand@plt>
mov    %eax,%ebp
sar    $0x1b,%ebp
mov    %rbp,0x10(%rsp,%r13,8)
mov    %ebp,%edi
mov    $0x4,%esi
call   1030 <count@plt>
add    %rax,%r12
mov    %ebp,%edi
mov    $0x4,%esi
call   1060 <sum@plt>
add    %rax,%rbx
mov    %r15,%rdi
lea    0xe37(%rip),%rsi
mov    %ebp,%edx
call   1050 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%r14
jne    1190 <generator_rand_hi+0x30>
jmp    11e0 <generator_rand_hi+0x80>
xor    %r12d,%r12d
xor    %ebx,%ebx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1070 <Frequency@plt>
mov    0x8(%rsp),%rbx
movsd  %xmm0,(%rbx)
lea    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1040 <Runs@plt>
movsd  %xmm0,0x8(%rbx)
add    $0x2018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%u \00"
define void @generator_rand_hi(i32* %0, i32 %1, double* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca [1024 x i64]
store i32* %0, i32** %4
store i32 %1, i32* %5
store double* %2, double** %6
store i64 0, i64* %9
store i64 0, i64* %10
store i32 0, i32* %7
br label %12
12: ; preds = %35, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %5
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %38
16: ; preds = %12
%17 = call i32 (...) @rand()
%18 = ashr i32 %17, 27
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = zext i32 %19 to i64
%21 = load i32, i32* %7
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [1024 x i64], [1024 x i64]* %11, i64 0, i64 %22
store i64 %20, i64* %23
%24 = load i32, i32* %8
%25 = call i64 @count(i32 %24, i32 4)
%26 = load i64, i64* %9
%27 = add i64 %26, %25
store i64 %27, i64* %9
%28 = load i32, i32* %8
%29 = call i64 @sum(i32 %28, i32 4)
%30 = load i64, i64* %10
%31 = add nsw i64 %30, %29
store i64 %31, i64* %10
%32 = load i32*, i32** %4
%33 = load i32, i32* %8
%34 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %16
%36 = load i32, i32* %7
%37 = add i32 %36, 1
store i32 %37, i32* %7
br label %12
38: ; preds = %12
%39 = load i64, i64* %10
%40 = call double @Frequency(i64 %39, i32 4)
%41 = load double*, double** %6
%42 = getelementptr inbounds double, double* %41, i64 0
store double %40, double* %42
%43 = getelementptr inbounds [1024 x i64], [1024 x i64]* %11, i64 0, i64 0
%44 = load i64, i64* %9
%45 = call double @Runs(i64* %43, i64 %44, i32 4)
%46 = load double*, double** %6
%47 = getelementptr inbounds double, double* %46, i64 1
store double %45, double* %47
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%u \00"
define void @generator_rand_hi(i32* nocapture %0, i32 %1, double* nocapture writeonly %2) {
%4 = alloca [1024 x i64]
%5 = bitcast [1024 x i64]* %4 to i8*
%6 = icmp eq i32 %1, 0
br i1 %6, label %24, label %7
7: ; preds = %3
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %22, %9 ]
%11 = phi i64 [ 0, %7 ], [ %20, %9 ]
%12 = phi i64 [ 0, %7 ], [ %18, %9 ]
%13 = tail call i32 (...) @rand()
%14 = ashr i32 %13, 27
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [1024 x i64], [1024 x i64]* %4, i64 0, i64 %10
store i64 %15, i64* %16
%17 = tail call i64 @count(i32 %14, i32 4)
%18 = add i64 %17, %12
%19 = tail call i64 @sum(i32 %14, i32 4)
%20 = add nsw i64 %19, %11
%21 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
%22 = add nuw nsw i64 %10, 1
%23 = icmp eq i64 %22, %8
br i1 %23, label %24, label %9
24: ; preds = %9, %3
%25 = phi i64 [ 0, %3 ], [ %18, %9 ]
%26 = phi i64 [ 0, %3 ], [ %20, %9 ]
%27 = tail call double @Frequency(i64 %26, i32 4)
store double %27, double* %2
%28 = getelementptr inbounds [1024 x i64], [1024 x i64]* %4, i64 0, i64 0
%29 = call double @Runs(i64* %28, i64 %25, i32 4)
%30 = getelementptr inbounds double, double* %2, i64 1
store double %29, double* %30
ret void
}