#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*/ printf(char *, ...);
void *rand();
int /*<<< orphan*/ srand(int);
void checkDisk5(void) {
  int errors;
  int seed;
  unsigned int *p;
  int i, j;
  printf("\nDisk block buffer read/write\n");
  errors = 0;
  srand(321);
  for (i = 0; i < 300; i++) {
    seed = rand();
    srand(seed);
    p = ((unsigned *)0xF0480000);
    for (j = 0; j < (4096 / sizeof(unsigned int)); j++) {
      *p++ = rand();
    }
    srand(seed);
    p = ((unsigned *)0xF0480000);
    for (j = 0; j < (4096 / sizeof(unsigned int)); j++) {
      if (*p++ != rand()) {
        errors++;
        break;
      }
    }
  }
  printf("%d errors in %d blocks\n", errors, 300);
}


x86 assembly (clang, -O0):
<checkDisk5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    $0x141,%edi
call   1040 <srand@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x12c,-0x14(%rbp)
jge    124d <checkDisk5+0x11d>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <srand@plt>
mov    $0xf0480000,%eax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x400,%rax
jae    11c5 <checkDisk5+0x95>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x10(%rbp)
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118d <checkDisk5+0x5d>
mov    -0x8(%rbp),%edi
call   1040 <srand@plt>
mov    $0xf0480000,%eax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0x400,%rax
jae    123a <checkDisk5+0x10a>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%eax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
je     1227 <checkDisk5+0xf7>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    123a <checkDisk5+0x10a>
jmp    122c <checkDisk5+0xfc>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11dd <checkDisk5+0xad>
jmp    123f <checkDisk5+0x10f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <checkDisk5+0x2e>
mov    -0x4(%rbp),%esi
lea    0xdc8(%rip),%rdi
mov    $0x12c,%edx
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkDisk5>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xf0480000,%r13d
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
mov    $0x141,%edi
call   1050 <srand@plt>
xor    %r12d,%r12d
xor    %r14d,%r14d
jmp    1181 <checkDisk5+0x41>
nop
add    $0x1,%r14d
add    $0x1,%r12d
cmp    $0x12c,%r12d
je     11ef <checkDisk5+0xaf>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %rax,%r15
mov    %r15d,%edi
call   1050 <srand@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,0x0(%r13,%rbx,4)
add    $0x1,%rbx
cmp    $0x400,%ebx
jne    11a0 <checkDisk5+0x60>
mov    %r15d,%edi
call   1050 <srand@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13,%rbx,4),%ebp
xor    %eax,%eax
call   1060 <rand@plt>
cmp    %rbp,%rax
jne    1170 <checkDisk5+0x30>
add    $0x1,%rbx
cmp    $0x400,%ebx
jne    11d0 <checkDisk5+0x90>
jmp    1174 <checkDisk5+0x34>
lea    0xe0a(%rip),%rdi
mov    %r14d,%esi
mov    $0x12c,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"\0ADisk block buffer read/write\0A\00"
@.str.1 = [24 x i8] c"%d errors in %d blocks\0A\00"
define void @checkDisk5() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
%7 = call i32 @srand(i32 321)
store i32 0, i32* %4
br label %8
8: ; preds = %51, %0
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 300
br i1 %10, label %11, label %54
11: ; preds = %8
%12 = call i8* (...) @rand()
%13 = ptrtoint i8* %12 to i32
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = call i32 @srand(i32 %14)
store i32* inttoptr (i64 4031250432 to i32*), i32** %3
store i32 0, i32* %5
br label %16
16: ; preds = %25, %11
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = icmp ult i64 %18, 1024
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = call i8* (...) @rand()
%22 = ptrtoint i8* %21 to i32
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i32 1
store i32* %24, i32** %3
store i32 %22, i32* %23
br label %25
25: ; preds = %20
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %16
28: ; preds = %16
%29 = load i32, i32* %2
%30 = call i32 @srand(i32 %29)
store i32* inttoptr (i64 4031250432 to i32*), i32** %3
store i32 0, i32* %5
br label %31
31: ; preds = %47, %28
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = icmp ult i64 %33, 1024
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = load i32*, i32** %3
%37 = getelementptr inbounds i32, i32* %36, i32 1
store i32* %37, i32** %3
%38 = load i32, i32* %36
%39 = zext i32 %38 to i64
%40 = inttoptr i64 %39 to i8*
%41 = call i8* (...) @rand()
%42 = icmp ne i8* %40, %41
br i1 %42, label %43, label %46
43: ; preds = %35
%44 = load i32, i32* %1
%45 = add nsw i32 %44, 1
store i32 %45, i32* %1
br label %50
46: ; preds = %35
br label %47
47: ; preds = %46
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %31
50: ; preds = %43, %31
br label %51
51: ; preds = %50
%52 = load i32, i32* %4
%53 = add nsw i32 %52, 1
store i32 %53, i32* %4
br label %8
54: ; preds = %8
%55 = load i32, i32* %1
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %55, i32 300)
ret void
}

LLVM IR (-O2):
@.str.1 = [24 x i8] c"%d errors in %d blocks\0A\00"
@str = [30 x i8] c"\0ADisk block buffer read/write\00"
define void @checkDisk5() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @srand(i32 321)
br label %3
3: ; preds = %0, %35
%4 = phi i32 [ 0, %0 ], [ %37, %35 ]
%5 = phi i32 [ 0, %0 ], [ %36, %35 ]
%6 = tail call i8* (...) @rand()
%7 = ptrtoint i8* %6 to i64
%8 = trunc i64 %7 to i32
%9 = tail call i32 @srand(i32 %8)
br label %10
10: ; preds = %3, %10
%11 = phi i32 [ 0, %3 ], [ %17, %10 ]
%12 = phi i32* [ inttoptr (i64 4031250432 to i32*), %3 ], [ %16, %10 ]
%13 = tail call i8* (...) @rand()
%14 = ptrtoint i8* %13 to i64
%15 = trunc i64 %14 to i32
%16 = getelementptr inbounds i32, i32* %12, i64 1
store i32 %15, i32* %12
%17 = add nuw nsw i32 %11, 1
%18 = icmp eq i32 %17, 1024
br i1 %18, label %19, label %10
19: ; preds = %10
%20 = tail call i32 @srand(i32 %8)
br label %21
21: ; preds = %19, %31
%22 = phi i32 [ 0, %19 ], [ %33, %31 ]
%23 = phi i32* [ inttoptr (i64 4031250432 to i32*), %19 ], [ %32, %31 ]
%24 = load i32, i32* %23
%25 = zext i32 %24 to i64
%26 = inttoptr i64 %25 to i8*
%27 = tail call i8* (...) @rand()
%28 = icmp eq i8* %27, %26
br i1 %28, label %31, label %29
29: ; preds = %21
%30 = add nsw i32 %5, 1
br label %35
31: ; preds = %21
%32 = getelementptr inbounds i32, i32* %23, i64 1
%33 = add nuw nsw i32 %22, 1
%34 = icmp eq i32 %33, 1024
br i1 %34, label %35, label %21
35: ; preds = %31, %29
%36 = phi i32 [ %30, %29 ], [ %5, %31 ]
%37 = add nuw nsw i32 %4, 1
%38 = icmp eq i32 %37, 300
br i1 %38, label %39, label %3
39: ; preds = %35
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %36, i32 300)
ret void
}