#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*/ basis_free(void *);
void *basis_malloc(long);
int /*<<< orphan*/ memcpy(void *, void *, long);
int /*<<< orphan*/ nixtrace(char *);
int /*<<< orphan*/ printf(char *);
void *basis_realloc(void *palt, long newsize) {
  void *p;
  long oldsize;
  char *ph;
  nixtrace("Start basis_realloc");
  p = basis_malloc(newsize);
  if (p != NULL) {
    if (palt != NULL) {
      ph = palt;
      oldsize = *((long *)(ph - 16));
      if (oldsize != 0)
        memcpy(p, palt, oldsize);
      basis_free(palt);
    }
  } else
    printf("schrecklicher Fehler: realloc gescheitert!\n");
  nixtrace("Ende basis_realloc");
  return p;
}


x86 assembly (clang, -O0):
<basis_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe99(%rip),%rdi
call   1070 <nixtrace@plt>
mov    -0x10(%rbp),%rdi
call   1050 <basis_malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cd <basis_realloc+0x7d>
cmpq   $0x0,-0x8(%rbp)
je     11c8 <basis_realloc+0x78>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11bf <basis_realloc+0x6f>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
call   1060 <basis_free@plt>
jmp    11d9 <basis_realloc+0x89>
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
lea    0xe60(%rip),%rdi
call   1070 <nixtrace@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basis_realloc>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe9f(%rip),%rdi
call   1070 <nixtrace@plt>
mov    %rbx,%rdi
call   1050 <basis_malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1199 <basis_realloc+0x49>
test   %r14,%r14
je     11a5 <basis_realloc+0x55>
mov    -0x10(%r14),%rdx
test   %rdx,%rdx
je     118f <basis_realloc+0x3f>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
mov    %r14,%rdi
call   1060 <basis_free@plt>
jmp    11a5 <basis_realloc+0x55>
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
lea    0xe68(%rip),%rdi
call   1070 <nixtrace@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Start basis_realloc\00"
@.str.1 = [44 x i8] c"schrecklicher Fehler: realloc gescheitert!\0A\00"
@.str.2 = [19 x i8] c"Ende basis_realloc\00"
define i8* @basis_realloc(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = call i32 @nixtrace(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = load i64, i64* %4
%10 = call i8* @basis_malloc(i64 %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %33
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %32
16: ; preds = %13
%17 = load i8*, i8** %3
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = getelementptr inbounds i8, i8* %18, i64 -16
%20 = bitcast i8* %19 to i64*
%21 = load i64, i64* %20
store i64 %21, i64* %6
%22 = load i64, i64* %6
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %16
%25 = load i8*, i8** %5
%26 = load i8*, i8** %3
%27 = load i64, i64* %6
%28 = call i32 @memcpy(i8* %25, i8* %26, i64 %27)
br label %29
29: ; preds = %24, %16
%30 = load i8*, i8** %3
%31 = call i32 @basis_free(i8* %30)
br label %32
32: ; preds = %29, %13
br label %35
33: ; preds = %2
%34 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %32
%36 = call i32 @nixtrace(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%37 = load i8*, i8** %5
ret i8* %37
}

LLVM IR (-O2):
@.str = [20 x i8] c"Start basis_realloc\00"
@.str.2 = [19 x i8] c"Ende basis_realloc\00"
@str = [43 x i8] c"schrecklicher Fehler: realloc gescheitert!\00"
define i8* @basis_realloc(i8* %0, i64 %1) {
%3 = tail call i32 @nixtrace(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @basis_malloc(i64 %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = icmp eq i8* %0, null
br i1 %7, label %19, label %8
8: ; preds = %6
%9 = getelementptr inbounds i8, i8* %0, i64 -16
%10 = bitcast i8* %9 to i64*
%11 = load i64, i64* %10
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = tail call i32 @memcpy(i8* %4, i8* %0, i64 %11)
br label %15
15: ; preds = %13, %8
%16 = tail call i32 @basis_free(i8* %0)
br label %19
17: ; preds = %2
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
br label %19
19: ; preds = %6, %15, %17
%20 = tail call i32 @nixtrace(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
ret i8* %4
}