#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_begin(char *);
char *mem_free(char *);
void test_004(void) {
  char *str = NULL;
  str = (char *)mem_alloc(10);
  assert(str != NULL);
  assert(mem_begin(str) == str);
  assert(mem_begin(str + 5) == str);
  assert(mem_begin(str + 10) == str);
  assert(mem_begin(str - 1) == NULL);
  assert(mem_begin(str + 11) == NULL);
  str = mem_free(str);
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
mov    $0xa,%edi
call   1060 <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_begin@plt>
cmp    -0x8(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
add    $0x5,%rdi
call   1050 <mem_begin@plt>
cmp    -0x8(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
add    $0xa,%rdi
call   1050 <mem_begin@plt>
cmp    -0x8(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
add    $0xffffffffffffffff,%rdi
call   1050 <mem_begin@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
add    $0xb,%rdi
call   1050 <mem_begin@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)
add    $0x10,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define void @test_004() {
%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 i8* @mem_begin(i8* %8)
%10 = load i8*, i8** %1
%11 = icmp eq i8* %9, %10
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8*, i8** %1
%15 = getelementptr inbounds i8, i8* %14, i64 5
%16 = call i8* @mem_begin(i8* %15)
%17 = load i8*, i8** %1
%18 = icmp eq i8* %16, %17
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %1
%22 = getelementptr inbounds i8, i8* %21, i64 10
%23 = call i8* @mem_begin(i8* %22)
%24 = load i8*, i8** %1
%25 = icmp eq i8* %23, %24
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i8*, i8** %1
%29 = getelementptr inbounds i8, i8* %28, i64 -1
%30 = call i8* @mem_begin(i8* %29)
%31 = icmp eq i8* %30, null
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i8*, i8** %1
%35 = getelementptr inbounds i8, i8* %34, i64 11
%36 = call i8* @mem_begin(i8* %35)
%37 = icmp eq i8* %36, null
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load i8*, i8** %1
%41 = call i8* @mem_free(i8* %40)
store i8* %41, i8** %1
ret void
}

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