#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*/ abort();
int /*<<< orphan*/ aligned_free(void *);
void *aligned_malloc(size_t, size_t);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
void fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memcpy(void *, void *, size_t);
int /*<<< orphan*/ stderr;
void *aligned_realloc(void *p, size_t old_size, size_t new_size,
                      size_t alignment) {
  void *ret_p = NULL;
  if (new_size != 0) {
    ret_p = aligned_malloc(new_size, alignment);
    (ret_p != NULL
         ? (void)1
         : (fprintf(
                stderr, "Assertion Failed at %s:%d ",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/pumpkin83/OpenUH-OpenACC/"
                "refs/heads/master/osprey/libopenmp-pcl/omp_util.c",
                466),
            fprintf(stderr, ("Can not aligned malloc")), fprintf(stderr, "\n"),
            fflush(stderr), abort(), (void)0));
  }
  if (p != NULL) {
    memcpy(ret_p, p, (old_size >= new_size) ? new_size : old_size);
    aligned_free(p);
  }
  return ret_p;
}


x86 assembly (clang, -O0):
<aligned_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1217 <aligned_realloc+0xb7>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <aligned_malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ac <aligned_realloc+0x4c>
jmp    1212 <aligned_realloc+0xb2>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
lea    0xe58(%rip),%rdx
mov    $0x1d2,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xee1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xee1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1217 <aligned_realloc+0xb7>
cmpq   $0x0,-0x8(%rbp)
je     126f <aligned_realloc+0x10f>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     124d <aligned_realloc+0xed>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    1255 <aligned_realloc+0xf5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x8(%rbp),%rdi
call   1040 <aligned_free@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aligned_realloc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r14
test   %rdx,%rdx
je     11ba <aligned_realloc+0x5a>
mov    %rbx,%rdi
mov    %rcx,%rsi
call   1080 <aligned_malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11c4 <aligned_realloc+0x64>
test   %r14,%r14
je     11ab <aligned_realloc+0x4b>
cmp    %rbx,%r12
cmovb  %r12,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <memcpy@plt>
mov    %r14,%rdi
call   1040 <aligned_free@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %r15d,%r15d
test   %r14,%r14
jne    118e <aligned_realloc+0x2e>
jmp    11ab <aligned_realloc+0x4b>
mov    0x2e15(%rip),%rbx
mov    (%rbx),%edi
lea    0xe2c(%rip),%rsi
lea    0xe40(%rip),%rdx
mov    $0x1d2,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xed0(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xed7(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
call   1070 <fflush@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Assertion Failed at %s:%d \00"
@.str.1 = [165 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pumpkin83/OpenUH-OpenACC/refs/heads/master/osprey/libopenmp-pcl/omp_util.c\00"
@.str.2 = [23 x i8] c"Can not aligned malloc\00"
@.str.3 = [2 x i8] c"\0A\00"
define i8* @aligned_realloc(i8* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
store i8* null, i8** %9
%10 = load i64, i64* %7
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %4
%13 = load i64, i64* %7
%14 = load i64, i64* %8
%15 = call i8* @aligned_malloc(i64 %13, i64 %14)
store i8* %15, i8** %9
%16 = load i8*, i8** %9
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %12
br label %27
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = load i32, i32* @stderr
%22 = load i32, i32* @stderr
%23 = load i32, i32* @stderr
%24 = call i32 @fflush(i32 %23)
%25 = call i32 (...) @abort()
unreachable
26: ; No predecessors!
br label %27
27: ; preds = %26, %18
br label %28
28: ; preds = %27, %4
%29 = load i8*, i8** %5
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %46
31: ; preds = %28
%32 = load i8*, i8** %9
%33 = load i8*, i8** %5
%34 = load i64, i64* %6
%35 = load i64, i64* %7
%36 = icmp uge i64 %34, %35
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = load i64, i64* %7
br label %41
39: ; preds = %31
%40 = load i64, i64* %6
br label %41
41: ; preds = %39, %37
%42 = phi i64 [ %38, %37 ], [ %40, %39 ]
%43 = call i32 @memcpy(i8* %32, i8* %33, i64 %42)
%44 = load i8*, i8** %5
%45 = call i32 @aligned_free(i8* %44)
br label %46
46: ; preds = %41, %28
%47 = load i8*, i8** %9
ret i8* %47
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Assertion Failed at %s:%d \00"
@.str.1 = [165 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pumpkin83/OpenUH-OpenACC/refs/heads/master/osprey/libopenmp-pcl/omp_util.c\00"
@.str.2 = [23 x i8] c"Can not aligned malloc\00"
@.str.3 = [2 x i8] c"\0A\00"
define i8* @aligned_realloc(i8* %0, i64 %1, i64 %2, i64 %3) {
%5 = icmp eq i64 %2, 0
br i1 %5, label %16, label %6
6: ; preds = %4
%7 = tail call i8* @aligned_malloc(i64 %2, i64 %3)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = load i32, i32* @stderr
tail call void (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str.1, i64 0, i64 0), i32 466)
%11 = load i32, i32* @stderr
tail call void (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @stderr
tail call void (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = load i32, i32* @stderr
%14 = tail call i32 @fflush(i32 %13)
%15 = tail call i32 (...) @abort()
unreachable
16: ; preds = %6, %4
%17 = phi i8* [ %7, %6 ], [ null, %4 ]
%18 = icmp eq i8* %0, null
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = icmp ult i64 %1, %2
%21 = select i1 %20, i64 %1, i64 %2
%22 = tail call i32 @memcpy(i8* %17, i8* %0, i64 %21)
%23 = tail call i32 @aligned_free(i8* %0)
br label %24
24: ; preds = %19, %16
ret i8* %17
}