#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ qfits_memory_free(int *, char *, int);
int *qfits_memory_malloc(int, char *, int);
int /*<<< orphan*/ qfits_memory_status();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
void stress1(void) {
  int i;
  int *ip[100];
  for (i = 0; i < 100; i++) {
    ip[i] = qfits_memory_malloc(
        256 * 1024 * sizeof(int),
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/blackball/an-test6/refs/heads/main/"
        "qfits-6.2.0/test/test_xmem_stress.c",
        74);
    printf("\rallocated %d", i);
    fflush(stdout);
  }
  qfits_memory_status();
  sleep(1);
  for (i = (100 - 1); i >= 0; i--) {
    qfits_memory_free(ip[i],
                      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/blackball/an-test6/"
                      "refs/heads/main/qfits-6.2.0/test/test_xmem_stress.c",
                      81);
  }
}


x86 assembly (clang, -O0):
<stress1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x330,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x64,-0x4(%rbp)
jge    11cc <stress1+0x6c>
mov    $0x100000,%edi
lea    0xe78(%rip),%rsi
mov    $0x4a,%edx
call   1050 <qfits_memory_malloc@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
mov    %rcx,-0x330(%rbp,%rax,8)
ff
mov    -0x4(%rbp),%esi
lea    0xef6(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1172 <stress1+0x12>
mov    $0x0,%al
call   1040 <qfits_memory_status@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
movl   $0x63,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1219 <stress1+0xb9>
movslq -0x4(%rbp),%rax
mov    -0x330(%rbp,%rax,8),%rdi
ff
lea    0xdff(%rip),%rsi
mov    $0x51,%edx
call   1060 <qfits_memory_free@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    11e4 <stress1+0x84>
add    $0x330,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stress1>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x328,%rsp
xor    %ebx,%ebx
lea    0xe89(%rip),%r14
lea    0xf23(%rip),%r15
mov    0x2e5b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x100000,%edi
mov    %r14,%rsi
mov    $0x4a,%edx
call   1050 <qfits_memory_malloc@plt>
mov    %rax,(%rsp,%rbx,8)
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    (%r12),%edi
call   1070 <fflush@plt>
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1190 <stress1+0x30>
xor    %eax,%eax
call   1040 <qfits_memory_status@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    $0x63,%ebx
lea    0xe20(%rip),%r14
mov    (%rsp,%rbx,8),%rdi
mov    %r14,%rsi
mov    $0x51,%edx
call   1060 <qfits_memory_free@plt>
add    $0xffffffffffffffff,%rbx
jb     11e0 <stress1+0x80>
add    $0x328,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [161 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/blackball/an-test6/refs/heads/main/qfits-6.2.0/test/test_xmem_stress.c\00"
@.str.1 = [14 x i8] c"\0Dallocated %d\00"
@stdout = global i32 0
define void @stress1() {
%1 = alloca i32
%2 = alloca [100 x i32*]
store i32 0, i32* %1
br label %3
3: ; preds = %15, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 100
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = call i32* @qfits_memory_malloc(i32 1048576, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str, i64 0, i64 0), i32 74)
%8 = load i32, i32* %1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [100 x i32*], [100 x i32*]* %2, i64 0, i64 %9
store i32* %7, i32** %10
%11 = load i32, i32* %1
%12 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @stdout
%14 = call i32 @fflush(i32 %13)
br label %15
15: ; preds = %6
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 1
store i32 %17, i32* %1
br label %3
18: ; preds = %3
%19 = call i32 (...) @qfits_memory_status()
%20 = call i32 @sleep(i32 1)
store i32 99, i32* %1
br label %21
21: ; preds = %30, %18
%22 = load i32, i32* %1
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %21
%25 = load i32, i32* %1
%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 @qfits_memory_free(i32* %28, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str, i64 0, i64 0), i32 81)
br label %30
30: ; preds = %24
%31 = load i32, i32* %1
%32 = add nsw i32 %31, -1
store i32 %32, i32* %1
br label %21
33: ; preds = %21
ret void
}

LLVM IR (-O2):
@.str = [161 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/blackball/an-test6/refs/heads/main/qfits-6.2.0/test/test_xmem_stress.c\00"
@.str.1 = [14 x i8] c"\0Dallocated %d\00"
@stdout = global i32 0
define void @stress1() {
%1 = alloca [100 x i32*]
%2 = bitcast [100 x i32*]* %1 to i8*
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %11, %3 ]
%5 = tail call i32* @qfits_memory_malloc(i32 1048576, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str, i64 0, i64 0), i32 74)
%6 = getelementptr inbounds [100 x i32*], [100 x i32*]* %1, i64 0, i64 %4
store i32* %5, i32** %6
%7 = trunc i64 %4 to i32
%8 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @stdout
%10 = tail call i32 @fflush(i32 %9)
%11 = add nuw nsw i64 %4, 1
%12 = icmp eq i64 %11, 100
br i1 %12, label %13, label %3
13: ; preds = %3
%14 = tail call i32 (...) @qfits_memory_status()
%15 = tail call i32 @sleep(i32 1)
br label %16
16: ; preds = %13, %16
%17 = phi i64 [ 99, %13 ], [ %21, %16 ]
%18 = getelementptr inbounds [100 x i32*], [100 x i32*]* %1, i64 0, i64 %17
%19 = load i32*, i32** %18
%20 = tail call i32 @qfits_memory_free(i32* %19, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str, i64 0, i64 0), i32 81)
%21 = add nsw i64 %17, -1
%22 = icmp eq i64 %17, 0
br i1 %22, label %23, label %16
23: ; preds = %16
ret void
}