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

/* Variables and functions */
int /*<<< orphan*/ libewf_fatal_print(char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, size_t);
scalar_t__ realloc(void *, size_t);
uint8_t *ewf_sectors_chunk_realloc(uint8_t *sectors_chunk, size_t size) {
  size_t sectors_chunk_size = sizeof(uint8_t) * size;
  if (sectors_chunk == NULL) {
    libewf_fatal_print("ewf_sectors_chunk_realloc: invalid sectors_chunk\n");
  }
  sectors_chunk = (uint8_t *)realloc((void *)sectors_chunk, sectors_chunk_size);
  if (sectors_chunk == NULL) {
    libewf_fatal_print(
        "ewf_sectors_chunk_realloc: unable to allocate sectors_chunk\n");
  }
  memset(sectors_chunk, 0, sectors_chunk_size);
  return (sectors_chunk);
}


x86 assembly (clang, -O0):
<ewf_sectors_chunk_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1163 <ewf_sectors_chunk_realloc+0x33>
lea    0xea2(%rip),%rdi
call   1030 <libewf_fatal_print@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118b <ewf_sectors_chunk_realloc+0x5b>
lea    0xeac(%rip),%rdi
call   1030 <libewf_fatal_print@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ewf_sectors_chunk_realloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
shl    $0x2,%r14
test   %rdi,%rdi
jne    114f <ewf_sectors_chunk_realloc+0x1f>
lea    0xeb6(%rip),%rdi
call   1030 <libewf_fatal_print@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116e <ewf_sectors_chunk_realloc+0x3e>
lea    0xec9(%rip),%rdi
call   1030 <libewf_fatal_print@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <memset@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [50 x i8] c"ewf_sectors_chunk_realloc: invalid sectors_chunk\0A\00"
@.str.1 = [61 x i8] c"ewf_sectors_chunk_realloc: unable to allocate sectors_chunk\0A\00"
define i32* @ewf_sectors_chunk_realloc(i32* %0, i64 %1) {
%3 = shl i64 %1, 2
%4 = icmp eq i32* %0, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @libewf_fatal_print(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
%8 = bitcast i32* %0 to i8*
%9 = tail call i64 @realloc(i8* %8, i64 %3)
%10 = inttoptr i64 %9 to i32*
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @libewf_fatal_print(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %7
%15 = tail call i32 @memset(i32* %10, i32 0, i64 %3)
ret i32* %10
}