#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ st_aligned_free(char *);
scalar_t__ st_aligned_malloc_impl(size_t, int);
scalar_t__ st_aligned_realloc_impl(char *, int, int);
int /*<<< orphan*/ st_free(char *);
scalar_t__ st_malloc_impl(size_t);
int /*<<< orphan*/ st_mem_usage_destroy();
scalar_t__ st_mem_usage_init();
int /*<<< orphan*/ st_mem_usage_report();
scalar_t__ st_realloc_impl(char *, int);
int /*<<< orphan*/ stderr;
int unit_test_st_mem_usage() {
  char *ptr = NULL;
  size_t size = 123;
  int ncase;
  fprintf(stderr, " Testing st_mem_usage...\n");
  if (st_mem_usage_init() < 0) {
    fprintf(stderr, "Failed\n");
    return -1;
  }
  ncase = 1;
  fprintf(stderr, "    Case %d...", ncase++);
  ptr = (char *)st_malloc_impl(size);
  if (ptr == NULL) {
    fprintf(stderr, "Failed\n");
    goto FAILED;
  }
  ptr = (char *)st_realloc_impl(ptr, 2 * size);
  if (ptr == NULL) {
    fprintf(stderr, "Failed\n");
    goto FAILED;
  }
  st_free(ptr);
  ptr = (char *)st_aligned_malloc_impl(size, 32);
  if (ptr == NULL) {
    fprintf(stderr, "Failed\n");
    goto FAILED;
  }
  ptr = (char *)st_aligned_realloc_impl(ptr, 3 * size, 32);
  if (ptr == NULL) {
    fprintf(stderr, "Failed\n");
    goto FAILED;
  }
  st_aligned_free(ptr);
  st_mem_usage_report();
  st_mem_usage_destroy();
  return 0;
FAILED:
  st_mem_usage_destroy();
  return -1;
}


x86 assembly (clang, -O0):
<unit_test_st_mem_usage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x7b,-0x18(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x0,%al
call   10b0 <st_mem_usage_init@plt>
cmp    $0x0,%rax
jge    1203 <unit_test_st_mem_usage+0x63>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1351 <unit_test_st_mem_usage+0x1b1>
movl   $0x1,-0x1c(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <st_malloc_impl@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1260 <unit_test_st_mem_usage+0xc0>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1343 <unit_test_st_mem_usage+0x1a3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %eax,%esi
call   1060 <st_realloc_impl@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    129e <unit_test_st_mem_usage+0xfe>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
lea    0xd88(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1343 <unit_test_st_mem_usage+0x1a3>
mov    -0x10(%rbp),%rdi
call   1090 <st_free@plt>
mov    -0x18(%rbp),%rdi
mov    $0x20,%esi
call   1070 <st_aligned_malloc_impl@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    12e0 <unit_test_st_mem_usage+0x140>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    0xd46(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1343 <unit_test_st_mem_usage+0x1a3>
mov    -0x10(%rbp),%rdi
imul   $0x3,-0x18(%rbp),%rax
mov    %eax,%esi
mov    $0x20,%edx
call   10c0 <st_aligned_realloc_impl@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1320 <unit_test_st_mem_usage+0x180>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
lea    0xd06(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1343 <unit_test_st_mem_usage+0x1a3>
mov    -0x10(%rbp),%rdi
call   1040 <st_aligned_free@plt>
mov    $0x0,%al
call   1080 <st_mem_usage_report@plt>
mov    $0x0,%al
call   10a0 <st_mem_usage_destroy@plt>
movl   $0x0,-0x4(%rbp)
jmp    1351 <unit_test_st_mem_usage+0x1b1>
mov    $0x0,%al
call   10a0 <st_mem_usage_destroy@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unit_test_st_mem_usage>:
push   %rbx
mov    0x2e38(%rip),%rbx
mov    (%rbx),%edi
lea    0xe4f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
call   10b0 <st_mem_usage_init@plt>
mov    (%rbx),%edi
test   %rax,%rax
js     1264 <unit_test_st_mem_usage+0xc4>
lea    0xe51(%rip),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x7b,%edi
call   1030 <st_malloc_impl@plt>
test   %rax,%rax
je     124b <unit_test_st_mem_usage+0xab>
mov    %rax,%rdi
mov    $0xf6,%esi
call   1060 <st_realloc_impl@plt>
test   %rax,%rax
je     124b <unit_test_st_mem_usage+0xab>
mov    %rax,%rdi
call   1090 <st_free@plt>
mov    $0x7b,%edi
mov    $0x20,%esi
call   1070 <st_aligned_malloc_impl@plt>
test   %rax,%rax
je     124b <unit_test_st_mem_usage+0xab>
mov    %rax,%rdi
mov    $0x171,%esi
mov    $0x20,%edx
call   10c0 <st_aligned_realloc_impl@plt>
test   %rax,%rax
je     124b <unit_test_st_mem_usage+0xab>
mov    %rax,%rdi
call   1040 <st_aligned_free@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <st_mem_usage_report@plt>
xor    %eax,%eax
call   10a0 <st_mem_usage_destroy@plt>
jmp    1277 <unit_test_st_mem_usage+0xd7>
mov    (%rbx),%edi
lea    0xdc6(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
call   10a0 <st_mem_usage_destroy@plt>
jmp    1272 <unit_test_st_mem_usage+0xd2>
lea    0xdaf(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c" Testing st_mem_usage...\0A\00"
@.str.1 = [8 x i8] c"Failed\0A\00"
@.str.2 = [15 x i8] c" Case %d...\00"
define i32 @unit_test_st_mem_usage() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
store i8* null, i8** %2
store i64 123, i64* %3
%5 = load i32, i32* @stderr
%6 = call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = call i64 (...) @st_mem_usage_init()
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %67
12: ; preds = %0
store i32 1, i32* %4
%13 = load i32, i32* @stderr
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%17 = load i64, i64* %3
%18 = call i64 @st_malloc_impl(i64 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %2
%20 = load i8*, i8** %2
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %12
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %65
25: ; preds = %12
%26 = load i8*, i8** %2
%27 = load i64, i64* %3
%28 = mul i64 2, %27
%29 = trunc i64 %28 to i32
%30 = call i64 @st_realloc_impl(i8* %26, i32 %29)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %2
%32 = load i8*, i8** %2
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %25
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %65
37: ; preds = %25
%38 = load i8*, i8** %2
%39 = call i32 @st_free(i8* %38)
%40 = load i64, i64* %3
%41 = call i64 @st_aligned_malloc_impl(i64 %40, i32 32)
%42 = inttoptr i64 %41 to i8*
store i8* %42, i8** %2
%43 = load i8*, i8** %2
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %48
45: ; preds = %37
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %65
48: ; preds = %37
%49 = load i8*, i8** %2
%50 = load i64, i64* %3
%51 = mul i64 3, %50
%52 = trunc i64 %51 to i32
%53 = call i64 @st_aligned_realloc_impl(i8* %49, i32 %52, i32 32)
%54 = inttoptr i64 %53 to i8*
store i8* %54, i8** %2
%55 = load i8*, i8** %2
%56 = icmp eq i8* %55, null
br i1 %56, label %57, label %60
57: ; preds = %48
%58 = load i32, i32* @stderr
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %65
60: ; preds = %48
%61 = load i8*, i8** %2
%62 = call i32 @st_aligned_free(i8* %61)
%63 = call i32 (...) @st_mem_usage_report()
%64 = call i32 (...) @st_mem_usage_destroy()
store i32 0, i32* %1
br label %67
65: ; preds = %57, %45, %34, %22
%66 = call i32 (...) @st_mem_usage_destroy()
store i32 -1, i32* %1
br label %67
67: ; preds = %65, %60, %9
%68 = load i32, i32* %1
ret i32 %68
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c" Testing st_mem_usage...\0A\00"
@.str.1 = [8 x i8] c"Failed\0A\00"
@.str.2 = [15 x i8] c" Case %d...\00"
define i32 @unit_test_st_mem_usage() {
%1 = load i32, i32* @stderr
%2 = tail call i32 (i32, i8*, ...) @fprintf(i32 %1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%3 = tail call i64 (...) @st_mem_usage_init()
%4 = icmp slt i64 %3, 0
%5 = load i32, i32* @stderr
br i1 %4, label %6, label %8
6: ; preds = %0
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %34
8: ; preds = %0
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 1)
%10 = tail call i64 @st_malloc_impl(i64 123)
%11 = icmp eq i64 %10, 0
br i1 %11, label %30, label %12
12: ; preds = %8
%13 = inttoptr i64 %10 to i8*
%14 = tail call i64 @st_realloc_impl(i8* %13, i32 246)
%15 = icmp eq i64 %14, 0
br i1 %15, label %30, label %16
16: ; preds = %12
%17 = inttoptr i64 %14 to i8*
%18 = tail call i32 @st_free(i8* %17)
%19 = tail call i64 @st_aligned_malloc_impl(i64 123, i32 32)
%20 = icmp eq i64 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %16
%22 = inttoptr i64 %19 to i8*
%23 = tail call i64 @st_aligned_realloc_impl(i8* %22, i32 369, i32 32)
%24 = icmp eq i64 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %21
%26 = inttoptr i64 %23 to i8*
%27 = tail call i32 @st_aligned_free(i8* %26)
%28 = tail call i32 (...) @st_mem_usage_report()
%29 = tail call i32 (...) @st_mem_usage_destroy()
br label %34
30: ; preds = %21, %16, %12, %8
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%33 = tail call i32 (...) @st_mem_usage_destroy()
br label %34
34: ; preds = %30, %25, %6
%35 = phi i32 [ -1, %6 ], [ -1, %30 ], [ 0, %25 ]
ret i32 %35
}