#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 */
struct dm_pool {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(char *);
char *dm_pool_alloc(struct dm_pool *, int);
struct dm_pool *dm_pool_create(char *, int);
int /*<<< orphan*/ dm_pool_destroy(struct dm_pool *);
int /*<<< orphan*/ dm_pool_empty(struct dm_pool *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
void check_allocation_near_chunk_size() {
  int i;
  char *data;
  struct dm_pool *p = dm_pool_create("", 900);
  for (i = 0; i < 1000; i++) {
    data = dm_pool_alloc(p, 37);
    memset(data, 0, 37);
    assert(data);
  }
  dm_pool_empty(p);
  data = dm_pool_alloc(p, 1020);
  assert(data);
  memset(data, 0, 1020);
  dm_pool_destroy(p);
}


x86 assembly (clang, -O0):
<check_allocation_near_chunk_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
mov    $0x384,%esi
call   1060 <dm_pool_create@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x3e8,-0x4(%rbp)
jge    11ca <check_allocation_near_chunk_size+0x6a>
mov    -0x18(%rbp),%rdi
mov    $0x25,%esi
call   1030 <dm_pool_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x25,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1184 <check_allocation_near_chunk_size+0x24>
mov    -0x18(%rbp),%rdi
call   1080 <dm_pool_empty@plt>
mov    -0x18(%rbp),%rdi
mov    $0x3fc,%esi
call   1030 <dm_pool_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x3fc,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
call   1070 <dm_pool_destroy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_allocation_near_chunk_size>:
push   %rbp
push   %r14
push   %rbx
lea    0xe95(%rip),%rdi
mov    $0x384,%esi
call   1060 <dm_pool_create@plt>
mov    %rax,%r14
mov    $0x3e8,%ebp
nopl   (%rax)
mov    %r14,%rdi
mov    $0x25,%esi
call   1030 <dm_pool_alloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x25,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1050 <assert@plt>
add    $0xffffffff,%ebp
jne    1180 <check_allocation_near_chunk_size+0x20>
mov    %r14,%rdi
call   1080 <dm_pool_empty@plt>
mov    %r14,%rdi
mov    $0x3fc,%esi
call   1030 <dm_pool_alloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <assert@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3fc,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <dm_pool_destroy@plt>

LLVM IR (-O0):
%struct.dm_pool = type { i32 }
@.str = [1 x i8] zeroinitializer
define void @check_allocation_near_chunk_size() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.dm_pool*
%4 = call %struct.dm_pool* @dm_pool_create(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 900)
store %struct.dm_pool* %4, %struct.dm_pool** %3
store i32 0, i32* %1
br label %5
5: ; preds = %15, %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 1000
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = load %struct.dm_pool*, %struct.dm_pool** %3
%10 = call i8* @dm_pool_alloc(%struct.dm_pool* %9, i32 37)
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = call i32 @memset(i8* %11, i32 0, i32 37)
%13 = load i8*, i8** %2
%14 = call i32 @assert(i8* %13)
br label %15
15: ; preds = %8
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 1
store i32 %17, i32* %1
br label %5
18: ; preds = %5
%19 = load %struct.dm_pool*, %struct.dm_pool** %3
%20 = call i32 @dm_pool_empty(%struct.dm_pool* %19)
%21 = load %struct.dm_pool*, %struct.dm_pool** %3
%22 = call i8* @dm_pool_alloc(%struct.dm_pool* %21, i32 1020)
store i8* %22, i8** %2
%23 = load i8*, i8** %2
%24 = call i32 @assert(i8* %23)
%25 = load i8*, i8** %2
%26 = call i32 @memset(i8* %25, i32 0, i32 1020)
%27 = load %struct.dm_pool*, %struct.dm_pool** %3
%28 = call i32 @dm_pool_destroy(%struct.dm_pool* %27)
ret void
}

LLVM IR (-O2):
%struct.dm_pool = type { i32 }
@.str = [1 x i8] zeroinitializer
define void @check_allocation_near_chunk_size() {
%1 = tail call %struct.dm_pool* @dm_pool_create(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 900)
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 0, %0 ], [ %7, %2 ]
%4 = tail call i8* @dm_pool_alloc(%struct.dm_pool* %1, i32 37)
%5 = tail call i32 @memset(i8* %4, i32 0, i32 37)
%6 = tail call i32 @assert(i8* %4)
%7 = add nuw nsw i32 %3, 1
%8 = icmp eq i32 %7, 1000
br i1 %8, label %9, label %2
9: ; preds = %2
%10 = tail call i32 @dm_pool_empty(%struct.dm_pool* %1)
%11 = tail call i8* @dm_pool_alloc(%struct.dm_pool* %1, i32 1020)
%12 = tail call i32 @assert(i8* %11)
%13 = tail call i32 @memset(i8* %11, i32 0, i32 1020)
%14 = tail call i32 @dm_pool_destroy(%struct.dm_pool* %1)
ret void
}