#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 */
typedef scalar_t__ uint32_t;
struct dvd_reader_s {
  int dummy;
};

/* Variables and functions */
int UDFReadBlocksRaw(struct dvd_reader_s *, scalar_t__, size_t, unsigned char *,
                     int);
int DVDReadLBUDF(struct dvd_reader_s *device, uint32_t lb_number,
                 size_t block_count, unsigned char *data, int encrypted) {
  int ret;
  size_t count = block_count;
  while (count > 0) {
    ret = UDFReadBlocksRaw(device, lb_number, count, data, encrypted);
    if (ret <= 0) {
      return ret;
    }
    count -= (size_t)ret;
    lb_number += (uint32_t)ret;
  }
  return block_count;
}


x86 assembly (clang, -O0):
<DVDReadLBUDF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jbe    1190 <DVDReadLBUDF+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
call   1030 <UDFReadBlocksRaw@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jg     1170 <DVDReadLBUDF+0x60>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1197 <DVDReadLBUDF+0x87>
movslq -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
movslq -0x30(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1134 <DVDReadLBUDF+0x24>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DVDReadLBUDF>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
test   %rdx,%rdx
je     1167 <DVDReadLBUDF+0x57>
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %rsi,%rbp
mov    %rdi,%r13
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15d,%r8d
call   1030 <UDFReadBlocksRaw@plt>
test   %eax,%eax
jle    1164 <DVDReadLBUDF+0x54>
mov    %eax,%eax
add    %rax,%rbp
sub    %rax,%rbx
jne    1140 <DVDReadLBUDF+0x30>
jmp    1167 <DVDReadLBUDF+0x57>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dvd_reader_s = type { i32 }
define i32 @DVDReadLBUDF(%struct.dvd_reader_s* %0, i64 %1, i64 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.dvd_reader_s*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
store %struct.dvd_reader_s* %0, %struct.dvd_reader_s** %7
store i64 %1, i64* %8
store i64 %2, i64* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%14 = load i64, i64* %9
store i64 %14, i64* %13
br label %15
15: ; preds = %29, %5
%16 = load i64, i64* %13
%17 = icmp ugt i64 %16, 0
br i1 %17, label %18, label %38
18: ; preds = %15
%19 = load %struct.dvd_reader_s*, %struct.dvd_reader_s** %7
%20 = load i64, i64* %8
%21 = load i64, i64* %13
%22 = load i8*, i8** %10
%23 = load i32, i32* %11
%24 = call i32 @UDFReadBlocksRaw(%struct.dvd_reader_s* %19, i64 %20, i64 %21, i8* %22, i32 %23)
store i32 %24, i32* %12
%25 = load i32, i32* %12
%26 = icmp sle i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %18
%28 = load i32, i32* %12
store i32 %28, i32* %6
br label %41
29: ; preds = %18
%30 = load i32, i32* %12
%31 = sext i32 %30 to i64
%32 = load i64, i64* %13
%33 = sub i64 %32, %31
store i64 %33, i64* %13
%34 = load i32, i32* %12
%35 = sext i32 %34 to i64
%36 = load i64, i64* %8
%37 = add nsw i64 %36, %35
store i64 %37, i64* %8
br label %15
38: ; preds = %15
%39 = load i64, i64* %9
%40 = trunc i64 %39 to i32
store i32 %40, i32* %6
br label %41
41: ; preds = %38, %27
%42 = load i32, i32* %6
ret i32 %42
}

LLVM IR (-O2):
%struct.dvd_reader_s = type { i32 }
define i32 @DVDReadLBUDF(%struct.dvd_reader_s* %0, i64 %1, i64 %2, i8* %3, i32 %4) {
%6 = icmp eq i64 %2, 0
br i1 %6, label %17, label %7
7: ; preds = %5, %12
%8 = phi i64 [ %14, %12 ], [ %2, %5 ]
%9 = phi i64 [ %15, %12 ], [ %1, %5 ]
%10 = tail call i32 @UDFReadBlocksRaw(%struct.dvd_reader_s* %0, i64 %9, i64 %8, i8* %3, i32 %4)
%11 = icmp slt i32 %10, 1
br i1 %11, label %19, label %12
12: ; preds = %7
%13 = zext i32 %10 to i64
%14 = sub i64 %8, %13
%15 = add nsw i64 %9, %13
%16 = icmp eq i64 %14, 0
br i1 %16, label %17, label %7
17: ; preds = %12, %5
%18 = trunc i64 %2 to i32
br label %19
19: ; preds = %7, %17
%20 = phi i32 [ %18, %17 ], [ %10, %7 ]
ret i32 %20
}