#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*/ uint8_t;
typedef int uint64_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int random_number(int);
uint64_t fill_buffer(void *buf, size_t size, uint64_t offset) {
  const int num_int64 = (512) >> 3;
  uint8_t *p, *ptr_end;
  assert(size > 0);
  assert(size % (512) == 0);
  p = buf;
  ptr_end = p + size;
  while (p < ptr_end) {
    uint64_t *sector = (uint64_t *)p;
    int i;
    sector[0] = offset;
    for (i = 1; i < num_int64; i++)
      sector[i] = random_number(sector[i - 1]);
    p += (512);
    offset += (512);
  }
  return offset;
}


x86 assembly (clang, -O0):
<fill_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x40,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
and    $0x1ff,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1200 <fill_buffer+0xe0>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x34(%rbp)
cmpl   $0x40,-0x34(%rbp)
jge    11e2 <fill_buffer+0xc2>
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <random_number@plt>
mov    %eax,%edx
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a8 <fill_buffer+0x88>
mov    -0x20(%rbp),%rax
add    $0x800,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x200,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <fill_buffer+0x62>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_buffer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   $0x1ff,%r14d
sete   %dil
call   1040 <assert@plt>
lea    (%rbx,%r14,4),%r14
cmp    %rbx,%r14
jbe    1197 <fill_buffer+0x77>
nopl   0x0(%rax)
mov    %r15d,(%rbx)
mov    $0x1,%ebp
mov    %r15d,%eax
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1030 <random_number@plt>
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    $0x40,%rbp
jne    1170 <fill_buffer+0x50>
add    $0x800,%rbx
add    $0x200,%r15d
cmp    %r14,%rbx
jb     1160 <fill_buffer+0x40>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fill_buffer(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
store i32 64, i32* %7
%12 = load i64, i64* %5
%13 = icmp ugt i64 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i64, i64* %5
%17 = urem i64 %16, 512
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %4
%22 = bitcast i8* %21 to i32*
store i32* %22, i32** %8
%23 = load i32*, i32** %8
%24 = load i64, i64* %5
%25 = getelementptr inbounds i32, i32* %23, i64 %24
store i32* %25, i32** %9
br label %26
26: ; preds = %53, %3
%27 = load i32*, i32** %8
%28 = load i32*, i32** %9
%29 = icmp ult i32* %27, %28
br i1 %29, label %30, label %58
30: ; preds = %26
%31 = load i32*, i32** %8
store i32* %31, i32** %10
%32 = load i32, i32* %6
%33 = load i32*, i32** %10
%34 = getelementptr inbounds i32, i32* %33, i64 0
store i32 %32, i32* %34
store i32 1, i32* %11
br label %35
35: ; preds = %50, %30
%36 = load i32, i32* %11
%37 = icmp slt i32 %36, 64
br i1 %37, label %38, label %53
38: ; preds = %35
%39 = load i32*, i32** %10
%40 = load i32, i32* %11
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %39, i64 %42
%44 = load i32, i32* %43
%45 = call i32 @random_number(i32 %44)
%46 = load i32*, i32** %10
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
store i32 %45, i32* %49
br label %50
50: ; preds = %38
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %35
53: ; preds = %35
%54 = load i32*, i32** %8
%55 = getelementptr inbounds i32, i32* %54, i64 512
store i32* %55, i32** %8
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 512
store i32 %57, i32* %6
br label %26
58: ; preds = %26
%59 = load i32, i32* %6
ret i32 %59
}

LLVM IR (-O2):
define i32 @fill_buffer(i8* %0, i64 %1, i32 %2) {
%4 = icmp ne i64 %1, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = and i64 %1, 511
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = bitcast i8* %0 to i32*
%12 = getelementptr inbounds i32, i32* %11, i64 %1
%13 = icmp ugt i32* %12, %11
br i1 %13, label %14, label %28
14: ; preds = %3, %24
%15 = phi i32 [ %26, %24 ], [ %2, %3 ]
%16 = phi i32* [ %25, %24 ], [ %11, %3 ]
store i32 %15, i32* %16
br label %17
17: ; preds = %14, %17
%18 = phi i32 [ %15, %14 ], [ %20, %17 ]
%19 = phi i64 [ 1, %14 ], [ %22, %17 ]
%20 = tail call i32 @random_number(i32 %18)
%21 = getelementptr inbounds i32, i32* %16, i64 %19
store i32 %20, i32* %21
%22 = add nuw nsw i64 %19, 1
%23 = icmp eq i64 %22, 64
br i1 %23, label %24, label %17
24: ; preds = %17
%25 = getelementptr inbounds i32, i32* %16, i64 512
%26 = add nsw i32 %15, 512
%27 = icmp ult i32* %25, %12
br i1 %27, label %14, label %28
28: ; preds = %24, %3
%29 = phi i32 [ %2, %3 ], [ %26, %24 ]
ret i32 %29
}