#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 /*<<< orphan*/ free(char *);
char *malloc(size_t);
int /*<<< orphan*/ passphrase_wipe(char *, size_t);
char *xrealloc(char *array, size_t cur_size, size_t new_size) {
  char *rc = malloc(new_size * sizeof(char));
  size_t i;
  if (rc)
    for (i = 0; i < cur_size; i++)
      *(rc + i) = *(array + i);
  passphrase_wipe(array, cur_size);
  free(array);
  return rc;
}


x86 assembly (clang, -O0):
<xrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
shl    $0x0,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a2 <xrealloc+0x72>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    119d <xrealloc+0x6d>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1168 <xrealloc+0x38>
jmp    11a2 <xrealloc+0x72>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <passphrase_wipe@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrealloc>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rdx,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     116e <xrealloc+0x2e>
test   %r15,%r15
je     116e <xrealloc+0x2e>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <passphrase_wipe@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define noalias i8* @xrealloc(i8* %0, i64 %1, i64 %2) {
%4 = tail call i8* @malloc(i64 %2)
%5 = icmp ne i8* %4, null
%6 = icmp ne i64 %1, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %9
8: ; preds = %3
br label %9
9: ; preds = %8, %3
%10 = tail call i32 @passphrase_wipe(i8* %0, i64 %1)
%11 = tail call i32 @free(i8* %0)
ret i8* %4
}