#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 int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ libewf_verbose_print(char *);
int write(int, int /*<<< orphan*/ *, size_t);
ssize_t ewf_sectors_chunk_write(uint8_t *sectors_chunk, int file_descriptor,
                                size_t size) {
  ssize_t count;
  if (sectors_chunk == NULL) {
    libewf_verbose_print("ewf_sectors_chunk_write: invalid sectors_chunk.\n");
    return (-1);
  }
  count = write(file_descriptor, sectors_chunk, size);
  if (count < size) {
    return (-1);
  }
  return (count);
}


x86 assembly (clang, -O0):
<ewf_sectors_chunk_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1156 <ewf_sectors_chunk_write+0x36>
lea    0xebb(%rip),%rdi
call   1030 <libewf_verbose_print@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1189 <ewf_sectors_chunk_write+0x69>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <write@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1183 <ewf_sectors_chunk_write+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    1189 <ewf_sectors_chunk_write+0x69>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ewf_sectors_chunk_write>:
push   %rbx
test   %rdi,%rdi
je     1145 <ewf_sectors_chunk_write+0x25>
mov    %rdx,%rbx
mov    %rdi,%rax
mov    %esi,%edi
mov    %rax,%rsi
call   1040 <write@plt>
cltq
cmp    %rbx,%rax
mov    $0xffffffff,%ecx
cmovb  %ecx,%eax
pop    %rbx
ret
lea    0xeb4(%rip),%rdi
call   1030 <libewf_verbose_print@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [49 x i8] c"ewf_sectors_chunk_write: invalid sectors_chunk.\0A\00"
define i32 @ewf_sectors_chunk_write(i32* %0, i32 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i64 %2, i64* %7
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @libewf_verbose_print(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %25
13: ; preds = %3
%14 = load i32, i32* %6
%15 = load i32*, i32** %5
%16 = load i64, i64* %7
%17 = call i32 @write(i32 %14, i32* %15, i64 %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = load i64, i64* %7
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %13
store i32 -1, i32* %4
br label %25
23: ; preds = %13
%24 = load i32, i32* %8
store i32 %24, i32* %4
br label %25
25: ; preds = %23, %22, %11
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
@.str = [49 x i8] c"ewf_sectors_chunk_write: invalid sectors_chunk.\0A\00"
define i32 @ewf_sectors_chunk_write(i32* %0, i32 %1, i64 %2) {
%4 = icmp eq i32* %0, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @libewf_verbose_print(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %12
7: ; preds = %3
%8 = tail call i32 @write(i32 %1, i32* %0, i64 %2)
%9 = sext i32 %8 to i64
%10 = icmp ult i64 %9, %2
%11 = select i1 %10, i32 -1, i32 %8
br label %12
12: ; preds = %7, %5
%13 = phi i32 [ -1, %5 ], [ %11, %7 ]
ret i32 %13
}