#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 */
typedef char dm_pool;

/* Variables and functions */
int /*<<< orphan*/ assert(char *);
char *dm_pool_alloc(char *, int);
char *dm_pool_create(char *, int);
int /*<<< orphan*/ dm_pool_destroy(char *);
int /*<<< orphan*/ dm_pool_free(char *, char *);
void check_free2() {
  struct dm_pool *p = dm_pool_create("", 900);
  char *data1, *data2;
  assert(p);
  data1 = dm_pool_alloc(p, 123);
  assert(data1);
  data1 = dm_pool_alloc(p, 1024);
  assert(data1);
  data2 = dm_pool_alloc(p, 123);
  assert(data2);
  data2[0] = 'A';
  dm_pool_free(p, data1);
  data2[0] = 'B';
  dm_pool_destroy(p);
}


x86 assembly (clang, -O0):
<check_free2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
mov    $0x384,%esi
call   1050 <dm_pool_create@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    $0x7b,%esi
call   1030 <dm_pool_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    $0x400,%esi
call   1030 <dm_pool_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    $0x7b,%esi
call   1030 <dm_pool_alloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
movb   $0x41,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <dm_pool_free@plt>
mov    -0x18(%rbp),%rax
movb   $0x42,(%rax)
mov    -0x8(%rbp),%rdi
call   1060 <dm_pool_destroy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_free2>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rdi
mov    $0x384,%esi
call   1050 <dm_pool_create@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <assert@plt>
mov    %r15,%rdi
mov    $0x7b,%esi
call   1030 <dm_pool_alloc@plt>
mov    %rax,%rdi
call   1040 <assert@plt>
mov    %r15,%rdi
mov    $0x400,%esi
call   1030 <dm_pool_alloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <assert@plt>
mov    %r15,%rdi
mov    $0x7b,%esi
call   1030 <dm_pool_alloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <assert@plt>
movb   $0x41,(%rbx)
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <dm_pool_free@plt>
movb   $0x42,(%rbx)
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <dm_pool_destroy@plt>

LLVM IR (-O0):
%struct.dm_pool = type opaque
@.str = [1 x i8] zeroinitializer
define void @check_free2() {
%1 = alloca %struct.dm_pool*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @dm_pool_create(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 900)
%5 = bitcast i8* %4 to %struct.dm_pool*
store %struct.dm_pool* %5, %struct.dm_pool** %1
%6 = load %struct.dm_pool*, %struct.dm_pool** %1
%7 = bitcast %struct.dm_pool* %6 to i8*
%8 = call i32 @assert(i8* %7)
%9 = load %struct.dm_pool*, %struct.dm_pool** %1
%10 = bitcast %struct.dm_pool* %9 to i8*
%11 = call i8* @dm_pool_alloc(i8* %10, i32 123)
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = call i32 @assert(i8* %12)
%14 = load %struct.dm_pool*, %struct.dm_pool** %1
%15 = bitcast %struct.dm_pool* %14 to i8*
%16 = call i8* @dm_pool_alloc(i8* %15, i32 1024)
store i8* %16, i8** %2
%17 = load i8*, i8** %2
%18 = call i32 @assert(i8* %17)
%19 = load %struct.dm_pool*, %struct.dm_pool** %1
%20 = bitcast %struct.dm_pool* %19 to i8*
%21 = call i8* @dm_pool_alloc(i8* %20, i32 123)
store i8* %21, i8** %3
%22 = load i8*, i8** %3
%23 = call i32 @assert(i8* %22)
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 0
store i8 65, i8* %25
%26 = load %struct.dm_pool*, %struct.dm_pool** %1
%27 = bitcast %struct.dm_pool* %26 to i8*
%28 = load i8*, i8** %2
%29 = call i32 @dm_pool_free(i8* %27, i8* %28)
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 0
store i8 66, i8* %31
%32 = load %struct.dm_pool*, %struct.dm_pool** %1
%33 = bitcast %struct.dm_pool* %32 to i8*
%34 = call i32 @dm_pool_destroy(i8* %33)
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define void @check_free2() {
%1 = tail call i8* @dm_pool_create(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 900)
%2 = tail call i32 @assert(i8* %1)
%3 = tail call i8* @dm_pool_alloc(i8* %1, i32 123)
%4 = tail call i32 @assert(i8* %3)
%5 = tail call i8* @dm_pool_alloc(i8* %1, i32 1024)
%6 = tail call i32 @assert(i8* %5)
%7 = tail call i8* @dm_pool_alloc(i8* %1, i32 123)
%8 = tail call i32 @assert(i8* %7)
store i8 65, i8* %7
%9 = tail call i32 @dm_pool_free(i8* %1, i8* %5)
store i8 66, i8* %7
%10 = tail call i32 @dm_pool_destroy(i8* %1)
ret void
}