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

/* Variables and functions */
int /*<<< orphan*/ Rfree(void *, char *);
char *Rmalloc(unsigned int, char *);
char *Rrealloc(char *, int, char *);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
unsigned int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void Test4(void) {
  unsigned int u;
  int i;
  char *bla[1000];
  unsigned int count = 1000;
  char *foo[20];
  void *pending;
  memset(bla, 0, sizeof(bla));
  srand(time(NULL));
  while (count > 0) {
    u = (u + rand()) % 1000;
    if (bla[u] == NULL) {
      bla[u] =
          Rmalloc((u + 1), "/scratch/repos/new/home/jordi_armengol_estape/"
                           "c-scraper/outputs/2022-01-22/02-19-57/repos/Tathar/"
                           "roclick/refs/heads/master/src/rmalloc/rtest.c"
                           ":"
                           "218");
      assert(bla[u] != NULL);
      count--;
    }
  }
  for (i = 1000 - 1; i >= 0; i--) {
    bla[i] = Rrealloc((bla[i]), (2 * i + 2),
                      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/Tathar/roclick/refs/"
                      "heads/master/src/rmalloc/rtest.c"
                      ":"
                      "225");
  }
  pending = bla[0];
  count = 1000;
  while (count > 0) {
    u = (u + rand()) % 1000;
    if (bla[u] != NULL) {
      Rfree((bla[u]), "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/Tathar/roclick/refs/"
                      "heads/master/src/rmalloc/rtest.c"
                      ":"
                      "234");
      bla[u] = NULL;
      count--;
    }
  }
  Rfree((pending), "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/Tathar/roclick/refs/"
                   "heads/master/src/rmalloc/rtest.c"
                   ":"
                   "240");
}


x86 assembly (clang, -O0):
<Test4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2010,%rsp
movl   $0x3e8,-0x1f54(%rbp)
lea    -0x1f50(%rbp),%rdi
xor    %esi,%esi
mov    $0x1f40,%edx
call   1060 <memset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
cmpl   $0x0,-0x1f54(%rbp)
jbe    124a <Test4+0xca>
mov    -0x4(%rbp),%eax
mov    %eax,-0x200c(%rbp)
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,%ecx
mov    -0x200c(%rbp),%eax
add    %ecx,%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmpq   $0x0,-0x1f50(%rbp,%rax,8)
jne    1245 <Test4+0xc5>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    0xdf6(%rip),%rsi
call   1040 <Rmalloc@plt>
mov    %rax,%rcx
mov    -0x4(%rbp),%eax
mov    %rcx,-0x1f50(%rbp,%rax,8)
ff
mov    -0x4(%rbp),%eax
cmpq   $0x0,-0x1f50(%rbp,%rax,8)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x1f54(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1f54(%rbp)
jmp    11b8 <Test4+0x38>
movl   $0x3e7,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1299 <Test4+0x119>
movslq -0x8(%rbp),%rax
mov    -0x1f50(%rbp,%rax,8),%rdi
ff
mov    -0x8(%rbp),%esi
shl    $0x1,%esi
add    $0x2,%esi
lea    0xe1c(%rip),%rdx
call   1030 <Rrealloc@plt>
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
mov    %rcx,-0x1f50(%rbp,%rax,8)
ff
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1251 <Test4+0xd1>
mov    -0x1f50(%rbp),%rax
mov    %rax,-0x2008(%rbp)
movl   $0x3e8,-0x1f54(%rbp)
cmpl   $0x0,-0x1f54(%rbp)
jbe    1330 <Test4+0x1b0>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2010(%rbp)
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,%ecx
mov    -0x2010(%rbp),%eax
add    %ecx,%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmpq   $0x0,-0x1f50(%rbp,%rax,8)
je     132b <Test4+0x1ab>
mov    -0x4(%rbp),%eax
mov    -0x1f50(%rbp,%rax,8),%rdi
lea    0xe1e(%rip),%rsi
call   1050 <Rfree@plt>
mov    -0x4(%rbp),%eax
movq   $0x0,-0x1f50(%rbp,%rax,8)
mov    -0x1f54(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1f54(%rbp)
jmp    12b1 <Test4+0x131>
mov    -0x2008(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1050 <Rfree@plt>
add    $0x2010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Test4>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1f48,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x1f40,%edx
call   1060 <memset@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    $0x3e8,%ebp
lea    0xe4a(%rip),%rbx
jmp    11c4 <Test4+0x44>
nopl   0x0(%rax,%rax,1)
test   %ebp,%ebp
je     120f <Test4+0x8f>
xor    %eax,%eax
call   10a0 <rand@plt>
add    %r15d,%eax
imul   $0x10624dd3,%rax,%rcx
shr    $0x26,%rcx
imul   $0x3e8,%ecx,%ecx
mov    %eax,%r15d
sub    %ecx,%r15d
cmpq   $0x0,(%rsp,%r15,8)
jne    11c0 <Test4+0x40>
lea    0x1(%r15),%edi
mov    %rbx,%rsi
call   1040 <Rmalloc@plt>
mov    %rax,(%rsp,%r15,8)
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1080 <assert@plt>
add    $0xffffffff,%ebp
jmp    11c0 <Test4+0x40>
mov    $0x7d0,%ebx
lea    0xe78(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    -0x8(%rsp,%rbx,4),%rdi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <Rrealloc@plt>
mov    %rax,-0x8(%rsp,%rbx,4)
add    $0xfffffffffffffffe,%rbx
jne    1220 <Test4+0xa0>
mov    $0x3e8,%ebp
mov    (%rsp),%r14
lea    0xedc(%rip),%rbx
jmp    1254 <Test4+0xd4>
nopl   0x0(%rax)
test   %ebp,%ebp
je     1293 <Test4+0x113>
xor    %eax,%eax
call   10a0 <rand@plt>
add    %r15d,%eax
imul   $0x10624dd3,%rax,%rcx
shr    $0x26,%rcx
imul   $0x3e8,%ecx,%ecx
mov    %eax,%r15d
sub    %ecx,%r15d
mov    (%rsp,%r15,8),%rdi
test   %rdi,%rdi
je     1250 <Test4+0xd0>
mov    %rbx,%rsi
call   1050 <Rfree@plt>
movq   $0x0,(%rsp,%r15,8)
add    $0xffffffff,%ebp
jmp    1250 <Test4+0xd0>
lea    0xf1f(%rip),%rsi
mov    %r14,%rdi
call   1050 <Rfree@plt>
add    $0x1f48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Tathar/roclick/refs/heads/master/src/rmalloc/rtest.c:218\00"
@.str.1 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Tathar/roclick/refs/heads/master/src/rmalloc/rtest.c:225\00"
@.str.2 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Tathar/roclick/refs/heads/master/src/rmalloc/rtest.c:234\00"
@.str.3 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Tathar/roclick/refs/heads/master/src/rmalloc/rtest.c:240\00"
define void @Test4() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1000 x i8*]
%4 = alloca i32
%5 = alloca [20 x i8*]
%6 = alloca i8*
store i32 1000, i32* %4
%7 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %3, i64 0, i64 0
%8 = call i32 @memset(i8** %7, i32 0, i32 8000)
%9 = call i32 @time(i32* null)
%10 = call i32 @srand(i32 %9)
br label %11
11: ; preds = %40, %0
%12 = load i32, i32* %4
%13 = icmp ugt i32 %12, 0
br i1 %13, label %14, label %41
14: ; preds = %11
%15 = load i32, i32* %1
%16 = call i32 (...) @rand()
%17 = add i32 %15, %16
%18 = urem i32 %17, 1000
store i32 %18, i32* %1
%19 = load i32, i32* %1
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %3, i64 0, i64 %20
%22 = load i8*, i8** %21
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %40
24: ; preds = %14
%25 = load i32, i32* %1
%26 = add i32 %25, 1
%27 = call i8* @Rmalloc(i32 %26, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* %1
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %3, i64 0, i64 %29
store i8* %27, i8** %30
%31 = load i32, i32* %1
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %3, i64 0, i64 %32
%34 = load i8*, i8** %33
%35 = icmp ne i8* %34, null
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i32, i32* %4
%39 = add i32 %38, -1
store i32 %39, i32* %4
br label %40
40: ; preds = %24, %14
br label %11
41: ; preds = %11
store i32 999, i32* %2
br label %42
42: ; preds = %57, %41
%43 = load i32, i32* %2
%44 = icmp sge i32 %43, 0
br i1 %44, label %45, label %60
45: ; preds = %42
%46 = load i32, i32* %2
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %3, i64 0, i64 %47
%49 = load i8*, i8** %48
%50 = load i32, i32* %2
%51 = mul nsw i32 2, %50
%52 = add nsw i32 %51, 2
%53 = call i8* @Rrealloc(i8* %49, i32 %52, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0))
%54 = load i32, i32* %2
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %3, i64 0, i64 %55
store i8* %53, i8** %56
br label %57
57: ; preds = %45
%58 = load i32, i32* %2
%59 = add nsw i32 %58, -1
store i32 %59, i32* %2
br label %42
60: ; preds = %42
%61 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %3, i64 0, i64 0
%62 = load i8*, i8** %61
store i8* %62, i8** %6
store i32 1000, i32* %4
br label %63
63: ; preds = %87, %60
%64 = load i32, i32* %4
%65 = icmp ugt i32 %64, 0
br i1 %65, label %66, label %88
66: ; preds = %63
%67 = load i32, i32* %1
%68 = call i32 (...) @rand()
%69 = add i32 %67, %68
%70 = urem i32 %69, 1000
store i32 %70, i32* %1
%71 = load i32, i32* %1
%72 = zext i32 %71 to i64
%73 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %3, i64 0, i64 %72
%74 = load i8*, i8** %73
%75 = icmp ne i8* %74, null
br i1 %75, label %76, label %87
76: ; preds = %66
%77 = load i32, i32* %1
%78 = zext i32 %77 to i64
%79 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %3, i64 0, i64 %78
%80 = load i8*, i8** %79
%81 = call i32 @Rfree(i8* %80, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0))
%82 = load i32, i32* %1
%83 = zext i32 %82 to i64
%84 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %3, i64 0, i64 %83
store i8* null, i8** %84
%85 = load i32, i32* %4
%86 = add i32 %85, -1
store i32 %86, i32* %4
br label %87
87: ; preds = %76, %66
br label %63
88: ; preds = %63
%89 = load i8*, i8** %6
%90 = call i32 @Rfree(i8* %89, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Tathar/roclick/refs/heads/master/src/rmalloc/rtest.c:218\00"
@.str.1 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Tathar/roclick/refs/heads/master/src/rmalloc/rtest.c:225\00"
@.str.2 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Tathar/roclick/refs/heads/master/src/rmalloc/rtest.c:234\00"
@.str.3 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Tathar/roclick/refs/heads/master/src/rmalloc/rtest.c:240\00"
define void @Test4() {
%1 = alloca [1000 x i8*]
%2 = bitcast [1000 x i8*]* %1 to i8*
%3 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %1, i64 0, i64 0
%4 = call i32 @memset(i8** %3, i32 0, i32 8000)
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
br label %7
7: ; preds = %0, %24
%8 = phi i32 [ undef, %0 ], [ %12, %24 ]
%9 = phi i32 [ 1000, %0 ], [ %25, %24 ]
%10 = call i32 (...) @rand()
%11 = add i32 %10, %8
%12 = urem i32 %11, 1000
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %1, i64 0, i64 %13
%15 = load i8*, i8** %14
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %24
17: ; preds = %7
%18 = add nuw nsw i32 %12, 1
%19 = call i8* @Rmalloc(i32 %18, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %14
%20 = icmp ne i8* %19, null
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = add i32 %9, -1
br label %24
24: ; preds = %17, %7
%25 = phi i32 [ %23, %17 ], [ %9, %7 ]
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %7
27: ; preds = %24, %27
%28 = phi i64 [ %35, %27 ], [ 999, %24 ]
%29 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %1, i64 0, i64 %28
%30 = load i8*, i8** %29
%31 = trunc i64 %28 to i32
%32 = shl i32 %31, 1
%33 = add i32 %32, 2
%34 = call i8* @Rrealloc(i8* %30, i32 %33, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0))
store i8* %34, i8** %29
%35 = add nsw i64 %28, -1
%36 = icmp eq i64 %28, 0
br i1 %36, label %37, label %27
37: ; preds = %27
%38 = load i8*, i8** %3
br label %39
39: ; preds = %37, %52
%40 = phi i32 [ %12, %37 ], [ %44, %52 ]
%41 = phi i32 [ 1000, %37 ], [ %53, %52 ]
%42 = call i32 (...) @rand()
%43 = add i32 %42, %40
%44 = urem i32 %43, 1000
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %1, i64 0, i64 %45
%47 = load i8*, i8** %46
%48 = icmp eq i8* %47, null
br i1 %48, label %52, label %49
49: ; preds = %39
%50 = call i32 @Rfree(i8* %47, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %46
%51 = add i32 %41, -1
br label %52
52: ; preds = %49, %39
%53 = phi i32 [ %51, %49 ], [ %41, %39 ]
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %39
55: ; preds = %52
%56 = call i32 @Rfree(i8* %38, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.3, i64 0, i64 0))
ret void
}