#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__ malloc(int);
scalar_t__ mem_alloc(int);
char *mem_end(char *);
char *mem_free(char *);
int mem_size(char *);
void test_003(void) {
  char *str1 = NULL;
  char *str2 = NULL;
  str1 = (char *)mem_alloc(10);
  assert(str1 != NULL);
  str2 = (char *)malloc(10);
  assert(str2 != NULL);
  assert(mem_size(str1) == 10);
  assert(mem_size(str2) == 0);
  assert(mem_end(str1) == str1 + 10);
  assert(mem_end(str2) == NULL);
  str1 = mem_free(str1);
  assert(str1 == NULL);
  str2 = mem_free(str2);
  assert(str2 == NULL);
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%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   1040 <assert@plt>
mov    $0xa,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%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    -0x10(%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>
mov    -0x8(%rbp),%rcx
add    $0xa,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%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>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <mem_free@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %r14
push   %rbx
push   %rax
mov    $0xa,%edi
call   1080 <mem_alloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
mov    $0xa,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
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    %r14,%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>
lea    0xa(%rbx),%rcx
xor    %edi,%edi
cmp    %rcx,%rax
sete   %dil
call   1040 <assert@plt>
mov    %r14,%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
call   1040 <assert@plt>
mov    %r14,%rdi
call   1030 <mem_free@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <assert@plt>

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

LLVM IR (-O2):
define void @test_003() {
%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 i64 @malloc(i32 10)
%7 = inttoptr i64 %6 to i8*
%8 = icmp ne i64 %6, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 @mem_size(i8* %2)
%12 = icmp eq i32 %11, 10
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32 @mem_size(i8* %7)
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call i8* @mem_end(i8* %2)
%20 = getelementptr inbounds i8, i8* %2, i64 10
%21 = icmp eq i8* %19, %20
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = tail call i8* @mem_end(i8* %7)
%25 = icmp eq i8* %24, null
%26 = zext i1 %25 to i32
%27 = tail call i32 @assert(i32 %26)
%28 = tail call i8* @mem_free(i8* %2)
%29 = icmp eq i8* %28, null
%30 = zext i1 %29 to i32
%31 = tail call i32 @assert(i32 %30)
%32 = tail call i8* @mem_free(i8* %7)
%33 = icmp eq i8* %32, null
%34 = zext i1 %33 to i32
%35 = tail call i32 @assert(i32 %34)
ret void
}