#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*/ posix_memalign(void **, int, int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int *generate_array(int n, int a, int b) {
  int i;
  int *res;
  posix_memalign((void **)&res, 32, sizeof(int) * n);
  srand(time(NULL));
  for (i = 0; i < n; i++)
    res[i] = rand() % (b - a + 1) + a;
  return res;
}


x86 assembly (clang, -O0):
<generate_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
mov    $0x20,%esi
call   1050 <posix_memalign@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11bb <generate_array+0x7b>
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0xc(%rbp),%ecx
sub    -0x8(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
add    -0x8(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1180 <generate_array+0x40>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_array>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r12d
mov    %esi,%r15d
mov    %edi,%r14d
lea    0x0(,%r14,4),%edx
lea    0x8(%rsp),%rdi
mov    $0x20,%esi
call   1050 <posix_memalign@plt>
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %r14d,%r14d
jle    11b1 <generate_array+0x71>
sub    %r15d,%r12d
add    $0x1,%r12d
mov    %r14d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
cltd
idiv   %r12d
add    %r15d,%edx
mov    0x8(%rsp),%rax
mov    %edx,(%rax,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <generate_array+0x50>
jmp    11b6 <generate_array+0x76>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @generate_array(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = bitcast i32** %8 to i8**
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = mul i64 4, %11
%13 = trunc i64 %12 to i32
%14 = call i32 @posix_memalign(i8** %9, i32 32, i32 %13)
%15 = call i32 @time(i32* null)
%16 = call i32 @srand(i32 %15)
store i32 0, i32* %7
br label %17
17: ; preds = %34, %3
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %37
21: ; preds = %17
%22 = call i32 (...) @rand()
%23 = load i32, i32* %6
%24 = load i32, i32* %5
%25 = sub nsw i32 %23, %24
%26 = add nsw i32 %25, 1
%27 = srem i32 %22, %26
%28 = load i32, i32* %5
%29 = add nsw i32 %27, %28
%30 = load i32*, i32** %8
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
store i32 %29, i32* %33
br label %34
34: ; preds = %21
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %17
37: ; preds = %17
%38 = load i32*, i32** %8
ret i32* %38
}

LLVM IR (-O2):
define i32* @generate_array(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = bitcast i32** %4 to i8*
%6 = bitcast i32** %4 to i8**
%7 = shl i32 %0, 2
%8 = call i32 @posix_memalign(i8** %6, i32 32, i32 %7)
%9 = call i32 @time(i32* null)
%10 = call i32 @srand(i32 %9)
%11 = icmp sgt i32 %0, 0
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = load i32*, i32** %4
br label %27
14: ; preds = %3
%15 = sub i32 1, %1
%16 = add i32 %15, %2
%17 = zext i32 %0 to i64
br label %18
18: ; preds = %14, %18
%19 = phi i64 [ 0, %14 ], [ %25, %18 ]
%20 = call i32 (...) @rand()
%21 = srem i32 %20, %16
%22 = add nsw i32 %21, %1
%23 = load i32*, i32** %4
%24 = getelementptr inbounds i32, i32* %23, i64 %19
store i32 %22, i32* %24
%25 = add nuw nsw i64 %19, 1
%26 = icmp eq i64 %25, %17
br i1 %26, label %27, label %18
27: ; preds = %18, %12
%28 = phi i32* [ %13, %12 ], [ %23, %18 ]
ret i32* %28
}