#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 *);
int mem_size(char *);
void test_001(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_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   1070 <mem_alloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1050 <mem_size@plt>
cmp    $0xa,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1060 <mem_end@plt>
mov    -0x8(%rbp),%rcx
add    $0xa,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <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   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1050 <mem_size@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1060 <mem_end@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <mem_free@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define void @test_001() {
%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_free(i8* %20)
store i8* %21, i8** %1
%22 = load i8*, i8** %1
%23 = icmp eq 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, 0
%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 = icmp eq i8* %32, null
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i8*, i8** %1
%37 = call i8* @mem_free(i8* %36)
%38 = icmp eq i8* %37, null
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
ret void
}

LLVM IR (-O2):
define void @test_001() {
%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_free(i8* %2)
%16 = icmp eq 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, 0
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = tail call i8* @mem_end(i8* %15)
%24 = icmp eq i8* %23, null
%25 = zext i1 %24 to i32
%26 = tail call i32 @assert(i32 %25)
%27 = tail call i8* @mem_free(i8* %15)
%28 = icmp eq i8* %27, null
%29 = zext i1 %28 to i32
%30 = tail call i32 @assert(i32 %29)
ret void
}