#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 BMK_rand(unsigned int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, double);
int /*<<< orphan*/ stderr;
void BMK_genData(void *buffer, size_t buffSize, double p) {
  char table[2048] = {0};
  int remaining = 2048;
  unsigned pos = 0;
  unsigned s = 0;
  char *op = (char *)buffer;
  char *oend = op + buffSize;
  unsigned seed = 1;
  static unsigned done = 0;
  if (p < 0.01)
    p = 0.005;
  if (p > 1.)
    p = 1.;
  if (!done) {
    done = 1;
    fprintf(stderr, "Generating %i KB with P=%.2f%%\n", (int)(buffSize >> 10),
            p * 100);
  }
  while (remaining) {
    unsigned n = (unsigned)(remaining * p);
    unsigned end;
    if (!n)
      n = 1;
    end = pos + n;
    while (pos < end)
      table[pos++] = (char)s;
    s++;
    if (s == 255)
      s = 0;
    remaining -= n;
  }
  while (op < oend) {
    const unsigned r = BMK_rand(&seed) & (2048 - 1);
    *op++ = table[r];
  }
}


x86 assembly (clang, -O0):
<BMK_genData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
movl   $0x800,-0x824(%rbp)
movl   $0x0,-0x828(%rbp)
movl   $0x0,-0x82c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x838(%rbp)
mov    -0x838(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x840(%rbp)
movl   $0x1,-0x844(%rbp)
movsd  0xe58(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11c0 <BMK_genData+0x90>
movsd  0xe4d(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe43(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e4 <BMK_genData+0xb4>
movsd  0xe31(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,0x2e51(%rip)
jne    1227 <BMK_genData+0xf7>
movl   $0x1,0x2e41(%rip)
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
shr    $0xa,%rax
mov    %eax,%edx
movsd  0xe02(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
lea    0xdfe(%rip),%rsi
call   1050 <fprintf@plt>
jmp    122c <BMK_genData+0xfc>
cmpl   $0x0,-0x824(%rbp)
je     12f9 <BMK_genData+0x1c9>
cvtsi2sdl -0x824(%rbp),%xmm0
ff
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,-0x848(%rbp)
cmpl   $0x0,-0x848(%rbp)
jne    126c <BMK_genData+0x13c>
movl   $0x1,-0x848(%rbp)
mov    -0x828(%rbp),%eax
add    -0x848(%rbp),%eax
mov    %eax,-0x84c(%rbp)
mov    -0x828(%rbp),%eax
cmp    -0x84c(%rbp),%eax
jae    12b7 <BMK_genData+0x187>
mov    -0x82c(%rbp),%eax
mov    %al,%cl
mov    -0x828(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x828(%rbp)
mov    %eax,%eax
mov    %cl,-0x820(%rbp,%rax,1)
jmp    127e <BMK_genData+0x14e>
mov    -0x82c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x82c(%rbp)
cmpl   $0xff,-0x82c(%rbp)
jne    12e0 <BMK_genData+0x1b0>
movl   $0x0,-0x82c(%rbp)
mov    -0x848(%rbp),%ecx
mov    -0x824(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x824(%rbp)
jmp    122c <BMK_genData+0xfc>
jmp    12fe <BMK_genData+0x1ce>
mov    -0x838(%rbp),%rax
cmp    -0x840(%rbp),%rax
jae    1352 <BMK_genData+0x222>
lea    -0x844(%rbp),%rdi
call   1030 <BMK_rand@plt>
and    $0x7ff,%eax
mov    %eax,-0x850(%rbp)
mov    -0x850(%rbp),%eax
mov    -0x820(%rbp,%rax,1),%cl
mov    -0x838(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x838(%rbp)
mov    %cl,(%rax)
jmp    12fe <BMK_genData+0x1ce>
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BMK_genData>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
movaps %xmm0,0x10(%rsp)
mov    %rsi,%rbx
mov    %rdi,%r13
lea    0x30(%rsp),%rdi
mov    $0x800,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x1,0xc(%rsp)
movapd 0x10(%rsp),%xmm2
movapd %xmm2,%xmm0
cmpltsd 0xe88(%rip),%xmm0
movsd  0xe88(%rip),%xmm1
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
movsd  0xe7c(%rip),%xmm1
minsd  %xmm0,%xmm1
cmpb   $0x1,0x2e9d(%rip)
movsd  %xmm1,0x10(%rsp)
je     11dc <BMK_genData+0xac>
movb   $0x1,0x2e8e(%rip)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rdx
shr    $0xa,%rdx
movsd  0xe52(%rip),%xmm0
mulsd  %xmm1,%xmm0
lea    0xe4f(%rip),%rsi
call   1050 <fprintf@plt>
movsd  0x10(%rsp),%xmm1
mov    %rbx,0x28(%rsp)
lea    (%rbx,%r13,1),%rax
mov    %rax,0x20(%rsp)
mov    $0x800,%ebx
mov    $0x1,%r14d
xor    %eax,%eax
xor    %ebp,%ebp
jmp    1233 <BMK_genData+0x103>
nopl   0x0(%rax,%rax,1)
mov    %eax,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x30,%rdi
mov    %r15d,%edx
mov    %ebp,%esi
call   1040 <memset@plt>
movsd  0x10(%rsp),%xmm1
add    $0x1,%ebp
cmp    $0xff,%ebp
mov    $0x0,%eax
cmove  %eax,%ebp
mov    %r12d,%eax
sub    %r15d,%ebx
je     1258 <BMK_genData+0x128>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%r15
test   %r15d,%r15d
cmove  %r14d,%r15d
lea    (%r15,%rax,1),%r12d
cmp    %r12d,%eax
jb     1200 <BMK_genData+0xd0>
mov    %eax,%r12d
jmp    121a <BMK_genData+0xea>
cmpq   $0x0,0x28(%rsp)
mov    0x20(%rsp),%rbx
jle    128f <BMK_genData+0x15f>
lea    0xc(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1030 <BMK_rand@plt>
and    $0x7ff,%eax
movzbl 0x30(%rsp,%rax,1),%eax
mov    %al,0x0(%r13)
add    $0x1,%r13
cmp    %rbx,%r13
jb     1270 <BMK_genData+0x140>
add    $0x838,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BMK_genData.done = internal global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Generating %i KB with P=%.2f%%\0A\00"
define void @BMK_genData(i8* %0, i64 %1, double %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca double
%7 = alloca [2048 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store double %2, double* %6
%17 = bitcast [2048 x i8]* %7 to i8*
store i32 2048, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%18 = load i8*, i8** %4
store i8* %18, i8** %11
%19 = load i8*, i8** %11
%20 = load i64, i64* %5
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8* %21, i8** %12
store i32 1, i32* %13
%22 = load double, double* %6
%23 = fcmp olt double %22, 1.000000e-02
br i1 %23, label %24, label %25
24: ; preds = %3
store double 5.000000e-03, double* %6
br label %25
25: ; preds = %24, %3
%26 = load double, double* %6
%27 = fcmp ogt double %26, 1.000000e+00
br i1 %27, label %28, label %29
28: ; preds = %25
store double 1.000000e+00, double* %6
br label %29
29: ; preds = %28, %25
%30 = load i32, i32* @BMK_genData.done
%31 = icmp ne i32 %30, 0
br i1 %31, label %40, label %32
32: ; preds = %29
store i32 1, i32* @BMK_genData.done
%33 = load i32, i32* @stderr
%34 = load i64, i64* %5
%35 = lshr i64 %34, 10
%36 = trunc i64 %35 to i32
%37 = load double, double* %6
%38 = fmul double %37, 1.000000e+02
%39 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %36, double %38)
br label %40
40: ; preds = %32, %29
br label %41
41: ; preds = %74, %40
%42 = load i32, i32* %8
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %78
44: ; preds = %41
%45 = load i32, i32* %8
%46 = sitofp i32 %45 to double
%47 = load double, double* %6
%48 = fmul double %46, %47
%49 = fptoui double %48 to i32
store i32 %49, i32* %14
%50 = load i32, i32* %14
%51 = icmp ne i32 %50, 0
br i1 %51, label %53, label %52
52: ; preds = %44
store i32 1, i32* %14
br label %53
53: ; preds = %52, %44
%54 = load i32, i32* %9
%55 = load i32, i32* %14
%56 = add i32 %54, %55
store i32 %56, i32* %15
br label %57
57: ; preds = %61, %53
%58 = load i32, i32* %9
%59 = load i32, i32* %15
%60 = icmp ult i32 %58, %59
br i1 %60, label %61, label %68
61: ; preds = %57
%62 = load i32, i32* %10
%63 = trunc i32 %62 to i8
%64 = load i32, i32* %9
%65 = add i32 %64, 1
store i32 %65, i32* %9
%66 = zext i32 %64 to i64
%67 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 %66
store i8 %63, i8* %67
br label %57
68: ; preds = %57
%69 = load i32, i32* %10
%70 = add i32 %69, 1
store i32 %70, i32* %10
%71 = load i32, i32* %10
%72 = icmp eq i32 %71, 255
br i1 %72, label %73, label %74
73: ; preds = %68
store i32 0, i32* %10
br label %74
74: ; preds = %73, %68
%75 = load i32, i32* %14
%76 = load i32, i32* %8
%77 = sub i32 %76, %75
store i32 %77, i32* %8
br label %41
78: ; preds = %41
br label %79
79: ; preds = %83, %78
%80 = load i8*, i8** %11
%81 = load i8*, i8** %12
%82 = icmp ult i8* %80, %81
br i1 %82, label %83, label %92
83: ; preds = %79
%84 = call i32 @BMK_rand(i32* %13)
%85 = and i32 %84, 2047
store i32 %85, i32* %16
%86 = load i32, i32* %16
%87 = zext i32 %86 to i64
%88 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 %87
%89 = load i8, i8* %88
%90 = load i8*, i8** %11
%91 = getelementptr inbounds i8, i8* %90, i32 1
store i8* %91, i8** %11
store i8 %89, i8* %90
br label %79
92: ; preds = %79
ret void
}

LLVM IR (-O2):
@BMK_genData.done = internal unnamed_addr global i1 false
@stderr = global i32 0
@.str = [32 x i8] c"Generating %i KB with P=%.2f%%\0A\00"
define void @BMK_genData(i8* writeonly %0, i64 %1, double %2) {
%4 = alloca [2048 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds i8, i8* %0, i64 %1
%8 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%9 = fcmp olt double %2, 1.000000e-02
%10 = select i1 %9, double 5.000000e-03, double %2
%11 = fcmp ogt double %10, 1.000000e+00
%12 = select i1 %11, double 1.000000e+00, double %10
%13 = load i1, i1* @BMK_genData.done
br i1 %13, label %14, label %15
14: ; preds = %15, %3
br label %23
15: ; preds = %3
store i1 true, i1* @BMK_genData.done
%16 = load i32, i32* @stderr
%17 = lshr i64 %1, 10
%18 = trunc i64 %17 to i32
%19 = fmul double %12, 1.000000e+02
%20 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %18, double %19)
br label %14
21: ; preds = %40
%22 = icmp sgt i64 %1, 0
br i1 %22, label %47, label %56
23: ; preds = %14, %40
%24 = phi i32 [ %45, %40 ], [ 2048, %14 ]
%25 = phi i32 [ %41, %40 ], [ 0, %14 ]
%26 = phi i32 [ %44, %40 ], [ 0, %14 ]
%27 = sitofp i32 %24 to double
%28 = fmul double %12, %27
%29 = fptoui double %28 to i32
%30 = icmp eq i32 %29, 0
%31 = select i1 %30, i32 1, i32 %29
%32 = add i32 %31, %25
%33 = icmp ult i32 %25, %32
br i1 %33, label %34, label %40
34: ; preds = %23
%35 = trunc i32 %26 to i8
%36 = zext i32 %25 to i64
%37 = getelementptr [2048 x i8], [2048 x i8]* %4, i64 0, i64 %36
%38 = zext i32 %31 to i64
%39 = add i32 %25, %31
br label %40
40: ; preds = %34, %23
%41 = phi i32 [ %25, %23 ], [ %39, %34 ]
%42 = add i32 %26, 1
%43 = icmp eq i32 %42, 255
%44 = select i1 %43, i32 0, i32 %42
%45 = sub i32 %24, %31
%46 = icmp eq i32 %45, 0
br i1 %46, label %21, label %23
47: ; preds = %21, %47
%48 = phi i8* [ %54, %47 ], [ %0, %21 ]
%49 = call i32 @BMK_rand(i32* %5)
%50 = and i32 %49, 2047
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = getelementptr inbounds i8, i8* %48, i64 1
store i8 %53, i8* %48
%55 = icmp ult i8* %54, %7
br i1 %55, label %47, label %56
56: ; preds = %47, %21
ret void
}