#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 int /*<<< orphan*/ uint8_t;
typedef int uint32_t;
typedef scalar_t__ uint16_t;
typedef int /*<<< orphan*/ mem_head;
typedef int /*<<< orphan*/ mem;

/* Variables and functions */
int /*<<< orphan*/ memcpy(void *, void **, int);
void mem_release(void *mem, void **mem_head) {
  uint16_t free_count = 0;
  if (*mem_head) {
    free_count = *(
        (uint16_t *)(((uint32_t)((uint8_t *)*mem_head + sizeof(mem_head)) + 3) &
                     (~((uint32_t)3))));
  }
  free_count++;
  memcpy(mem, mem_head, sizeof(mem));
  *((uint16_t *)(((uint32_t)((uint8_t *)mem + sizeof(mem)) + 3) &
                 (~((uint32_t)3)))) = free_count;
  *mem_head = mem;
}


x86 assembly (clang, -O0):
<mem_release>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1150 <mem_release+0x40>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
add    $0x20,%rax
add    $0x3,%eax
and    $0xfffffffc,%eax
cltq
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
add    $0x20,%rax
add    $0x3,%eax
and    $0xfffffffc,%eax
cltq
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_release>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
movabs $0x300000000,%r15
mov    (%rsi),%rax
test   %rax,%rax
je     114b <mem_release+0x3b>
add    $0x20,%eax
shl    $0x20,%rax
add    %r15,%rax
sar    $0x20,%rax
and    $0xfffffffffffffffc,%rax
mov    (%rax),%rbx
add    $0x1,%rbx
jmp    1150 <mem_release+0x40>
mov    $0x1,%ebx
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
lea    0x20(%r12),%eax
shl    $0x20,%rax
add    %r15,%rax
sar    $0x20,%rax
and    $0xfffffffffffffffc,%rax
mov    %rbx,(%rax)
mov    %r12,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @mem_release(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i64
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i64 0, i64* %5
%6 = load i8**, i8*** %4
%7 = load i8*, i8** %6
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %20
9: ; preds = %2
%10 = load i8**, i8*** %4
%11 = load i8*, i8** %10
%12 = bitcast i8* %11 to i32*
%13 = getelementptr inbounds i32, i32* %12, i64 8
%14 = ptrtoint i32* %13 to i32
%15 = add nsw i32 %14, 3
%16 = and i32 %15, -4
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i64*
%19 = load i64, i64* %18
store i64 %19, i64* %5
br label %20
20: ; preds = %9, %2
%21 = load i64, i64* %5
%22 = add nsw i64 %21, 1
store i64 %22, i64* %5
%23 = load i8*, i8** %3
%24 = load i8**, i8*** %4
%25 = call i32 @memcpy(i8* %23, i8** %24, i32 8)
%26 = load i64, i64* %5
%27 = load i8*, i8** %3
%28 = bitcast i8* %27 to i32*
%29 = getelementptr inbounds i32, i32* %28, i64 8
%30 = ptrtoint i32* %29 to i32
%31 = add nsw i32 %30, 3
%32 = and i32 %31, -4
%33 = sext i32 %32 to i64
%34 = inttoptr i64 %33 to i64*
store i64 %26, i64* %34
%35 = load i8*, i8** %3
%36 = load i8**, i8*** %4
store i8* %35, i8** %36
ret void
}

LLVM IR (-O2):
define void @mem_release(i8* %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = icmp eq i8* %3, null
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 32
%7 = ptrtoint i8* %6 to i64
%8 = shl i64 %7, 32
%9 = add i64 %8, 12884901888
%10 = ashr exact i64 %9, 32
%11 = and i64 %10, -4
%12 = inttoptr i64 %11 to i64*
%13 = load i64, i64* %12
%14 = add i64 %13, 1
br label %15
15: ; preds = %5, %2
%16 = phi i64 [ %14, %5 ], [ 1, %2 ]
%17 = tail call i32 @memcpy(i8* %0, i8** %1, i32 8)
%18 = getelementptr inbounds i8, i8* %0, i64 32
%19 = ptrtoint i8* %18 to i64
%20 = shl i64 %19, 32
%21 = add i64 %20, 12884901888
%22 = ashr exact i64 %21, 32
%23 = and i64 %22, -4
%24 = inttoptr i64 %23 to i64*
store i64 %16, i64* %24
store i8* %0, i8** %1
ret void
}