#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 checkDisk3(void) {
  int errors;
  int seed;
  unsigned int *p;
  int i, j;
  printf("\nDisk sector buffer read/write\n");
  errors = 0;
  srand(321);
  for (i = 0; i < 500; i++) {
    seed = rand();
    srand(seed);
    p = ((unsigned *)0xF0480000);
    for (j = 0; j < (512 / sizeof(unsigned int)); j++) {
      *p++ = rand();
    }
    srand(seed);
    p = ((unsigned *)0xF0480000);
    for (j = 0; j < (512 / sizeof(unsigned int)); j++) {
      if (*p++ != rand()) {
        errors++;
        break;
      }
    }
  }
  printf("%d errors in %d sectors\n", errors, 500);
}


x86 assembly (clang, -O0):
<checkDisk3>:
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   $0x1f4,-0x14(%rbp)
jge    124d <checkDisk3+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    $0x80,%rax
jae    11c5 <checkDisk3+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 <checkDisk3+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    $0x80,%rax
jae    123a <checkDisk3+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 <checkDisk3+0xf7>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    123a <checkDisk3+0x10a>
jmp    122c <checkDisk3+0xfc>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11dd <checkDisk3+0xad>
jmp    123f <checkDisk3+0x10f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <checkDisk3+0x2e>
mov    -0x4(%rbp),%esi
lea    0xdc9(%rip),%rdi
mov    $0x1f4,%edx
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkDisk3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xf0480000,%r13d
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x141,%edi
call   1050 <srand@plt>
xor    %r12d,%r12d
xor    %r14d,%r14d
jmp    1181 <checkDisk3+0x41>
nop
add    $0x1,%r14d
add    $0x1,%r12d
cmp    $0x1f4,%r12d
je     11ef <checkDisk3+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    $0x80,%ebx
jne    11a0 <checkDisk3+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 <checkDisk3+0x30>
add    $0x1,%rbx
cmp    $0x80,%ebx
jne    11d0 <checkDisk3+0x90>
jmp    1174 <checkDisk3+0x34>
lea    0xe0a(%rip),%rdi
mov    %r14d,%esi
mov    $0x1f4,%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 = [32 x i8] c"\0ADisk sector buffer read/write\0A\00"
@.str.1 = [25 x i8] c"%d errors in %d sectors\0A\00"
define void @checkDisk3() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 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, 500
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, 128
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, 128
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 ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %55, i32 500)
ret void
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"%d errors in %d sectors\0A\00"
@str = [31 x i8] c"\0ADisk sector buffer read/write\00"
define void @checkDisk3() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 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, 128
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, 128
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, 500
br i1 %38, label %39, label %3
39: ; preds = %35
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %36, i32 500)
ret void
}