#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;
typedef int /*<<< orphan*/ rn;
typedef int /*<<< orphan*/ offset;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ memmove(int /*<<< orphan*/ *, int *, int);
int random_number(int);
uint64_t fill_buffer(void *buf, size_t size, uint64_t offset) {
  uint8_t *p, *ptr_next_sector, *ptr_end;
  uint64_t rn;
  assert(size > 0);
  assert(size % (512) == 0);
  assert((512) >= sizeof(offset) + sizeof(rn));
  assert(((512) - sizeof(offset)) % sizeof(rn) == 0);
  p = buf;
  ptr_end = p + size;
  while (p < ptr_end) {
    rn = offset;
    memmove(p, &offset, sizeof(offset));
    ptr_next_sector = p + (512);
    p += sizeof(offset);
    for (; p < ptr_next_sector; p += sizeof(rn)) {
      rn = random_number(rn);
      memmove(p, &rn, sizeof(rn));
    }
    assert(p == ptr_next_sector);
    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)
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    $0x1,%edi
call   1040 <assert@plt>
mov    $0x1,%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,-0x30(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1240 <fill_buffer+0x110>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <memmove@plt>
mov    -0x20(%rbp),%rax
add    $0x800,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    121b <fill_buffer+0xeb>
mov    -0x34(%rbp),%edi
call   1030 <random_number@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x34(%rbp),%rsi
mov    $0x4,%edx
call   1050 <memmove@plt>
mov    -0x20(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x20(%rbp)
jmp    11df <fill_buffer+0xaf>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x14(%rbp),%eax
add    $0x200,%eax
mov    %eax,-0x14(%rbp)
jmp    119f <fill_buffer+0x6f>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %edx,0x4(%rsp)
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   $0x1ff,%ebp
sete   %dil
call   1040 <assert@plt>
mov    $0x1,%edi
call   1040 <assert@plt>
mov    $0x1,%edi
call   1040 <assert@plt>
lea    (%rbx,%rbp,4),%r12
cmp    %rbx,%r12
jbe    11f8 <fill_buffer+0xc8>
mov    %rsp,%r14
mov    $0x200,%r13d
nopl   (%rax)
mov    %r15d,(%rsp)
mov    %rbx,%rdi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1050 <memmove@plt>
add    $0x10,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    (%rsp),%edi
call   1030 <random_number@plt>
mov    %eax,(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1050 <memmove@plt>
add    $0x10,%rbx
add    $0x4,%rbp
cmp    $0x1fc,%rbp
jb     11b0 <fill_buffer+0x80>
mov    $0x1,%edi
call   1040 <assert@plt>
mov    0x4(%rsp),%r15d
add    %r13d,%r15d
mov    %r15d,0x4(%rsp)
cmp    %r12,%rbx
jb     1190 <fill_buffer+0x60>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
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
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%11 = load i64, i64* %5
%12 = icmp ugt i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i64, i64* %5
%16 = urem i64 %15, 512
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = call i32 @assert(i32 1)
%21 = call i32 @assert(i32 1)
%22 = load i8*, i8** %4
%23 = bitcast i8* %22 to i32*
store i32* %23, i32** %7
%24 = load i32*, i32** %7
%25 = load i64, i64* %5
%26 = getelementptr inbounds i32, i32* %24, i64 %25
store i32* %26, i32** %9
br label %27
27: ; preds = %51, %3
%28 = load i32*, i32** %7
%29 = load i32*, i32** %9
%30 = icmp ult i32* %28, %29
br i1 %30, label %31, label %59
31: ; preds = %27
%32 = load i32, i32* %6
store i32 %32, i32* %10
%33 = load i32*, i32** %7
%34 = call i32 @memmove(i32* %33, i32* %6, i32 4)
%35 = load i32*, i32** %7
%36 = getelementptr inbounds i32, i32* %35, i64 512
store i32* %36, i32** %8
%37 = load i32*, i32** %7
%38 = getelementptr inbounds i32, i32* %37, i64 4
store i32* %38, i32** %7
br label %39
39: ; preds = %48, %31
%40 = load i32*, i32** %7
%41 = load i32*, i32** %8
%42 = icmp ult i32* %40, %41
br i1 %42, label %43, label %51
43: ; preds = %39
%44 = load i32, i32* %10
%45 = call i32 @random_number(i32 %44)
store i32 %45, i32* %10
%46 = load i32*, i32** %7
%47 = call i32 @memmove(i32* %46, i32* %10, i32 4)
br label %48
48: ; preds = %43
%49 = load i32*, i32** %7
%50 = getelementptr inbounds i32, i32* %49, i64 4
store i32* %50, i32** %7
br label %39
51: ; preds = %39
%52 = load i32*, i32** %7
%53 = load i32*, i32** %8
%54 = icmp eq i32* %52, %53
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
%57 = load i32, i32* %6
%58 = add nsw i32 %57, 512
store i32 %58, i32* %6
br label %27
59: ; preds = %27
%60 = load i32, i32* %6
ret i32 %60
}

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