#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*/ STDOUT_FILENO;
int /*<<< orphan*/ munmap(size_t *, size_t);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
void free(void *ptr) {
  write(STDOUT_FILENO, "free... ", 8);
  size_t *real_ptr = (size_t *)ptr - 1;
  if (!munmap(real_ptr, *real_ptr)) {
    write(STDOUT_FILENO, "ok\n", 3);
  } else {
    write(STDOUT_FILENO, "fail\n", 5);
  }
}


x86 assembly (clang, -O0):
<free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%edi
lea    0xec4(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%rax
add    $0xfffffffffffffff8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1040 <munmap@plt>
cmp    $0x0,%eax
jne    118a <free+0x6a>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
jmp    11a4 <free+0x84>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<free>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ec2(%rip),%r14
mov    (%r14),%edi
lea    0xec8(%rip),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x8(%rbx),%rsi
add    $0xfffffffffffffff8,%rbx
mov    %rbx,%rdi
call   1040 <munmap@plt>
mov    (%r14),%edi
test   %eax,%eax
je     1167 <free+0x47>
lea    0xead(%rip),%rsi
mov    $0x5,%edx
jmp    1173 <free+0x53>
lea    0xe9b(%rip),%rsi
mov    $0x3,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <write@plt>

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@.str = [9 x i8] c"free... \00"
@.str.1 = [4 x i8] c"ok\0A\00"
@.str.2 = [6 x i8] c"fail\0A\00"
define void @free(i8* %0) {
%2 = alloca i8*
%3 = alloca i64*
store i8* %0, i8** %2
%4 = load i32, i32* @STDOUT_FILENO
%5 = call i32 @write(i32 %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i64*
%8 = getelementptr inbounds i64, i64* %7, i64 -1
store i64* %8, i64** %3
%9 = load i64*, i64** %3
%10 = load i64*, i64** %3
%11 = load i64, i64* %10
%12 = call i32 @munmap(i64* %9, i64 %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %1
%15 = load i32, i32* @STDOUT_FILENO
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
br label %20
17: ; preds = %1
%18 = load i32, i32* @STDOUT_FILENO
%19 = call i32 @write(i32 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
br label %20
20: ; preds = %17, %14
ret void
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@.str = [9 x i8] c"free... \00"
@.str.1 = [4 x i8] c"ok\0A\00"
@.str.2 = [6 x i8] c"fail\0A\00"
define void @free(i8* %0) {
%2 = load i32, i32* @STDOUT_FILENO
%3 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%4 = getelementptr inbounds i8, i8* %0, i64 -8
%5 = bitcast i8* %4 to i64*
%6 = load i64, i64* %5
%7 = tail call i32 @munmap(i64* %5, i64 %6)
%8 = icmp eq i32 %7, 0
%9 = load i32, i32* @STDOUT_FILENO
br i1 %8, label %10, label %12
10: ; preds = %1
%11 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
br label %14
12: ; preds = %1
%13 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
br label %14
14: ; preds = %12, %10
ret void
}