#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*/ alloc_test_free(void *);
int /*<<< orphan*/ *alloc_test_malloc(int);
int /*<<< orphan*/ alloc_test_set_limit(int);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
void test_limits(void) {
  void *block;
  block = alloc_test_malloc(2048);
  assert(block != NULL);
  alloc_test_free(block);
  alloc_test_set_limit(1);
  block = alloc_test_malloc(1024);
  assert(block != NULL);
  assert(alloc_test_malloc(1024) == NULL);
  alloc_test_free(block);
  alloc_test_set_limit(-1);
  block = alloc_test_malloc(1024);
  assert(block != NULL);
  alloc_test_free(block);
}


x86 assembly (clang, -O0):
<test_limits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x800,%edi
call   1060 <alloc_test_malloc@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   1040 <alloc_test_free@plt>
mov    $0x1,%edi
call   1030 <alloc_test_set_limit@plt>
mov    $0x400,%edi
call   1060 <alloc_test_malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x400,%edi
call   1060 <alloc_test_malloc@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <alloc_test_free@plt>
mov    $0xffffffff,%edi
call   1030 <alloc_test_set_limit@plt>
mov    $0x400,%edi
call   1060 <alloc_test_malloc@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   1040 <alloc_test_free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_limits>:
push   %rbx
mov    $0x800,%edi
call   1060 <alloc_test_malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1040 <alloc_test_free@plt>
mov    $0x1,%edi
call   1030 <alloc_test_set_limit@plt>
mov    $0x400,%edi
call   1060 <alloc_test_malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    $0x400,%edi
call   1060 <alloc_test_malloc@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1040 <alloc_test_free@plt>
mov    $0xffffffff,%edi
call   1030 <alloc_test_set_limit@plt>
mov    $0x400,%edi
call   1060 <alloc_test_malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <alloc_test_free@plt>

LLVM IR (-O0):
define void @test_limits() {
%1 = alloca i8*
%2 = call i32* @alloc_test_malloc(i32 2048)
%3 = bitcast i32* %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 @alloc_test_free(i8* %8)
%10 = call i32 @alloc_test_set_limit(i32 1)
%11 = call i32* @alloc_test_malloc(i32 1024)
%12 = bitcast i32* %11 to i8*
store i8* %12, i8** %1
%13 = load i8*, i8** %1
%14 = icmp ne i8* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i32* @alloc_test_malloc(i32 1024)
%18 = icmp eq i32* %17, null
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %1
%22 = call i32 @alloc_test_free(i8* %21)
%23 = call i32 @alloc_test_set_limit(i32 -1)
%24 = call i32* @alloc_test_malloc(i32 1024)
%25 = bitcast i32* %24 to i8*
store i8* %25, i8** %1
%26 = load i8*, i8** %1
%27 = icmp ne i8* %26, null
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i8*, i8** %1
%31 = call i32 @alloc_test_free(i8* %30)
ret void
}

LLVM IR (-O2):
define void @test_limits() {
%1 = tail call i32* @alloc_test_malloc(i32 2048)
%2 = bitcast i32* %1 to i8*
%3 = icmp ne i32* %1, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 @alloc_test_free(i8* %2)
%7 = tail call i32 @alloc_test_set_limit(i32 1)
%8 = tail call i32* @alloc_test_malloc(i32 1024)
%9 = bitcast i32* %8 to i8*
%10 = icmp ne i32* %8, null
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i32* @alloc_test_malloc(i32 1024)
%14 = icmp eq i32* %13, null
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call i32 @alloc_test_free(i8* %9)
%18 = tail call i32 @alloc_test_set_limit(i32 -1)
%19 = tail call i32* @alloc_test_malloc(i32 1024)
%20 = bitcast i32* %19 to i8*
%21 = icmp ne i32* %19, null
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = tail call i32 @alloc_test_free(i8* %20)
ret void
}