#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 disk_readsect(int, int, char *);
int disk_readsects(int id, int lba, int count, void *buf) {
  int i, err;
  for (i = 0; i < count; i++) {
    if (err = disk_readsect(id, lba + i, &((char *)buf)[i * 512]))
      return err;
  }
  return 0;
}


x86 assembly (clang, -O0):
<disk_readsects>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    117f <disk_readsects+0x6f>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
add    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%eax
shl    $0x9,%eax
cltq
add    %rax,%rdx
call   1030 <disk_readsect@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     116c <disk_readsects+0x5c>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1186 <disk_readsects+0x76>
jmp    1171 <disk_readsects+0x61>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112c <disk_readsects+0x1c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disk_readsects>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r14d,%r14d
test   %edx,%edx
jle    1156 <disk_readsects+0x46>
mov    %rcx,%rbx
mov    %esi,%ebp
mov    %edi,%r15d
mov    %edx,%r12d
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1030 <disk_readsect@plt>
test   %eax,%eax
jne    1153 <disk_readsects+0x43>
add    $0x1,%ebp
add    $0x200,%rbx
add    $0xffffffffffffffff,%r12
jne    1130 <disk_readsects+0x20>
jmp    1156 <disk_readsects+0x46>
mov    %eax,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @disk_readsects(i32 %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 0, i32* %10
br label %12
12: ; preds = %31, %4
%13 = load i32, i32* %10
%14 = load i32, i32* %8
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = load i32, i32* %10
%20 = add nsw i32 %18, %19
%21 = load i8*, i8** %9
%22 = load i32, i32* %10
%23 = mul nsw i32 %22, 512
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = call i32 @disk_readsect(i32 %17, i32 %20, i8* %25)
store i32 %26, i32* %11
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %16
%29 = load i32, i32* %11
store i32 %29, i32* %5
br label %35
30: ; preds = %16
br label %31
31: ; preds = %30
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %10
br label %12
34: ; preds = %12
store i32 0, i32* %5
br label %35
35: ; preds = %34, %28
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
define i32 @disk_readsects(i32 %0, i32 %1, i32 %2, i8* %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %19
6: ; preds = %4
%7 = zext i32 %2 to i64
br label %10
8: ; preds = %10
%9 = icmp eq i64 %18, %7
br i1 %9, label %19, label %10
10: ; preds = %6, %8
%11 = phi i64 [ 0, %6 ], [ %18, %8 ]
%12 = shl nsw i64 %11, 9
%13 = getelementptr inbounds i8, i8* %3, i64 %12
%14 = trunc i64 %11 to i32
%15 = add i32 %14, %1
%16 = tail call i32 @disk_readsect(i32 %0, i32 %15, i8* %13)
%17 = icmp eq i32 %16, 0
%18 = add nuw nsw i64 %11, 1
br i1 %17, label %8, label %19
19: ; preds = %10, %8, %4
%20 = phi i32 [ 0, %4 ], [ 0, %8 ], [ %16, %10 ]
ret i32 %20
}