#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int *malloc(int);
void *realloc(int *, int);
int /*<<< orphan*/ stderr;
int add_entry(uint32_t **net, uint32_t new_idx) {
  if (!*net) {
    *net = malloc(16 * sizeof(**net));
    if (!(*net)) {
      fprintf(stderr, "Out of memory in %s:%i\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/DeanoC/fpgatools/refs/heads/master/"
              "pair2net.c",
              25);
      return -1;
    }
    **net = 1;
  } else {
    uint32_t num_entries = **net;
    if (!(num_entries % 16)) {
      void *new_ptr = realloc(*net, (num_entries + 16) * sizeof(**net));
      if (!new_ptr) {
        fprintf(stderr, "Out of memory in %s:%i\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/DeanoC/fpgatools/refs/heads/"
                "master/pair2net.c",
                36);
        return -1;
      }
      *net = new_ptr;
    }
  }
  (*net)[**net] = new_idx;
  (**net)++;
  return 0;
}


x86 assembly (clang, -O0):
<add_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11ae <add_entry+0x7e>
mov    $0x40,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    119c <add_entry+0x6c>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe81(%rip),%rsi
lea    0xe92(%rip),%rdx
mov    $0x19,%ecx
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1260 <add_entry+0x130>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movl   $0x1,(%rax)
jmp    1234 <add_entry+0x104>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    122f <add_entry+0xff>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%eax
add    $0x10,%eax
cltq
shl    $0x2,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1224 <add_entry+0xf4>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
lea    0xe0a(%rip),%rdx
mov    $0x24,%ecx
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1260 <add_entry+0x130>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1234 <add_entry+0x104>
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
movslq (%rcx),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_entry>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    (%rdi),%rax
test   %rax,%rax
je     1162 <add_entry+0x32>
mov    (%rax),%ecx
test   $0xf,%cl
jne    117f <add_entry+0x4f>
lea    0x40(,%rcx,4),%esi
mov    %rax,%rdi
call   1050 <realloc@plt>
test   %rax,%rax
je     11aa <add_entry+0x7a>
mov    %rax,(%rbx)
mov    (%rax),%ecx
jmp    117f <add_entry+0x4f>
mov    $0x40,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     118c <add_entry+0x5c>
movl   $0x1,(%rax)
mov    $0x1,%ecx
movslq %ecx,%rcx
mov    %ebp,(%rax,%rcx,4)
addl   $0x1,(%rax)
xor    %eax,%eax
jmp    11d0 <add_entry+0xa0>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
lea    0xe75(%rip),%rdx
mov    $0x19,%ecx
jmp    11c6 <add_entry+0x96>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
lea    0xe57(%rip),%rdx
mov    $0x24,%ecx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Out of memory in %s:%i\0A\00"
@.str.1 = [136 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/DeanoC/fpgatools/refs/heads/master/pair2net.c\00"
define i32 @add_entry(i32** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i32** %0, i32*** %4
store i32 %1, i32* %5
%8 = load i32**, i32*** %4
%9 = load i32*, i32** %8
%10 = icmp ne i32* %9, null
br i1 %10, label %23, label %11
11: ; preds = %2
%12 = call i32* @malloc(i32 64)
%13 = load i32**, i32*** %4
store i32* %12, i32** %13
%14 = load i32**, i32*** %4
%15 = load i32*, i32** %14
%16 = icmp ne i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.1, i64 0, i64 0), i32 25)
store i32 -1, i32* %3
br label %62
20: ; preds = %11
%21 = load i32**, i32*** %4
%22 = load i32*, i32** %21
store i32 1, i32* %22
br label %49
23: ; preds = %2
%24 = load i32**, i32*** %4
%25 = load i32*, i32** %24
%26 = load i32, i32* %25
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = srem i32 %27, 16
%29 = icmp ne i32 %28, 0
br i1 %29, label %48, label %30
30: ; preds = %23
%31 = load i32**, i32*** %4
%32 = load i32*, i32** %31
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 16
%35 = sext i32 %34 to i64
%36 = mul i64 %35, 4
%37 = trunc i64 %36 to i32
%38 = call i8* @realloc(i32* %32, i32 %37)
store i8* %38, i8** %7
%39 = load i8*, i8** %7
%40 = icmp ne i8* %39, null
br i1 %40, label %44, label %41
41: ; preds = %30
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.1, i64 0, i64 0), i32 36)
store i32 -1, i32* %3
br label %62
44: ; preds = %30
%45 = load i8*, i8** %7
%46 = bitcast i8* %45 to i32*
%47 = load i32**, i32*** %4
store i32* %46, i32** %47
br label %48
48: ; preds = %44, %23
br label %49
49: ; preds = %48, %20
%50 = load i32, i32* %5
%51 = load i32**, i32*** %4
%52 = load i32*, i32** %51
%53 = load i32**, i32*** %4
%54 = load i32*, i32** %53
%55 = load i32, i32* %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %52, i64 %56
store i32 %50, i32* %57
%58 = load i32**, i32*** %4
%59 = load i32*, i32** %58
%60 = load i32, i32* %59
%61 = add nsw i32 %60, 1
store i32 %61, i32* %59
store i32 0, i32* %3
br label %62
62: ; preds = %49, %41, %17
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Out of memory in %s:%i\0A\00"
@.str.1 = [136 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/DeanoC/fpgatools/refs/heads/master/pair2net.c\00"
define i32 @add_entry(i32** nocapture %0, i32 %1) {
%3 = load i32*, i32** %0
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = tail call i32* @malloc(i32 64)
store i32* %6, i32** %0
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.1, i64 0, i64 0), i32 25)
br label %35
11: ; preds = %5
store i32 1, i32* %6
br label %28
12: ; preds = %2
%13 = load i32, i32* %3
%14 = and i32 %13, 15
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = shl i32 %13, 2
%18 = add i32 %17, 64
%19 = tail call i8* @realloc(i32* %3, i32 %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %25, label %21
21: ; preds = %16
%22 = bitcast i32** %0 to i8**
store i8* %19, i8** %22
%23 = bitcast i8* %19 to i32*
%24 = load i32, i32* %23
br label %28
25: ; preds = %16
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.1, i64 0, i64 0), i32 36)
br label %35
28: ; preds = %12, %21, %11
%29 = phi i32 [ %13, %12 ], [ %24, %21 ], [ 1, %11 ]
%30 = phi i32* [ %3, %12 ], [ %23, %21 ], [ %6, %11 ]
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i32, i32* %30, i64 %31
store i32 %1, i32* %32
%33 = load i32, i32* %30
%34 = add nsw i32 %33, 1
store i32 %34, i32* %30
br label %35
35: ; preds = %25, %28, %8
%36 = phi i32 [ -1, %25 ], [ 0, %28 ], [ -1, %8 ]
ret i32 %36
}