#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*/ offset;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
long lrand48();
int /*<<< orphan*/ memmove(int /*<<< orphan*/ *, int *, int);
int /*<<< orphan*/ srand48(int);
uint64_t fill_buffer(void *buf, size_t size, uint64_t offset) {
  uint8_t *p, *ptr_next_sector, *ptr_end;
  assert(size % 512 == 0);
  p = buf;
  ptr_end = p + size;
  while (p < ptr_end) {
    memmove(p, &offset, sizeof(offset));
    srand48(offset);
    ptr_next_sector = p + 512;
    p += sizeof(offset);
    for (; p < ptr_next_sector; p += sizeof(long int))
      (*(long int *)p) = lrand48();
    assert(p == ptr_next_sector);
    offset += 512;
  }
  return offset;
}


x86 assembly (clang, -O0):
<fill_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
and    $0x1ff,%rax
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <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    1220 <fill_buffer+0xe0>
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1060 <memmove@plt>
mov    -0x14(%rbp),%edi
call   1050 <srand48@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    11fb <fill_buffer+0xbb>
mov    $0x0,%al
call   1040 <lrand48@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x20(%rbp)
jmp    11cb <fill_buffer+0x8b>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x14(%rbp),%eax
add    $0x200,%eax
mov    %eax,-0x14(%rbp)
jmp    1189 <fill_buffer+0x49>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,0xc(%rsp)
xor    %edi,%edi
test   $0x1ff,%r14d
sete   %dil
call   1030 <assert@plt>
lea    (%rbx,%r14,4),%r15
cmp    %rbx,%r15
jbe    11e2 <fill_buffer+0xa2>
lea    0xc(%rsp),%r14
mov    $0x200,%r12d
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1060 <memmove@plt>
mov    0xc(%rsp),%edi
call   1050 <srand48@plt>
add    $0x10,%rbx
mov    $0xfffffffffffffffc,%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <lrand48@plt>
mov    %rax,(%rbx)
add    $0x20,%rbx
add    $0x8,%rbp
cmp    $0x1f8,%rbp
jb     11b0 <fill_buffer+0x70>
xor    %edi,%edi
call   1030 <assert@plt>
mov    0xc(%rsp),%ebp
add    %r12d,%ebp
mov    %ebp,0xc(%rsp)
cmp    %r15,%rbx
jb     1180 <fill_buffer+0x40>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
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*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%10 = load i64, i64* %5
%11 = urem i64 %10, 512
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8*, i8** %4
%16 = bitcast i8* %15 to i32*
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = load i64, i64* %5
%19 = getelementptr inbounds i32, i32* %17, i64 %18
store i32* %19, i32** %9
br label %20
20: ; preds = %44, %3
%21 = load i32*, i32** %7
%22 = load i32*, i32** %9
%23 = icmp ult i32* %21, %22
br i1 %23, label %24, label %52
24: ; preds = %20
%25 = load i32*, i32** %7
%26 = call i32 @memmove(i32* %25, i32* %6, i32 4)
%27 = load i32, i32* %6
%28 = call i32 @srand48(i32 %27)
%29 = load i32*, i32** %7
%30 = getelementptr inbounds i32, i32* %29, i64 512
store i32* %30, i32** %8
%31 = load i32*, i32** %7
%32 = getelementptr inbounds i32, i32* %31, i64 4
store i32* %32, i32** %7
br label %33
33: ; preds = %41, %24
%34 = load i32*, i32** %7
%35 = load i32*, i32** %8
%36 = icmp ult i32* %34, %35
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = call i64 (...) @lrand48()
%39 = load i32*, i32** %7
%40 = bitcast i32* %39 to i64*
store i64 %38, i64* %40
br label %41
41: ; preds = %37
%42 = load i32*, i32** %7
%43 = getelementptr inbounds i32, i32* %42, i64 8
store i32* %43, i32** %7
br label %33
44: ; preds = %33
%45 = load i32*, i32** %7
%46 = load i32*, i32** %8
%47 = icmp eq i32* %45, %46
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 512
store i32 %51, i32* %6
br label %20
52: ; preds = %20
%53 = load i32, i32* %6
ret i32 %53
}

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