#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*/ advAddReallocMem(void *, int, void *);
void *advMalloc(int);
void *realloc(void *, int);
void *advRealloc(void *destinationAdr, int velikost) {
  void *tmpVar = NULL;
  if (destinationAdr == NULL) {
    destinationAdr = advMalloc(velikost);
    return destinationAdr;
  } else {
    tmpVar = realloc(destinationAdr, velikost);
    if (tmpVar != destinationAdr)
      advAddReallocMem(tmpVar, velikost, destinationAdr);
    return tmpVar;
  }
}


x86 assembly (clang, -O0):
<advRealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116b <advRealloc+0x3b>
mov    -0x14(%rbp),%edi
call   1040 <advMalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a1 <advRealloc+0x71>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1199 <advRealloc+0x69>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <advAddReallocMem@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<advRealloc>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
test   %rdi,%rdi
je     1168 <advRealloc+0x38>
mov    %rdi,%rbx
mov    %r14d,%esi
call   1050 <realloc@plt>
cmp    %rbx,%rax
je     1160 <advRealloc+0x30>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1030 <advAddReallocMem@plt>
mov    %rbp,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14d,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <advMalloc@plt>

LLVM IR (-O0):
define i8* @advRealloc(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* null, i8** %6
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* %5
%11 = call i8* @advMalloc(i32 %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %4
store i8* %12, i8** %3
br label %27
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = call i8* @realloc(i8* %14, i32 %15)
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = load i8*, i8** %4
%19 = icmp ne i8* %17, %18
br i1 %19, label %20, label %25
20: ; preds = %13
%21 = load i8*, i8** %6
%22 = load i32, i32* %5
%23 = load i8*, i8** %4
%24 = call i32 @advAddReallocMem(i8* %21, i32 %22, i8* %23)
br label %25
25: ; preds = %20, %13
%26 = load i8*, i8** %6
store i8* %26, i8** %3
br label %27
27: ; preds = %25, %9
%28 = load i8*, i8** %3
ret i8* %28
}

LLVM IR (-O2):
define i8* @advRealloc(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i8* @advMalloc(i32 %1)
br label %11
6: ; preds = %2
%7 = tail call i8* @realloc(i8* %0, i32 %1)
%8 = icmp eq i8* %7, %0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @advAddReallocMem(i8* %7, i32 %1, i8* %0)
br label %11
11: ; preds = %6, %9, %4
%12 = phi i8* [ %5, %4 ], [ %7, %9 ], [ %0, %6 ]
ret i8* %12
}