#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*/ sizes;

/* Variables and functions */
int /*<<< orphan*/ assertEqual(size_t, int /*<<< orphan*/);
int /*<<< orphan*/ mfree(void *);
void *mmalloc(size_t);
int /*<<< orphan*/ msize(void *);
void testMalloc(void) {
  int sizes[7] = {1, 2, 3, 4, 8, 16, 32};
  void *ptr;
  size_t size;
  for (int i = 0; i < (sizeof(sizes) / sizeof(sizes[0])); i++) {
    size = 1 >> sizes[i];
    ptr = mmalloc(size);
    assertEqual(size, msize(ptr));
    mfree(ptr);
  }
}


x86 assembly (clang, -O0):
<testMalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0xeb1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeae(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeab(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xea9(%rip),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    $0x7,%rax
jae    11dc <testMalloc+0x9c>
movslq -0x34(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%ecx
mov    $0x1,%eax
sar    %cl,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <mmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <msize@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   1040 <assertEqual@plt>
mov    -0x28(%rbp),%rdi
call   1050 <mfree@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1179 <testMalloc+0x39>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testMalloc>:
push   %rbx
xor    %edi,%edi
call   1030 <mmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <msize@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1040 <assertEqual@plt>
mov    %rbx,%rdi
call   1050 <mfree@plt>
xor    %edi,%edi
call   1030 <mmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <msize@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1040 <assertEqual@plt>
mov    %rbx,%rdi
call   1050 <mfree@plt>
xor    %edi,%edi
call   1030 <mmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <msize@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1040 <assertEqual@plt>
mov    %rbx,%rdi
call   1050 <mfree@plt>
xor    %edi,%edi
call   1030 <mmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <msize@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1040 <assertEqual@plt>
mov    %rbx,%rdi
call   1050 <mfree@plt>
xor    %edi,%edi
call   1030 <mmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <msize@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1040 <assertEqual@plt>
mov    %rbx,%rdi
call   1050 <mfree@plt>
xor    %edi,%edi
call   1030 <mmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <msize@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1040 <assertEqual@plt>
mov    %rbx,%rdi
call   1050 <mfree@plt>
call   1030 <mmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <msize@plt>
mov    %eax,%esi
call   1040 <assertEqual@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <mfree@plt>

LLVM IR (-O0):
@__const.testMalloc.sizes = [7 x i32] [i32 1, i32 2, i32 3, i32 4, i32 8, i32 16, i32 32]
define void @testMalloc() {
%1 = alloca [7 x i32]
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = bitcast [7 x i32]* %1 to i8*
store i32 0, i32* %4
br label %6
6: ; preds = %25, %0
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = icmp ult i64 %8, 7
br i1 %9, label %10, label %28
10: ; preds = %6
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [7 x i32], [7 x i32]* %1, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = ashr i32 1, %14
%16 = sext i32 %15 to i64
store i64 %16, i64* %3
%17 = load i64, i64* %3
%18 = call i8* @mmalloc(i64 %17)
store i8* %18, i8** %2
%19 = load i64, i64* %3
%20 = load i8*, i8** %2
%21 = call i32 @msize(i8* %20)
%22 = call i32 @assertEqual(i64 %19, i32 %21)
%23 = load i8*, i8** %2
%24 = call i32 @mfree(i8* %23)
br label %25
25: ; preds = %10
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %6
28: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @testMalloc() {
%1 = tail call i8* @mmalloc(i64 0)
%2 = tail call i32 @msize(i8* %1)
%3 = tail call i32 @assertEqual(i64 0, i32 %2)
%4 = tail call i32 @mfree(i8* %1)
%5 = tail call i8* @mmalloc(i64 0)
%6 = tail call i32 @msize(i8* %5)
%7 = tail call i32 @assertEqual(i64 0, i32 %6)
%8 = tail call i32 @mfree(i8* %5)
%9 = tail call i8* @mmalloc(i64 0)
%10 = tail call i32 @msize(i8* %9)
%11 = tail call i32 @assertEqual(i64 0, i32 %10)
%12 = tail call i32 @mfree(i8* %9)
%13 = tail call i8* @mmalloc(i64 0)
%14 = tail call i32 @msize(i8* %13)
%15 = tail call i32 @assertEqual(i64 0, i32 %14)
%16 = tail call i32 @mfree(i8* %13)
%17 = tail call i8* @mmalloc(i64 0)
%18 = tail call i32 @msize(i8* %17)
%19 = tail call i32 @assertEqual(i64 0, i32 %18)
%20 = tail call i32 @mfree(i8* %17)
%21 = tail call i8* @mmalloc(i64 0)
%22 = tail call i32 @msize(i8* %21)
%23 = tail call i32 @assertEqual(i64 0, i32 %22)
%24 = tail call i32 @mfree(i8* %21)
%25 = tail call i8* @mmalloc(i64 poison)
%26 = tail call i32 @msize(i8* %25)
%27 = tail call i32 @assertEqual(i64 poison, i32 %26)
%28 = tail call i32 @mfree(i8* %25)
ret void
}