#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);
scalar_t__ mem_alloc(int);
char *mem_end(char *);
char *mem_free(char *);
char *mem_realloc(char *, int);
int mem_size(char *);
void test_002(void) {
  char *str = NULL;
  str = (char *)mem_alloc(10);
  assert(str != NULL);
  assert(mem_size(str) == 10);
  assert(mem_end(str) == str + 10);
  str = mem_realloc(str, 1024 * 1024);
  assert(str != NULL);
  assert(mem_size(str) == 1024 * 1024);
  assert(mem_end(str) == str + (1024 * 1024));
  str = mem_free(str);
  assert(str == NULL);
  assert(mem_size(str) == 0);
  assert(mem_end(str) == NULL);
  assert(mem_free(str) == NULL);
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
mov    $0xa,%edi
call   1080 <mem_alloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1060 <mem_size@plt>
cmp    $0xa,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1070 <mem_end@plt>
mov    -0x8(%rbp),%rcx
add    $0xa,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    $0x100000,%esi
call   1040 <mem_realloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1060 <mem_size@plt>
cmp    $0x100000,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1070 <mem_end@plt>
mov    -0x8(%rbp),%rcx
add    $0x100000,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <mem_free@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1060 <mem_size@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1070 <mem_end@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <mem_free@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbx
mov    $0xa,%edi
call   1080 <mem_alloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1060 <mem_size@plt>
xor    %edi,%edi
cmp    $0xa,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1070 <mem_end@plt>
lea    0xa(%rbx),%rcx
xor    %edi,%edi
cmp    %rcx,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    $0x100000,%esi
call   1040 <mem_realloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1060 <mem_size@plt>
xor    %edi,%edi
cmp    $0x100000,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1070 <mem_end@plt>
lea    0x100000(%rbx),%rcx
xor    %edi,%edi
cmp    %rcx,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <mem_free@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1060 <mem_size@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1070 <mem_end@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <mem_free@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
pop    %rbx
jmp    1050 <assert@plt>

LLVM IR (-O0):
define void @test_002() {
%1 = alloca i8*
store i8* null, i8** %1
%2 = call i64 @mem_alloc(i32 10)
%3 = inttoptr i64 %2 to i8*
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = icmp ne i8* %4, null
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i8*, i8** %1
%9 = call i32 @mem_size(i8* %8)
%10 = icmp eq i32 %9, 10
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i8*, i8** %1
%14 = call i8* @mem_end(i8* %13)
%15 = load i8*, i8** %1
%16 = getelementptr inbounds i8, i8* %15, i64 10
%17 = icmp eq i8* %14, %16
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i8*, i8** %1
%21 = call i8* @mem_realloc(i8* %20, i32 1048576)
store i8* %21, i8** %1
%22 = load i8*, i8** %1
%23 = icmp ne i8* %22, null
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i8*, i8** %1
%27 = call i32 @mem_size(i8* %26)
%28 = icmp eq i32 %27, 1048576
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i8*, i8** %1
%32 = call i8* @mem_end(i8* %31)
%33 = load i8*, i8** %1
%34 = getelementptr inbounds i8, i8* %33, i64 1048576
%35 = icmp eq i8* %32, %34
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i8*, i8** %1
%39 = call i8* @mem_free(i8* %38)
store i8* %39, i8** %1
%40 = load i8*, i8** %1
%41 = icmp eq i8* %40, null
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i8*, i8** %1
%45 = call i32 @mem_size(i8* %44)
%46 = icmp eq i32 %45, 0
%47 = zext i1 %46 to i32
%48 = call i32 @assert(i32 %47)
%49 = load i8*, i8** %1
%50 = call i8* @mem_end(i8* %49)
%51 = icmp eq i8* %50, null
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = load i8*, i8** %1
%55 = call i8* @mem_free(i8* %54)
%56 = icmp eq i8* %55, null
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
ret void
}

LLVM IR (-O2):
define void @test_002() {
%1 = tail call i64 @mem_alloc(i32 10)
%2 = inttoptr i64 %1 to i8*
%3 = icmp ne i64 %1, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 @mem_size(i8* %2)
%7 = icmp eq i32 %6, 10
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i8* @mem_end(i8* %2)
%11 = getelementptr inbounds i8, i8* %2, i64 10
%12 = icmp eq i8* %10, %11
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i8* @mem_realloc(i8* %2, i32 1048576)
%16 = icmp ne i8* %15, null
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call i32 @mem_size(i8* %15)
%20 = icmp eq i32 %19, 1048576
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = tail call i8* @mem_end(i8* %15)
%24 = getelementptr inbounds i8, i8* %15, i64 1048576
%25 = icmp eq i8* %23, %24
%26 = zext i1 %25 to i32
%27 = tail call i32 @assert(i32 %26)
%28 = tail call i8* @mem_free(i8* %15)
%29 = icmp eq i8* %28, null
%30 = zext i1 %29 to i32
%31 = tail call i32 @assert(i32 %30)
%32 = tail call i32 @mem_size(i8* %28)
%33 = icmp eq i32 %32, 0
%34 = zext i1 %33 to i32
%35 = tail call i32 @assert(i32 %34)
%36 = tail call i8* @mem_end(i8* %28)
%37 = icmp eq i8* %36, null
%38 = zext i1 %37 to i32
%39 = tail call i32 @assert(i32 %38)
%40 = tail call i8* @mem_free(i8* %28)
%41 = icmp eq i8* %40, null
%42 = zext i1 %41 to i32
%43 = tail call i32 @assert(i32 %42)
ret void
}