#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*/ assert(int);
int rand();
int /*<<< orphan*/ srand(int);
void random_fill(long *arr, long n) {
  assert(n >= 0);
  static long seeded = 0;
  if (!seeded) {
    srand(4567);
    seeded = 1;
  }
  for (long i = 0; i < n; i++) {
    arr[i] = rand() % 100;
  }
}


x86 assembly (clang, -O0):
<random_fill>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,0x2ee6(%rip)
jne    1175 <random_fill+0x45>
mov    $0x11d7,%edi
call   1030 <srand@plt>
movq   $0x1,0x2ecb(%rip)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11ba <random_fill+0x8a>
mov    $0x0,%al
call   1050 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
movslq %edx,%rdx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    117d <random_fill+0x4d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_fill>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
shr    $0x3f,%rdi
xor    $0x1,%edi
call   1040 <assert@plt>
cmpb   $0x0,0x2eef(%rip)
jne    1164 <random_fill+0x34>
mov    $0x11d7,%edi
call   1030 <srand@plt>
movb   $0x1,0x2edc(%rip)
test   %r15,%r15
jle    11a1 <random_fill+0x71>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
cltq
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1170 <random_fill+0x40>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@random_fill.seeded = internal global i64 0
define void @random_fill(i64* %0, i64 %1) {
%3 = alloca i64*
%4 = alloca i64
%5 = alloca i64
store i64* %0, i64** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = icmp sge i64 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i64, i64* @random_fill.seeded
%11 = icmp ne i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @srand(i32 4567)
store i64 1, i64* @random_fill.seeded
br label %14
14: ; preds = %12, %2
store i64 0, i64* %5
br label %15
15: ; preds = %26, %14
%16 = load i64, i64* %5
%17 = load i64, i64* %4
%18 = icmp slt i64 %16, %17
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 100
%22 = sext i32 %21 to i64
%23 = load i64*, i64** %3
%24 = load i64, i64* %5
%25 = getelementptr inbounds i64, i64* %23, i64 %24
store i64 %22, i64* %25
br label %26
26: ; preds = %19
%27 = load i64, i64* %5
%28 = add nsw i64 %27, 1
store i64 %28, i64* %5
br label %15
29: ; preds = %15
ret void
}

LLVM IR (-O2):
@random_fill.seeded = internal unnamed_addr global i1 false
define void @random_fill(i64* nocapture writeonly %0, i64 %1) {
%3 = lshr i64 %1, 63
%4 = trunc i64 %3 to i32
%5 = xor i32 %4, 1
%6 = tail call i32 @assert(i32 %5)
%7 = load i1, i1* @random_fill.seeded
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @srand(i32 4567)
store i1 true, i1* @random_fill.seeded
br label %10
10: ; preds = %8, %2
%11 = icmp sgt i64 %1, 0
br i1 %11, label %13, label %12
12: ; preds = %13, %10
ret void
13: ; preds = %10, %13
%14 = phi i64 [ %19, %13 ], [ 0, %10 ]
%15 = tail call i32 (...) @rand()
%16 = srem i32 %15, 100
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i64, i64* %0, i64 %14
store i64 %17, i64* %18
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %1
br i1 %20, label %12, label %13
}