#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*/ block_read(unsigned int, unsigned char *);
int /*<<< orphan*/ block_write(unsigned int, unsigned char *);
int /*<<< orphan*/ data_check(unsigned char *, unsigned char *);
int /*<<< orphan*/ data_fill(unsigned char *, unsigned char, unsigned char);
int /*<<< orphan*/ printf(char *, ...);
void fill_blocks(unsigned blocknum, unsigned char pattern) {
  unsigned char data[1024];
  unsigned char rdata[1024];
  unsigned bn;
  printf("Testing blocks 0-%u with byte value %02X.\n", blocknum, pattern);
  for (bn = 0; bn <= blocknum; bn++) {
    data_fill(data, pattern, pattern);
    block_write(bn, data);
    block_read(bn, rdata);
    data_check(data, rdata);
    if (bn == blocknum)
      break;
  }
  printf("Done.\n");
}


x86 assembly (clang, -O0):
<fill_blocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    -0x4(%rbp),%esi
movzbl -0x5(%rbp),%edx
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x814(%rbp)
mov    -0x814(%rbp),%eax
cmp    -0x4(%rbp),%eax
ja     120c <fill_blocks+0xbc>
lea    -0x410(%rbp),%rdi
mov    -0x5(%rbp),%al
movzbl %al,%esi
movzbl -0x5(%rbp),%edx
call   1030 <data_fill@plt>
mov    -0x814(%rbp),%edi
lea    -0x410(%rbp),%rsi
call   1060 <block_write@plt>
mov    -0x814(%rbp),%edi
lea    -0x810(%rbp),%rsi
call   1070 <block_read@plt>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1040 <data_check@plt>
mov    -0x814(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11f3 <fill_blocks+0xa3>
jmp    120c <fill_blocks+0xbc>
jmp    11f8 <fill_blocks+0xa8>
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    1183 <fill_blocks+0x33>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_blocks>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %esi,%ebx
mov    %edi,%r14d
lea    0xe85(%rip),%rdi
xor    %ebp,%ebp
mov    %r14d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
movzbl %bl,%ebx
lea    0x400(%rsp),%r15
mov    %rsp,%r12
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
call   1030 <data_fill@plt>
mov    %ebp,%edi
mov    %r15,%rsi
call   1070 <block_write@plt>
mov    %ebp,%edi
mov    %r12,%rsi
call   1080 <block_read@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <data_check@plt>
cmp    %ebp,%r14d
je     11d8 <fill_blocks+0x78>
add    $0x1,%ebp
cmp    %r14d,%ebp
jbe    11a0 <fill_blocks+0x40>
lea    0xe4c(%rip),%rdi
call   1040 <puts@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Testing blocks 0-%u with byte value %02X.\0A\00"
@.str.1 = [7 x i8] c"Done.\0A\00"
define void @fill_blocks(i32 %0, i8 zeroext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32
store i32 %0, i32* %3
store i8 %1, i8* %4
%8 = load i32, i32* %3
%9 = load i8, i8* %4
%10 = zext i8 %9 to i32
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %10)
store i32 0, i32* %7
br label %12
12: ; preds = %35, %2
%13 = load i32, i32* %7
%14 = load i32, i32* %3
%15 = icmp ule i32 %13, %14
br i1 %15, label %16, label %38
16: ; preds = %12
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = load i8, i8* %4
%19 = load i8, i8* %4
%20 = call i32 @data_fill(i8* %17, i8 zeroext %18, i8 zeroext %19)
%21 = load i32, i32* %7
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%23 = call i32 @block_write(i32 %21, i8* %22)
%24 = load i32, i32* %7
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = call i32 @block_read(i32 %24, i8* %25)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = call i32 @data_check(i8* %27, i8* %28)
%30 = load i32, i32* %7
%31 = load i32, i32* %3
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %16
br label %38
34: ; preds = %16
br label %35
35: ; preds = %34
%36 = load i32, i32* %7
%37 = add i32 %36, 1
store i32 %37, i32* %7
br label %12
38: ; preds = %33, %12
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"Testing blocks 0-%u with byte value %02X.\0A\00"
@str = [6 x i8] c"Done.\00"
define void @fill_blocks(i32 %0, i8 zeroext %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = zext i8 %1 to i32
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %7)
br label %9
9: ; preds = %9, %2
%10 = phi i32 [ 0, %2 ], [ %16, %9 ]
%11 = call i32 @data_fill(i8* %5, i8 zeroext %1, i8 zeroext %1)
%12 = call i32 @block_write(i32 %10, i8* %5)
%13 = call i32 @block_read(i32 %10, i8* %6)
%14 = call i32 @data_check(i8* %5, i8* %6)
%15 = icmp eq i32 %10, %0
%16 = add i32 %10, 1
%17 = icmp ugt i32 %16, %0
%18 = or i1 %15, %17
br i1 %18, label %19, label %9
19: ; preds = %9
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
ret void
}