#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*/ run_case(char *, int /*<<< orphan*/);
int /*<<< orphan*/ salloc_alloc_not_enough();
int /*<<< orphan*/ salloc_basic_alloc();
int /*<<< orphan*/ salloc_basic_free();
int /*<<< orphan*/ salloc_free_all();
int /*<<< orphan*/ salloc_free_join_consecutive();
int /*<<< orphan*/ salloc_free_join_head();
int /*<<< orphan*/ salloc_free_join_mid();
int /*<<< orphan*/ salloc_free_join_tail();
int /*<<< orphan*/ salloc_full_alloc();
int /*<<< orphan*/ salloc_full_free();
int /*<<< orphan*/ salloc_init_test();
int /*<<< orphan*/ salloc_multiple_alloc();
int /*<<< orphan*/ salloc_multiple_free();
int /*<<< orphan*/ salloc_overflow_alloc();
int /*<<< orphan*/ test_begin(char *);
int /*<<< orphan*/ test_end();
void salloc_test(void) {
  test_begin("salloc test");
  run_case("salloc_init_test", salloc_init_test());
  run_case("salloc_basic_alloc", salloc_basic_alloc());
  run_case("salloc_full_alloc", salloc_full_alloc());
  run_case("salloc_overflow_alloc", salloc_overflow_alloc());
  run_case("salloc_multiple_alloc", salloc_multiple_alloc());
  run_case("salloc_alloc_not_enough", salloc_alloc_not_enough());
  run_case("salloc_basic_free", salloc_basic_free());
  run_case("salloc_full_free", salloc_full_free());
  run_case("salloc_multiple_free", salloc_multiple_free());
  run_case("salloc_free_join_tail", salloc_free_join_tail());
  run_case("salloc_free_join_head", salloc_free_join_head());
  run_case("salloc_free_join_mid", salloc_free_join_mid());
  run_case("salloc_free_join_consecutive", salloc_free_join_consecutive());
  run_case("salloc_free_all", salloc_free_all());
  test_end();
}


x86 assembly (clang, -O0):
<salloc_test>:
push   %rbp
mov    %rsp,%rbp
lea    0xde5(%rip),%rdi
call   1060 <test_begin@plt>
mov    $0x0,%al
call   1040 <salloc_init_test@plt>
mov    %eax,%esi
lea    0xddc(%rip),%rdi
call   10b0 <run_case@plt>
mov    $0x0,%al
call   10d0 <salloc_basic_alloc@plt>
mov    %eax,%esi
lea    0xdd8(%rip),%rdi
call   10b0 <run_case@plt>
mov    $0x0,%al
call   10a0 <salloc_full_alloc@plt>
mov    %eax,%esi
lea    0xdd6(%rip),%rdi
call   10b0 <run_case@plt>
mov    $0x0,%al
call   1130 <salloc_overflow_alloc@plt>
mov    %eax,%esi
lea    0xdd3(%rip),%rdi
call   10b0 <run_case@plt>
mov    $0x0,%al
call   10e0 <salloc_multiple_alloc@plt>
mov    %eax,%esi
lea    0xdd4(%rip),%rdi
call   10b0 <run_case@plt>
mov    $0x0,%al
call   1050 <salloc_alloc_not_enough@plt>
mov    %eax,%esi
lea    0xdd5(%rip),%rdi
call   10b0 <run_case@plt>
mov    $0x0,%al
call   1110 <salloc_basic_free@plt>
mov    %eax,%esi
lea    0xdd8(%rip),%rdi
call   10b0 <run_case@plt>
mov    $0x0,%al
call   10f0 <salloc_full_free@plt>
mov    %eax,%esi
lea    0xdd5(%rip),%rdi
call   10b0 <run_case@plt>
mov    $0x0,%al
call   1090 <salloc_multiple_free@plt>
mov    %eax,%esi
lea    0xdd1(%rip),%rdi
call   10b0 <run_case@plt>
mov    $0x0,%al
call   1030 <salloc_free_join_tail@plt>
mov    %eax,%esi
lea    0xdd1(%rip),%rdi
call   10b0 <run_case@plt>
mov    $0x0,%al
call   1120 <salloc_free_join_head@plt>
mov    %eax,%esi
lea    0xdd2(%rip),%rdi
call   10b0 <run_case@plt>
mov    $0x0,%al
call   1080 <salloc_free_join_mid@plt>
mov    %eax,%esi
lea    0xdd3(%rip),%rdi
call   10b0 <run_case@plt>
mov    $0x0,%al
call   1070 <salloc_free_join_consecutive@plt>
mov    %eax,%esi
lea    0xdd3(%rip),%rdi
call   10b0 <run_case@plt>
mov    $0x0,%al
call   1100 <salloc_free_all@plt>
mov    %eax,%esi
lea    0xddb(%rip),%rdi
call   10b0 <run_case@plt>
mov    $0x0,%al
call   10c0 <test_end@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<salloc_test>:
push   %rax
lea    0xde8(%rip),%rdi
call   1060 <test_begin@plt>
xor    %eax,%eax
call   1040 <salloc_init_test@plt>
lea    0xde1(%rip),%rdi
mov    %eax,%esi
call   10b0 <run_case@plt>
xor    %eax,%eax
call   10d0 <salloc_basic_alloc@plt>
lea    0xddd(%rip),%rdi
mov    %eax,%esi
call   10b0 <run_case@plt>
xor    %eax,%eax
call   10a0 <salloc_full_alloc@plt>
lea    0xddb(%rip),%rdi
mov    %eax,%esi
call   10b0 <run_case@plt>
xor    %eax,%eax
call   1130 <salloc_overflow_alloc@plt>
lea    0xdd8(%rip),%rdi
mov    %eax,%esi
call   10b0 <run_case@plt>
xor    %eax,%eax
call   10e0 <salloc_multiple_alloc@plt>
lea    0xdd9(%rip),%rdi
mov    %eax,%esi
call   10b0 <run_case@plt>
xor    %eax,%eax
call   1050 <salloc_alloc_not_enough@plt>
lea    0xdda(%rip),%rdi
mov    %eax,%esi
call   10b0 <run_case@plt>
xor    %eax,%eax
call   1110 <salloc_basic_free@plt>
lea    0xddd(%rip),%rdi
mov    %eax,%esi
call   10b0 <run_case@plt>
xor    %eax,%eax
call   10f0 <salloc_full_free@plt>
lea    0xdda(%rip),%rdi
mov    %eax,%esi
call   10b0 <run_case@plt>
xor    %eax,%eax
call   1090 <salloc_multiple_free@plt>
lea    0xdd6(%rip),%rdi
mov    %eax,%esi
call   10b0 <run_case@plt>
xor    %eax,%eax
call   1030 <salloc_free_join_tail@plt>
lea    0xdd6(%rip),%rdi
mov    %eax,%esi
call   10b0 <run_case@plt>
xor    %eax,%eax
call   1120 <salloc_free_join_head@plt>
lea    0xdd7(%rip),%rdi
mov    %eax,%esi
call   10b0 <run_case@plt>
xor    %eax,%eax
call   1080 <salloc_free_join_mid@plt>
lea    0xdd8(%rip),%rdi
mov    %eax,%esi
call   10b0 <run_case@plt>
xor    %eax,%eax
call   1070 <salloc_free_join_consecutive@plt>
lea    0xdd8(%rip),%rdi
mov    %eax,%esi
call   10b0 <run_case@plt>
xor    %eax,%eax
call   1100 <salloc_free_all@plt>
lea    0xde0(%rip),%rdi
mov    %eax,%esi
call   10b0 <run_case@plt>
xor    %eax,%eax
pop    %rcx
jmp    10c0 <test_end@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"salloc test\00"
@.str.1 = [17 x i8] c"salloc_init_test\00"
@.str.2 = [19 x i8] c"salloc_basic_alloc\00"
@.str.3 = [18 x i8] c"salloc_full_alloc\00"
@.str.4 = [22 x i8] c"salloc_overflow_alloc\00"
@.str.5 = [22 x i8] c"salloc_multiple_alloc\00"
@.str.6 = [24 x i8] c"salloc_alloc_not_enough\00"
@.str.7 = [18 x i8] c"salloc_basic_free\00"
@.str.8 = [17 x i8] c"salloc_full_free\00"
@.str.9 = [21 x i8] c"salloc_multiple_free\00"
@.str.10 = [22 x i8] c"salloc_free_join_tail\00"
@.str.11 = [22 x i8] c"salloc_free_join_head\00"
@.str.12 = [21 x i8] c"salloc_free_join_mid\00"
@.str.13 = [29 x i8] c"salloc_free_join_consecutive\00"
@.str.14 = [16 x i8] c"salloc_free_all\00"
define void @salloc_test() {
%1 = call i32 @test_begin(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%2 = call i32 (...) @salloc_init_test()
%3 = call i32 @run_case(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = call i32 (...) @salloc_basic_alloc()
%5 = call i32 @run_case(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %4)
%6 = call i32 (...) @salloc_full_alloc()
%7 = call i32 @run_case(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %6)
%8 = call i32 (...) @salloc_overflow_alloc()
%9 = call i32 @run_case(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %8)
%10 = call i32 (...) @salloc_multiple_alloc()
%11 = call i32 @run_case(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %10)
%12 = call i32 (...) @salloc_alloc_not_enough()
%13 = call i32 @run_case(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %12)
%14 = call i32 (...) @salloc_basic_free()
%15 = call i32 @run_case(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %14)
%16 = call i32 (...) @salloc_full_free()
%17 = call i32 @run_case(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %16)
%18 = call i32 (...) @salloc_multiple_free()
%19 = call i32 @run_case(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i32 %18)
%20 = call i32 (...) @salloc_free_join_tail()
%21 = call i32 @run_case(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i32 %20)
%22 = call i32 (...) @salloc_free_join_head()
%23 = call i32 @run_case(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i32 %22)
%24 = call i32 (...) @salloc_free_join_mid()
%25 = call i32 @run_case(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0), i32 %24)
%26 = call i32 (...) @salloc_free_join_consecutive()
%27 = call i32 @run_case(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0), i32 %26)
%28 = call i32 (...) @salloc_free_all()
%29 = call i32 @run_case(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.14, i64 0, i64 0), i32 %28)
%30 = call i32 (...) @test_end()
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"salloc test\00"
@.str.1 = [17 x i8] c"salloc_init_test\00"
@.str.2 = [19 x i8] c"salloc_basic_alloc\00"
@.str.3 = [18 x i8] c"salloc_full_alloc\00"
@.str.4 = [22 x i8] c"salloc_overflow_alloc\00"
@.str.5 = [22 x i8] c"salloc_multiple_alloc\00"
@.str.6 = [24 x i8] c"salloc_alloc_not_enough\00"
@.str.7 = [18 x i8] c"salloc_basic_free\00"
@.str.8 = [17 x i8] c"salloc_full_free\00"
@.str.9 = [21 x i8] c"salloc_multiple_free\00"
@.str.10 = [22 x i8] c"salloc_free_join_tail\00"
@.str.11 = [22 x i8] c"salloc_free_join_head\00"
@.str.12 = [21 x i8] c"salloc_free_join_mid\00"
@.str.13 = [29 x i8] c"salloc_free_join_consecutive\00"
@.str.14 = [16 x i8] c"salloc_free_all\00"
define void @salloc_test() {
%1 = tail call i32 @test_begin(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (...) @salloc_init_test()
%3 = tail call i32 @run_case(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = tail call i32 (...) @salloc_basic_alloc()
%5 = tail call i32 @run_case(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %4)
%6 = tail call i32 (...) @salloc_full_alloc()
%7 = tail call i32 @run_case(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %6)
%8 = tail call i32 (...) @salloc_overflow_alloc()
%9 = tail call i32 @run_case(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %8)
%10 = tail call i32 (...) @salloc_multiple_alloc()
%11 = tail call i32 @run_case(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %10)
%12 = tail call i32 (...) @salloc_alloc_not_enough()
%13 = tail call i32 @run_case(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %12)
%14 = tail call i32 (...) @salloc_basic_free()
%15 = tail call i32 @run_case(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %14)
%16 = tail call i32 (...) @salloc_full_free()
%17 = tail call i32 @run_case(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %16)
%18 = tail call i32 (...) @salloc_multiple_free()
%19 = tail call i32 @run_case(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i32 %18)
%20 = tail call i32 (...) @salloc_free_join_tail()
%21 = tail call i32 @run_case(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i32 %20)
%22 = tail call i32 (...) @salloc_free_join_head()
%23 = tail call i32 @run_case(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i32 %22)
%24 = tail call i32 (...) @salloc_free_join_mid()
%25 = tail call i32 @run_case(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0), i32 %24)
%26 = tail call i32 (...) @salloc_free_join_consecutive()
%27 = tail call i32 @run_case(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0), i32 %26)
%28 = tail call i32 (...) @salloc_free_all()
%29 = tail call i32 @run_case(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.14, i64 0, i64 0), i32 %28)
%30 = tail call i32 (...) @test_end()
ret void
}