#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*/ da_trash(int *, int *, void ***);
int /*<<< orphan*/ nocc_pinternal(char *, char *, int, int);
scalar_t__ smalloc(int);
scalar_t__ srealloc(void *, int, int);
void da_setsize(int *cur, int *max, void ***array, int size) {
  if (size < 0) {
    nocc_pinternal(("dynarray_setsize to %d"),
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/concurrency/nocc/refs/"
                   "heads/master/misc/support.c",
                   1279, size);
  } else if (!size) {
    da_trash(cur, max, array);
  } else {
    if (*max == 0) {
      *array = (void **)smalloc(size * sizeof(void *));
      *max = size;
      *cur = size;
    } else if (size > *max) {
      *array = (void **)srealloc((void *)(*array), *max * sizeof(void *),
                                 size * sizeof(void *));
      *max = size;
      *cur = size;
    } else {
      *cur = size;
    }
  }
}


x86 assembly (clang, -O0):
<da_setsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1181 <da_setsize+0x41>
mov    -0x1c(%rbp),%ecx
lea    0xe95(%rip),%rdi
lea    0xea5(%rip),%rsi
mov    $0x4ff,%edx
call   1060 <nocc_pinternal@plt>
jmp    1249 <da_setsize+0x109>
cmpl   $0x0,-0x1c(%rbp)
jne    11a1 <da_setsize+0x61>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <da_trash@plt>
jmp    1244 <da_setsize+0x104>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11de <da_setsize+0x9e>
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <smalloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    123f <da_setsize+0xff>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    1231 <da_setsize+0xf1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%esi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1050 <srealloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    123a <da_setsize+0xfa>
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    123f <da_setsize+0xff>
jmp    1244 <da_setsize+0x104>
jmp    1249 <da_setsize+0x109>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<da_setsize>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
test   %ecx,%ecx
js     1179 <da_setsize+0x39>
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
je     119e <da_setsize+0x5e>
mov    (%r15),%esi
test   %esi,%esi
je     11b7 <da_setsize+0x77>
cmp    %ebx,%esi
jge    11ca <da_setsize+0x8a>
mov    (%r12),%rdi
shl    $0x3,%esi
lea    0x0(,%rbx,8),%edx
call   1050 <srealloc@plt>
jmp    11c3 <da_setsize+0x83>
lea    0xe80(%rip),%rdi
lea    0xe90(%rip),%rsi
mov    $0x4ff,%edx
mov    %ebx,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <nocc_pinternal@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <da_trash@plt>
lea    0x0(,%rbx,8),%edi
call   1040 <smalloc@plt>
mov    %rax,(%r12)
mov    %ebx,(%r15)
mov    %ebx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"dynarray_setsize to %d\00"
@.str.1 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/concurrency/nocc/refs/heads/master/misc/support.c\00"
define void @da_setsize(i32* %0, i32* %1, i8*** %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8***
%8 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i8*** %2, i8**** %7
store i32 %3, i32* %8
%9 = load i32, i32* %8
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %4
%12 = load i32, i32* %8
%13 = call i32 @nocc_pinternal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 1279, i32 %12)
br label %69
14: ; preds = %4
%15 = load i32, i32* %8
%16 = icmp ne i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %14
%18 = load i32*, i32** %5
%19 = load i32*, i32** %6
%20 = load i8***, i8**** %7
%21 = call i32 @da_trash(i32* %18, i32* %19, i8*** %20)
br label %68
22: ; preds = %14
%23 = load i32*, i32** %6
%24 = load i32, i32* %23
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %22
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = mul i64 %28, 8
%30 = trunc i64 %29 to i32
%31 = call i64 @smalloc(i32 %30)
%32 = inttoptr i64 %31 to i8**
%33 = load i8***, i8**** %7
store i8** %32, i8*** %33
%34 = load i32, i32* %8
%35 = load i32*, i32** %6
store i32 %34, i32* %35
%36 = load i32, i32* %8
%37 = load i32*, i32** %5
store i32 %36, i32* %37
br label %67
38: ; preds = %22
%39 = load i32, i32* %8
%40 = load i32*, i32** %6
%41 = load i32, i32* %40
%42 = icmp sgt i32 %39, %41
br i1 %42, label %43, label %63
43: ; preds = %38
%44 = load i8***, i8**** %7
%45 = load i8**, i8*** %44
%46 = bitcast i8** %45 to i8*
%47 = load i32*, i32** %6
%48 = load i32, i32* %47
%49 = sext i32 %48 to i64
%50 = mul i64 %49, 8
%51 = trunc i64 %50 to i32
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = mul i64 %53, 8
%55 = trunc i64 %54 to i32
%56 = call i64 @srealloc(i8* %46, i32 %51, i32 %55)
%57 = inttoptr i64 %56 to i8**
%58 = load i8***, i8**** %7
store i8** %57, i8*** %58
%59 = load i32, i32* %8
%60 = load i32*, i32** %6
store i32 %59, i32* %60
%61 = load i32, i32* %8
%62 = load i32*, i32** %5
store i32 %61, i32* %62
br label %66
63: ; preds = %38
%64 = load i32, i32* %8
%65 = load i32*, i32** %5
store i32 %64, i32* %65
br label %66
66: ; preds = %63, %43
br label %67
67: ; preds = %66, %26
br label %68
68: ; preds = %67, %17
br label %69
69: ; preds = %68, %11
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"dynarray_setsize to %d\00"
@.str.1 = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/concurrency/nocc/refs/heads/master/misc/support.c\00"
define void @da_setsize(i32* %0, i32* %1, i8*** %2, i32 %3) {
%5 = icmp slt i32 %3, 0
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @nocc_pinternal(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i32 1279, i32 %3)
br label %29
8: ; preds = %4
%9 = icmp eq i32 %3, 0
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 @da_trash(i32* %0, i32* %1, i8*** %2)
br label %29
12: ; preds = %8
%13 = load i32, i32* %1
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = shl i32 %3, 3
%17 = tail call i64 @smalloc(i32 %16)
%18 = inttoptr i64 %17 to i8**
store i8** %18, i8*** %2
store i32 %3, i32* %1
store i32 %3, i32* %0
br label %29
19: ; preds = %12
%20 = icmp slt i32 %13, %3
br i1 %20, label %21, label %28
21: ; preds = %19
%22 = bitcast i8*** %2 to i8**
%23 = load i8*, i8** %22
%24 = shl i32 %13, 3
%25 = shl i32 %3, 3
%26 = tail call i64 @srealloc(i8* %23, i32 %24, i32 %25)
%27 = inttoptr i64 %26 to i8**
store i8** %27, i8*** %2
store i32 %3, i32* %1
store i32 %3, i32* %0
br label %29
28: ; preds = %19
store i32 %3, i32* %0
br label %29
29: ; preds = %10, %21, %28, %15, %6
ret void
}