#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*/ BufRead(int, char *);
int /*<<< orphan*/ BufSync();
int /*<<< orphan*/ BufWrite(int, char *);
int /*<<< orphan*/ DevResetDiskAccessCount();
int /*<<< orphan*/ PrintBufInfo();
int /*<<< orphan*/ PrintDiskAccessCountInfo();
int /*<<< orphan*/ PrintDiskInfo(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
int testcase3() {
  int i;
  char pData[1024];
  DevResetDiskAccessCount();
  for (i = 10; i < 10 + (10) / 2; i++) {
    BufRead(i, pData);
    printf("read[%d]:%s ", i, (char *)pData);
    sprintf(pData, "[block %d]", i + 100);
    BufWrite(i, pData);
  }
  printf("\n----------------------------------\n");
  printf("========= BufSync() =========\n");
  BufSync();
  PrintBufInfo();
  PrintDiskInfo(0, 14);
  for (i = 15; i < 15 + (10) / 2; i++) {
    sprintf(pData, "[block %d]", i + 100);
    BufWrite(i, pData);
  }
  printf("========= BufSync() =========\n");
  BufSync();
  PrintBufInfo();
  PrintDiskInfo(0, 19);
  PrintDiskAccessCountInfo();
  return 1;
}


x86 assembly (clang, -O0):
<testcase3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    $0x0,%al
call   1070 <DevResetDiskAccessCount@plt>
movl   $0xa,-0x4(%rbp)
cmpl   $0xf,-0x4(%rbp)
jge    1210 <testcase3+0x80>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
call   10a0 <BufRead@plt>
mov    -0x4(%rbp),%esi
lea    -0x410(%rbp),%rdx
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x4(%rbp),%edx
add    $0x64,%edx
lea    0xe1f(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
call   1060 <BufWrite@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11a9 <testcase3+0x19>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <BufSync@plt>
mov    $0x0,%al
call   1040 <PrintBufInfo@plt>
xor    %edi,%edi
mov    $0xe,%esi
call   1080 <PrintDiskInfo@plt>
movl   $0xf,-0x4(%rbp)
cmpl   $0x14,-0x4(%rbp)
jge    128d <testcase3+0xfd>
lea    -0x410(%rbp),%rdi
mov    -0x4(%rbp),%edx
add    $0x64,%edx
lea    0xda2(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
call   1060 <BufWrite@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    124d <testcase3+0xbd>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <BufSync@plt>
mov    $0x0,%al
call   1040 <PrintBufInfo@plt>
xor    %edi,%edi
mov    $0x13,%esi
call   1080 <PrintDiskInfo@plt>
mov    $0x0,%al
call   1090 <PrintDiskAccessCountInfo@plt>
mov    $0x1,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testcase3>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
xor    %eax,%eax
call   1080 <DevResetDiskAccessCount@plt>
mov    %rsp,%rbx
mov    $0xa,%edi
mov    %rbx,%rsi
call   10b0 <BufRead@plt>
lea    0xe36(%rip),%r15
mov    %r15,%rdi
mov    $0xa,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe2a(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6e,%edx
call   10c0 <sprintf@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <BufWrite@plt>
mov    $0xb,%edi
mov    %rbx,%rsi
call   10b0 <BufRead@plt>
mov    %r15,%rdi
mov    $0xb,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x6f,%edx
call   10c0 <sprintf@plt>
mov    $0xb,%edi
mov    %rbx,%rsi
call   1070 <BufWrite@plt>
mov    $0xc,%edi
mov    %rbx,%rsi
call   10b0 <BufRead@plt>
mov    %r15,%rdi
mov    $0xc,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x70,%edx
call   10c0 <sprintf@plt>
mov    $0xc,%edi
mov    %rbx,%rsi
call   1070 <BufWrite@plt>
mov    $0xd,%edi
mov    %rbx,%rsi
call   10b0 <BufRead@plt>
mov    %r15,%rdi
mov    $0xd,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x71,%edx
call   10c0 <sprintf@plt>
mov    $0xd,%edi
mov    %rbx,%rsi
call   1070 <BufWrite@plt>
mov    $0xe,%edi
mov    %rbx,%rsi
call   10b0 <BufRead@plt>
mov    %r15,%rdi
mov    $0xe,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x72,%edx
call   10c0 <sprintf@plt>
mov    $0xe,%edi
mov    %rbx,%rsi
call   1070 <BufWrite@plt>
lea    0xd21(%rip),%rdi
call   1040 <puts@plt>
lea    0xd39(%rip),%r15
mov    %r15,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1030 <BufSync@plt>
xor    %eax,%eax
call   1050 <PrintBufInfo@plt>
xor    %edi,%edi
mov    $0xe,%esi
call   1090 <PrintDiskInfo@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x73,%edx
call   10c0 <sprintf@plt>
mov    $0xf,%edi
mov    %rbx,%rsi
call   1070 <BufWrite@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x74,%edx
call   10c0 <sprintf@plt>
mov    $0x10,%edi
mov    %rbx,%rsi
call   1070 <BufWrite@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x75,%edx
call   10c0 <sprintf@plt>
mov    $0x11,%edi
mov    %rbx,%rsi
call   1070 <BufWrite@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x76,%edx
call   10c0 <sprintf@plt>
mov    $0x12,%edi
mov    %rbx,%rsi
call   1070 <BufWrite@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x77,%edx
call   10c0 <sprintf@plt>
mov    $0x13,%edi
mov    %rbx,%rsi
call   1070 <BufWrite@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1030 <BufSync@plt>
xor    %eax,%eax
call   1050 <PrintBufInfo@plt>
xor    %edi,%edi
mov    $0x13,%esi
call   1090 <PrintDiskInfo@plt>
xor    %eax,%eax
call   10a0 <PrintDiskAccessCountInfo@plt>
mov    $0x1,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"read[%d]:%s \00"
@.str.1 = [11 x i8] c"[block %d]\00"
@.str.2 = [37 x i8] c"\0A----------------------------------\0A\00"
@.str.3 = [31 x i8] c"========= BufSync() =========\0A\00"
define i32 @testcase3() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = call i32 (...) @DevResetDiskAccessCount()
store i32 10, i32* %1
br label %4
4: ; preds = %21, %0
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 15
br i1 %6, label %7, label %24
7: ; preds = %4
%8 = load i32, i32* %1
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%10 = call i32 @BufRead(i32 %8, i8* %9)
%11 = load i32, i32* %1
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%15 = load i32, i32* %1
%16 = add nsw i32 %15, 100
%17 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %1
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%20 = call i32 @BufWrite(i32 %18, i8* %19)
br label %21
21: ; preds = %7
%22 = load i32, i32* %1
%23 = add nsw i32 %22, 1
store i32 %23, i32* %1
br label %4
24: ; preds = %4
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 (...) @BufSync()
%28 = call i32 (...) @PrintBufInfo()
%29 = call i32 @PrintDiskInfo(i32 0, i32 14)
store i32 15, i32* %1
br label %30
30: ; preds = %41, %24
%31 = load i32, i32* %1
%32 = icmp slt i32 %31, 20
br i1 %32, label %33, label %44
33: ; preds = %30
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%35 = load i32, i32* %1
%36 = add nsw i32 %35, 100
%37 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %1
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%40 = call i32 @BufWrite(i32 %38, i8* %39)
br label %41
41: ; preds = %33
%42 = load i32, i32* %1
%43 = add nsw i32 %42, 1
store i32 %43, i32* %1
br label %30
44: ; preds = %30
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%46 = call i32 (...) @BufSync()
%47 = call i32 (...) @PrintBufInfo()
%48 = call i32 @PrintDiskInfo(i32 0, i32 19)
%49 = call i32 (...) @PrintDiskAccessCountInfo()
ret i32 1
}

LLVM IR (-O2):
@.str = [13 x i8] c"read[%d]:%s \00"
@.str.1 = [11 x i8] c"[block %d]\00"
@str = [36 x i8] c"\0A----------------------------------\00"
@str.5 = [30 x i8] c"========= BufSync() =========\00"
define i32 @testcase3() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @DevResetDiskAccessCount()
%4 = call i32 @BufRead(i32 10, i8* %2)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 10, i8* %2)
%6 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 110)
%7 = call i32 @BufWrite(i32 10, i8* %2)
%8 = call i32 @BufRead(i32 11, i8* %2)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 11, i8* %2)
%10 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 111)
%11 = call i32 @BufWrite(i32 11, i8* %2)
%12 = call i32 @BufRead(i32 12, i8* %2)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 12, i8* %2)
%14 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 112)
%15 = call i32 @BufWrite(i32 12, i8* %2)
%16 = call i32 @BufRead(i32 13, i8* %2)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 13, i8* %2)
%18 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 113)
%19 = call i32 @BufWrite(i32 13, i8* %2)
%20 = call i32 @BufRead(i32 14, i8* %2)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 14, i8* %2)
%22 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 114)
%23 = call i32 @BufWrite(i32 14, i8* %2)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.5, i64 0, i64 0))
%26 = call i32 (...) @BufSync()
%27 = call i32 (...) @PrintBufInfo()
%28 = call i32 @PrintDiskInfo(i32 0, i32 14)
%29 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 115)
%30 = call i32 @BufWrite(i32 15, i8* %2)
%31 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 116)
%32 = call i32 @BufWrite(i32 16, i8* %2)
%33 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 117)
%34 = call i32 @BufWrite(i32 17, i8* %2)
%35 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 118)
%36 = call i32 @BufWrite(i32 18, i8* %2)
%37 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 119)
%38 = call i32 @BufWrite(i32 19, i8* %2)
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.5, i64 0, i64 0))
%40 = call i32 (...) @BufSync()
%41 = call i32 (...) @PrintBufInfo()
%42 = call i32 @PrintDiskInfo(i32 0, i32 19)
%43 = call i32 (...) @PrintDiskAccessCountInfo()
ret i32 1
}