#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();
void jlibc_arrayutil_randomize_int(int *array, int len) {
  int numbers[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  int primes[] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29,
                  31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
  while (len-- > 0) {
    int first = numbers[rand() % 10];
    int second = primes[rand() % 20];
    int third = rand() % 6 + 1;
    if (rand() % 2 == 0) {
      *array++ = (second - first) * third;
    } else {
      *array++ = (first + second) * third;
    }
  }
}


x86 assembly (clang, -O0):
<jlibc_arrayutil_randomize_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xec3(%rip),%rsi
mov    $0x28,%edx
call   1030 <memcpy@plt>
lea    -0x90(%rbp),%rdi
lea    0xedb(%rip),%rsi
mov    $0x50,%edx
call   1030 <memcpy@plt>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    1230 <jlibc_arrayutil_randomize_int+0x110>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x40(%rbp,%rax,4),%eax
mov    %eax,-0x94(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x14,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x90(%rbp,%rax,4),%eax
mov    %eax,-0x98(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x6,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x9c(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1207 <jlibc_arrayutil_randomize_int+0xe7>
mov    -0x98(%rbp),%ecx
sub    -0x94(%rbp),%ecx
imul   -0x9c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
jmp    122b <jlibc_arrayutil_randomize_int+0x10b>
mov    -0x94(%rbp),%ecx
add    -0x98(%rbp),%ecx
imul   -0x9c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x8(%rbp)
mov    %ecx,(%rax)
jmp    115f <jlibc_arrayutil_randomize_int+0x3f>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jlibc_arrayutil_randomize_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11f6 <jlibc_arrayutil_randomize_int+0xe6>
mov    %esi,%ebx
mov    %rdi,%r14
add    $0x1,%ebx
jmp    115a <jlibc_arrayutil_randomize_int+0x4a>
nopl   (%rax)
movslq %r12d,%rax
lea    (%r15,%r13,1),%ecx
add    $0x1,%ecx
lea    0xeef(%rip),%rdx
add    (%rdx,%rax,4),%ebp
imul   %ecx,%ebp
mov    %ebp,(%r14)
add    $0x4,%r14
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
jbe    11f6 <jlibc_arrayutil_randomize_int+0xe6>
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x2,%ecx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
cltq
lea    0xe76(%rip),%rcx
mov    (%rcx,%rax,4),%ebp
xor    %eax,%eax
call   1030 <rand@plt>
movslq %eax,%r12
imul   $0x66666667,%r12,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
sar    $0x3,%eax
add    %ecx,%eax
shl    $0x2,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r12d
xor    %eax,%eax
call   1030 <rand@plt>
mov    %eax,%r15d
cltq
imul   $0x2aaaaaab,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,2),%r13d
neg    %r13d
xor    %eax,%eax
call   1030 <rand@plt>
test   $0x1,%al
jne    1130 <jlibc_arrayutil_randomize_int+0x20>
neg    %ebp
jmp    1130 <jlibc_arrayutil_randomize_int+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@__const.jlibc_arrayutil_randomize_int.numbers = [10 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9]
@__const.jlibc_arrayutil_randomize_int.primes = [20 x i32] [i32 2, i32 3, i32 5, i32 7, i32 11, i32 13, i32 17, i32 19, i32 23, i32 29, i32 31, i32 37, i32 41, i32 43, i32 47, i32 53, i32 59, i32 61, i32 67, i32 71]
define void @jlibc_arrayutil_randomize_int(i32* nocapture writeonly %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %30
4: ; preds = %2, %4
%5 = phi i32* [ %27, %4 ], [ %0, %2 ]
%6 = phi i32 [ %7, %4 ], [ %1, %2 ]
%7 = add nsw i32 %6, -1
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 10
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [10 x i32], [10 x i32]* @__const.jlibc_arrayutil_randomize_int.numbers, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = tail call i32 (...) @rand()
%14 = srem i32 %13, 20
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [20 x i32], [20 x i32]* @__const.jlibc_arrayutil_randomize_int.primes, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = tail call i32 (...) @rand()
%19 = srem i32 %18, 6
%20 = add nsw i32 %19, 1
%21 = tail call i32 (...) @rand()
%22 = and i32 %21, 1
%23 = icmp eq i32 %22, 0
%24 = sub i32 0, %12
%25 = select i1 %23, i32 %24, i32 %12
%26 = add i32 %25, %17
%27 = getelementptr inbounds i32, i32* %5, i64 1
%28 = mul nsw i32 %26, %20
store i32 %28, i32* %5
%29 = icmp ugt i32 %6, 1
br i1 %29, label %4, label %30
30: ; preds = %4, %2
ret void
}