#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*/ exit(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ tlsf_free(int *);
int *tlsf_malloc(int);
int main(void) {
  int *ptr[100];
  int i;
  for (i = 0; i < 100; i++)
    if (!(ptr[i] = tlsf_malloc(1024))) {
      printf("Error\n");
      exit(-1);
    }
  for (i = 0; i < 100; i++)
    tlsf_free(ptr[i]);
  printf("Test OK\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x334(%rbp)
cmpl   $0x64,-0x334(%rbp)
jge    11bb <main+0x7b>
mov    $0x400,%edi
call   1030 <tlsf_malloc@plt>
movslq -0x334(%rbp),%rcx
mov    %rax,-0x330(%rbp,%rcx,8)
ff
cmp    $0x0,%rax
jne    11a2 <main+0x62>
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jmp    11a7 <main+0x67>
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x334(%rbp)
jmp    115c <main+0x1c>
movl   $0x0,-0x334(%rbp)
cmpl   $0x64,-0x334(%rbp)
jge    11fa <main+0xba>
movslq -0x334(%rbp),%rax
mov    -0x330(%rbp,%rax,8),%rdi
ff
call   1050 <tlsf_free@plt>
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x334(%rbp)
jmp    11c5 <main+0x85>
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x320,%rsp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x400,%edi
call   1040 <tlsf_malloc@plt>
mov    %rax,(%rsp,%rbx,8)
test   %rax,%rax
je     1196 <main+0x56>
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1150 <main+0x10>
xor    %ebx,%ebx
nop
mov    (%rsp,%rbx,8),%rdi
call   1050 <tlsf_free@plt>
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1170 <main+0x30>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>
lea    0xe6b(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"Error\0A\00"
@.str.1 = [9 x i8] c"Test OK\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32*]
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %4
4: ; preds = %17, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 100
br i1 %6, label %7, label %20
7: ; preds = %4
%8 = call i32* @tlsf_malloc(i32 1024)
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [100 x i32*], [100 x i32*]* %2, i64 0, i64 %10
store i32* %8, i32** %11
%12 = icmp ne i32* %8, null
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %7
br label %17
17: ; preds = %16
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %4
20: ; preds = %4
store i32 0, i32* %3
br label %21
21: ; preds = %30, %20
%22 = load i32, i32* %3
%23 = icmp slt i32 %22, 100
br i1 %23, label %24, label %33
24: ; preds = %21
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i32*], [100 x i32*]* %2, i64 0, i64 %26
%28 = load i32*, i32** %27
%29 = call i32 @tlsf_free(i32* %28)
br label %30
30: ; preds = %24
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %21
33: ; preds = %21
%34 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@str = [8 x i8] c"Test OK\00"
@str.2 = [6 x i8] c"Error\00"
define i32 @main() {
%1 = alloca [100 x i32*]
%2 = bitcast [100 x i32*]* %1 to i8*
br label %6
3: ; preds = %6
%4 = add nuw nsw i64 %7, 1
%5 = icmp eq i64 %4, 100
br i1 %5, label %14, label %6
6: ; preds = %0, %3
%7 = phi i64 [ 0, %0 ], [ %4, %3 ]
%8 = tail call i32* @tlsf_malloc(i32 1024)
%9 = getelementptr inbounds [100 x i32*], [100 x i32*]* %1, i64 0, i64 %7
store i32* %8, i32** %9
%10 = icmp eq i32* %8, null
br i1 %10, label %11, label %3
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.2, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %3, %14
%15 = phi i64 [ %19, %14 ], [ 0, %3 ]
%16 = getelementptr inbounds [100 x i32*], [100 x i32*]* %1, i64 0, i64 %15
%17 = load i32*, i32** %16
%18 = tail call i32 @tlsf_free(i32* %17)
%19 = add nuw nsw i64 %15, 1
%20 = icmp eq i64 %19, 100
br i1 %20, label %21, label %14
21: ; preds = %14
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%23 = tail call i32 @exit(i32 0)
unreachable
}