#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*/ assert(int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ *lift_arealloc_implementation(int **, size_t, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int main() {
  int *v = NULL;
  if (NULL == lift_arealloc_implementation(&v, 4, sizeof *v)) {
    printf("Failed to allocate memory\n");
    return -1;
  }
  v[0] = v[1] = v[2] = v[3] = 4443;
  if (NULL == lift_arealloc_implementation(&v, 8, sizeof *v)) {
    printf("Failed to re-allocate memory\n");
    return -1;
  }
  if (NULL == lift_arealloc_implementation(&v, (size_t)~0, sizeof *v)) {
    printf("Failed to re-allocate memory, as expected\n");
  }
  v[4] = v[5] = v[6] = v[7] = 443;
  if (NULL == lift_arealloc_implementation(&(v), (6), sizeof *(v))) {
    printf("Failed to re-allocate memory\n");
    return -1;
  }
  if (NULL == lift_arealloc_implementation(&(v), ((size_t)~0), sizeof *(v))) {
    printf("Failed to re-allocate memory, as expected\n");
  }
  assert(v[5] == 443);
  free(v);
  puts("lift_arealloc() example finished normally");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0x4,%esi
mov    $0x4,%edx
call   1050 <lift_arealloc_implementation@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11a0 <main+0x50>
lea    0xe71(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fb <main+0x1ab>
mov    -0x10(%rbp),%rax
movl   $0x115b,0xc(%rax)
mov    -0x10(%rbp),%rax
movl   $0x115b,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x115b,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0x115b,(%rax)
lea    -0x10(%rbp),%rdi
mov    $0x8,%esi
mov    $0x4,%edx
call   1050 <lift_arealloc_implementation@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1204 <main+0xb4>
lea    0xe28(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fb <main+0x1ab>
lea    -0x10(%rbp),%rdi
mov    $0xffffffffffffffff,%rsi
mov    $0x4,%edx
call   1050 <lift_arealloc_implementation@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1233 <main+0xe3>
lea    0xe0b(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
movl   $0x1bb,0x1c(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1bb,0x18(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1bb,0x14(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1bb,0x10(%rax)
lea    -0x10(%rbp),%rdi
mov    $0x6,%esi
mov    $0x4,%edx
call   1050 <lift_arealloc_implementation@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1298 <main+0x148>
lea    0xd94(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fb <main+0x1ab>
lea    -0x10(%rbp),%rdi
mov    $0xffffffffffffffff,%rsi
mov    $0x4,%edx
call   1050 <lift_arealloc_implementation@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12c7 <main+0x177>
lea    0xd77(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x1bb,0x14(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xd75(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movq   $0x0,(%rsp)
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x4,%edx
call   1050 <lift_arealloc_implementation@plt>
test   %rax,%rax
je     1235 <main+0xf5>
mov    (%rsp),%rax
movaps 0xe91(%rip),%xmm0
movups %xmm0,(%rax)
mov    %rsp,%rdi
mov    $0x8,%esi
mov    $0x4,%edx
call   1050 <lift_arealloc_implementation@plt>
test   %rax,%rax
je     122c <main+0xec>
mov    %rsp,%rdi
mov    $0xffffffffffffffff,%rsi
mov    $0x4,%edx
call   1050 <lift_arealloc_implementation@plt>
test   %rax,%rax
jne    11b2 <main+0x72>
lea    0xe9d(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rax
movaps 0xe53(%rip),%xmm0
movups %xmm0,0x10(%rax)
mov    %rsp,%rdi
mov    $0x6,%esi
mov    $0x4,%edx
call   1050 <lift_arealloc_implementation@plt>
test   %rax,%rax
je     122c <main+0xec>
mov    %rsp,%rdi
mov    $0xffffffffffffffff,%rsi
mov    $0x4,%edx
call   1050 <lift_arealloc_implementation@plt>
test   %rax,%rax
jne    11fd <main+0xbd>
lea    0xe52(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rax
xor    %edi,%edi
cmpl   $0x1bb,0x14(%rax)
sete   %dil
call   1060 <assert@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
lea    0xdfd(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe41(%rip),%rdi
jmp    123c <main+0xfc>
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Failed to allocate memory\0A\00"
@.str.1 = [30 x i8] c"Failed to re-allocate memory\0A\00"
@.str.2 = [43 x i8] c"Failed to re-allocate memory, as expected\0A\00"
@.str.3 = [42 x i8] c"lift_arealloc() example finished normally\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
store i32* null, i32** %2
%3 = call i32* @lift_arealloc_implementation(i32** %2, i64 4, i32 4)
%4 = icmp eq i32* null, %3
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %53
7: ; preds = %0
%8 = load i32*, i32** %2
%9 = getelementptr inbounds i32, i32* %8, i64 3
store i32 4443, i32* %9
%10 = load i32*, i32** %2
%11 = getelementptr inbounds i32, i32* %10, i64 2
store i32 4443, i32* %11
%12 = load i32*, i32** %2
%13 = getelementptr inbounds i32, i32* %12, i64 1
store i32 4443, i32* %13
%14 = load i32*, i32** %2
%15 = getelementptr inbounds i32, i32* %14, i64 0
store i32 4443, i32* %15
%16 = call i32* @lift_arealloc_implementation(i32** %2, i64 8, i32 4)
%17 = icmp eq i32* null, %16
br i1 %17, label %18, label %20
18: ; preds = %7
%19 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %53
20: ; preds = %7
%21 = call i32* @lift_arealloc_implementation(i32** %2, i64 -1, i32 4)
%22 = icmp eq i32* null, %21
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = load i32*, i32** %2
%27 = getelementptr inbounds i32, i32* %26, i64 7
store i32 443, i32* %27
%28 = load i32*, i32** %2
%29 = getelementptr inbounds i32, i32* %28, i64 6
store i32 443, i32* %29
%30 = load i32*, i32** %2
%31 = getelementptr inbounds i32, i32* %30, i64 5
store i32 443, i32* %31
%32 = load i32*, i32** %2
%33 = getelementptr inbounds i32, i32* %32, i64 4
store i32 443, i32* %33
%34 = call i32* @lift_arealloc_implementation(i32** %2, i64 6, i32 4)
%35 = icmp eq i32* null, %34
br i1 %35, label %36, label %38
36: ; preds = %25
%37 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %53
38: ; preds = %25
%39 = call i32* @lift_arealloc_implementation(i32** %2, i64 -1, i32 4)
%40 = icmp eq i32* null, %39
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
%44 = load i32*, i32** %2
%45 = getelementptr inbounds i32, i32* %44, i64 5
%46 = load i32, i32* %45
%47 = icmp eq i32 %46, 443
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i32*, i32** %2
%51 = call i32 @free(i32* %50)
%52 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %53
53: ; preds = %43, %36, %18, %5
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str.3 = [42 x i8] c"lift_arealloc() example finished normally\00"
@str.5 = [42 x i8] c"Failed to re-allocate memory, as expected\00"
@str.6 = [29 x i8] c"Failed to re-allocate memory\00"
@str.7 = [26 x i8] c"Failed to allocate memory\00"
define i32 @main() {
%1 = alloca i32*
%2 = bitcast i32** %1 to i8*
store i32* null, i32** %1
%3 = call i32* @lift_arealloc_implementation(i32** %1, i64 4, i32 4)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.7, i64 0, i64 0))
br label %42
7: ; preds = %0
%8 = bitcast i32** %1 to <4 x i32>**
%9 = load <4 x i32>*, <4 x i32>** %8
store <4 x i32> <i32 4443, i32 4443, i32 4443, i32 4443>, <4 x i32>* %9
%10 = call i32* @lift_arealloc_implementation(i32** %1, i64 8, i32 4)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.6, i64 0, i64 0))
br label %42
14: ; preds = %7
%15 = call i32* @lift_arealloc_implementation(i32** %1, i64 -1, i32 4)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.5, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = load i32*, i32** %1
%21 = getelementptr inbounds i32, i32* %20, i64 4
%22 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> <i32 443, i32 443, i32 443, i32 443>, <4 x i32>* %22
%23 = call i32* @lift_arealloc_implementation(i32** %1, i64 6, i32 4)
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.6, i64 0, i64 0))
br label %42
27: ; preds = %19
%28 = call i32* @lift_arealloc_implementation(i32** %1, i64 -1, i32 4)
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.5, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
%33 = load i32*, i32** %1
%34 = getelementptr inbounds i32, i32* %33, i64 5
%35 = load i32, i32* %34
%36 = icmp eq i32 %35, 443
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = load i32*, i32** %1
%40 = call i32 @free(i32* %39)
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %32, %25, %12, %5
%43 = phi i32 [ -1, %5 ], [ -1, %12 ], [ -1, %25 ], [ 0, %32 ]
ret i32 %43
}