#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*/ fatal(char *);
char *realloc(char *, unsigned int);
char *scxmalloc(unsigned int);
char *scxrealloc(char *ptr, unsigned n) {
  if (ptr == NULL)
    return (scxmalloc(n));
  ptr -= sizeof(double);
  if (*((double *)ptr) != (double)1234567890.12344)
    fatal("scxrealloc: storage not scxmalloc'ed");
  if ((ptr = realloc(ptr, n + sizeof(double))) == NULL)
    fatal("scxmalloc: no memory");
  *((double *)ptr) = (double)1234567890.12344;
  return (ptr + sizeof(double));
}


x86 assembly (clang, -O0):
<scxrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115b <scxrealloc+0x2b>
mov    -0x14(%rbp),%edi
call   1030 <scxmalloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11e0 <scxrealloc+0xb0>
mov    -0x10(%rbp),%rax
add    $0xfffffffffffffff8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xe89(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    118c <scxrealloc+0x5c>
jp     118c <scxrealloc+0x5c>
jmp    1198 <scxrealloc+0x68>
lea    0xe75(%rip),%rdi
call   1050 <fatal@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x8,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11c4 <scxrealloc+0x94>
lea    0xe6e(%rip),%rdi
call   1050 <fatal@plt>
mov    -0x10(%rbp),%rax
movsd  0xe30(%rip),%xmm0
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scxrealloc>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
test   %rdi,%rdi
je     119a <scxrealloc+0x6a>
mov    %rdi,%rbx
movsd  -0x8(%rdi),%xmm0
add    $0xfffffffffffffff8,%rbx
ucomisd 0xeb2(%rip),%xmm0
jne    1152 <scxrealloc+0x22>
jnp    115e <scxrealloc+0x2e>
lea    0xeaf(%rip),%rdi
call   1050 <fatal@plt>
add    $0x8,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117f <scxrealloc+0x4f>
lea    0xeb3(%rip),%rdi
call   1050 <fatal@plt>
movabs $0x41d26580b487e671,%rax
65 d2 41
mov    %rax,(%rbx)
add    $0x8,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <scxmalloc@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"scxrealloc: storage not scxmalloc'ed\00"
@.str.1 = [21 x i8] c"scxmalloc: no memory\00"
define i8* @scxrealloc(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i8*, i8** %4
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* %5
%10 = call i8* @scxmalloc(i32 %9)
store i8* %10, i8** %3
br label %35
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 -8
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = bitcast i8* %14 to double*
%16 = load double, double* %15
%17 = fcmp une double %16, 0x41D26580B487E671
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 @fatal(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %11
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = zext i32 %22 to i64
%24 = add i64 %23, 8
%25 = trunc i64 %24 to i32
%26 = call i8* @realloc(i8* %21, i32 %25)
store i8* %26, i8** %4
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = call i32 @fatal(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %20
%31 = load i8*, i8** %4
%32 = bitcast i8* %31 to double*
store double 0x41D26580B487E671, double* %32
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 8
store i8* %34, i8** %3
br label %35
35: ; preds = %30, %8
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
@.str = [37 x i8] c"scxrealloc: storage not scxmalloc'ed\00"
@.str.1 = [21 x i8] c"scxmalloc: no memory\00"
define i8* @scxrealloc(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i8* @scxmalloc(i32 %1)
br label %22
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %0, i64 -8
%8 = bitcast i8* %7 to double*
%9 = load double, double* %8
%10 = fcmp une double %9, 0x41D26580B487E671
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @fatal(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %6
%14 = add i32 %1, 8
%15 = tail call i8* @realloc(i8* %7, i32 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @fatal(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %13
%20 = bitcast i8* %15 to double*
store double 0x41D26580B487E671, double* %20
%21 = getelementptr inbounds i8, i8* %15, i64 8
br label %22
22: ; preds = %19, %4
%23 = phi i8* [ %5, %4 ], [ %21, %19 ]
ret i8* %23
}