#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 int /*<<< orphan*/ uint8_t;
typedef scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ hdd_image_zero(int /*<<< orphan*/, scalar_t__, scalar_t__);
scalar_t__ hdd_sectors(int /*<<< orphan*/);
int hdd_image_zero_ex(uint8_t id, uint32_t sector, uint32_t count) {
  uint32_t transfer_sectors = count;
  uint32_t sectors = hdd_sectors(id);
  if ((sectors - sector) < transfer_sectors)
    transfer_sectors = sectors - sector;
  hdd_image_zero(id, sector, transfer_sectors);
  if (count != transfer_sectors)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<hdd_image_zero_ex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <hdd_sectors@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    1165 <hdd_image_zero_ex+0x45>
mov    -0x28(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <hdd_image_zero@plt>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     118f <hdd_image_zero_ex+0x6f>
movl   $0x1,-0x4(%rbp)
jmp    1196 <hdd_image_zero_ex+0x76>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hdd_image_zero_ex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%r15d
call   1040 <hdd_sectors@plt>
sub    %r14,%rax
xor    %ebp,%ebp
cmp    %rbx,%rax
setl   %bpl
cmovl  %rax,%rbx
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <hdd_image_zero@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hdd_image_zero_ex(i32 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32 %0, i32* %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%10 = load i64, i64* %7
store i64 %10, i64* %8
%11 = load i32, i32* %5
%12 = call i64 @hdd_sectors(i32 %11)
store i64 %12, i64* %9
%13 = load i64, i64* %9
%14 = load i64, i64* %6
%15 = sub nsw i64 %13, %14
%16 = load i64, i64* %8
%17 = icmp slt i64 %15, %16
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = load i64, i64* %9
%20 = load i64, i64* %6
%21 = sub nsw i64 %19, %20
store i64 %21, i64* %8
br label %22
22: ; preds = %18, %3
%23 = load i32, i32* %5
%24 = load i64, i64* %6
%25 = load i64, i64* %8
%26 = call i32 @hdd_image_zero(i32 %23, i64 %24, i64 %25)
%27 = load i64, i64* %7
%28 = load i64, i64* %8
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %22
store i32 1, i32* %4
br label %32
31: ; preds = %22
store i32 0, i32* %4
br label %32
32: ; preds = %31, %30
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @hdd_image_zero_ex(i32 %0, i64 %1, i64 %2) {
%4 = tail call i64 @hdd_sectors(i32 %0)
%5 = sub nsw i64 %4, %1
%6 = icmp slt i64 %5, %2
%7 = select i1 %6, i64 %5, i64 %2
%8 = tail call i32 @hdd_image_zero(i32 %0, i64 %1, i64 %7)
%9 = zext i1 %6 to i32
ret i32 %9
}