#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 */
struct gsgp_tree {
  int dummy;
};
struct gsgp_individual {
  int dummy;
};
struct gsgp_archive {
  int dummy;
};

/* Variables and functions */
double *extract_coef(struct gsgp_individual *, struct gsgp_tree **, int);
int extract_models(struct gsgp_individual *, struct gsgp_tree ***,
                   int /*<<< orphan*/, int *);
int /*<<< orphan*/ free(struct gsgp_tree **);
struct gsgp_tree **reallocate(struct gsgp_tree **, int, int, char *, int, int);
int gsgp_extract_model(struct gsgp_individual *ind, double **beta_ptr,
                       struct gsgp_tree ***models_ptr,
                       struct gsgp_archive *archive) {
  int N, buffer_capacity;
  struct gsgp_tree **model_buffer;
  buffer_capacity = 10000;
  model_buffer =
      reallocate(NULL, (buffer_capacity), (sizeof(struct gsgp_tree *)),
                 "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/grantdick/libgsgp/refs/"
                 "heads/master/src/ensemble.c",
                 55, false);
  N = extract_models(ind, &model_buffer, 0, &buffer_capacity);
  if (beta_ptr)
    *beta_ptr = extract_coef(ind, model_buffer, N);
  if (models_ptr) {
    *models_ptr =
        reallocate((model_buffer), (N), (sizeof(struct gsgp_tree *)),
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/grantdick/libgsgp/refs/"
                   "heads/master/src/ensemble.c",
                   61, false);
  } else {
    free(model_buffer);
  }
  return N;
}


x86 assembly (clang, -O0):
<gsgp_extract_model>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x2710,-0x28(%rbp)
mov    -0x28(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edi
mov    $0x8,%edx
lea    0xe8e(%rip),%rcx
mov    $0x37,%r8d
xor    %r9d,%r9d
call   1060 <reallocate@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
lea    -0x28(%rbp),%rcx
call   1050 <extract_models@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11bf <gsgp_extract_model+0x7f>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <extract_coef@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11fa <gsgp_extract_model+0xba>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    $0x8,%edx
lea    0xe23(%rip),%rcx
mov    $0x3d,%r8d
xor    %r9d,%r9d
call   1060 <reallocate@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    1203 <gsgp_extract_model+0xc3>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gsgp_extract_model>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movl   $0x2710,0x14(%rsp)
lea    0xe9e(%rip),%rcx
xor    %edi,%edi
mov    $0x2710,%esi
mov    $0x8,%edx
mov    $0x37,%r8d
xor    %r9d,%r9d
call   1060 <reallocate@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rcx
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <extract_models@plt>
mov    %eax,%ebp
test   %r15,%r15
je     11ae <gsgp_extract_model+0x6e>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <extract_coef@plt>
mov    %rax,(%r15)
mov    0x8(%rsp),%rdi
test   %r14,%r14
je     11d9 <gsgp_extract_model+0x99>
lea    0xe41(%rip),%rcx
mov    %ebp,%esi
mov    $0x8,%edx
mov    $0x3d,%r8d
xor    %r9d,%r9d
call   1060 <reallocate@plt>
mov    %rax,(%r14)
jmp    11de <gsgp_extract_model+0x9e>
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.gsgp_individual = type { i32 }
%struct.gsgp_tree = type { i32 }
%struct.gsgp_archive = type { i32 }
@.str = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/grantdick/libgsgp/refs/heads/master/src/ensemble.c\00"
define i32 @gsgp_extract_model(%struct.gsgp_individual* %0, double** %1, %struct.gsgp_tree*** %2, %struct.gsgp_archive* %3) {
%5 = alloca %struct.gsgp_individual*
%6 = alloca double**
%7 = alloca %struct.gsgp_tree***
%8 = alloca %struct.gsgp_archive*
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.gsgp_tree**
store %struct.gsgp_individual* %0, %struct.gsgp_individual** %5
store double** %1, double*** %6
store %struct.gsgp_tree*** %2, %struct.gsgp_tree**** %7
store %struct.gsgp_archive* %3, %struct.gsgp_archive** %8
store i32 10000, i32* %10
%12 = load i32, i32* %10
%13 = call %struct.gsgp_tree** @reallocate(%struct.gsgp_tree** null, i32 %12, i32 8, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str, i64 0, i64 0), i32 55, i32 0)
store %struct.gsgp_tree** %13, %struct.gsgp_tree*** %11
%14 = load %struct.gsgp_individual*, %struct.gsgp_individual** %5
%15 = call i32 @extract_models(%struct.gsgp_individual* %14, %struct.gsgp_tree*** %11, i32 0, i32* %10)
store i32 %15, i32* %9
%16 = load double**, double*** %6
%17 = icmp ne double** %16, null
br i1 %17, label %18, label %24
18: ; preds = %4
%19 = load %struct.gsgp_individual*, %struct.gsgp_individual** %5
%20 = load %struct.gsgp_tree**, %struct.gsgp_tree*** %11
%21 = load i32, i32* %9
%22 = call double* @extract_coef(%struct.gsgp_individual* %19, %struct.gsgp_tree** %20, i32 %21)
%23 = load double**, double*** %6
store double* %22, double** %23
br label %24
24: ; preds = %18, %4
%25 = load %struct.gsgp_tree***, %struct.gsgp_tree**** %7
%26 = icmp ne %struct.gsgp_tree*** %25, null
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load %struct.gsgp_tree**, %struct.gsgp_tree*** %11
%29 = load i32, i32* %9
%30 = call %struct.gsgp_tree** @reallocate(%struct.gsgp_tree** %28, i32 %29, i32 8, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str, i64 0, i64 0), i32 61, i32 0)
%31 = load %struct.gsgp_tree***, %struct.gsgp_tree**** %7
store %struct.gsgp_tree** %30, %struct.gsgp_tree*** %31
br label %35
32: ; preds = %24
%33 = load %struct.gsgp_tree**, %struct.gsgp_tree*** %11
%34 = call i32 @free(%struct.gsgp_tree** %33)
br label %35
35: ; preds = %32, %27
%36 = load i32, i32* %9
ret i32 %36
}

LLVM IR (-O2):
%struct.gsgp_individual = type { i32 }
%struct.gsgp_tree = type { i32 }
%struct.gsgp_archive = type { i32 }
@.str = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/grantdick/libgsgp/refs/heads/master/src/ensemble.c\00"
define i32 @gsgp_extract_model(%struct.gsgp_individual* %0, double** writeonly %1, %struct.gsgp_tree*** writeonly %2, %struct.gsgp_archive* nocapture readnone %3) {
%5 = alloca i32
%6 = alloca %struct.gsgp_tree**
%7 = bitcast i32* %5 to i8*
%8 = bitcast %struct.gsgp_tree*** %6 to i8*
store i32 10000, i32* %5
%9 = tail call %struct.gsgp_tree** @reallocate(%struct.gsgp_tree** null, i32 10000, i32 8, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str, i64 0, i64 0), i32 55, i32 0)
store %struct.gsgp_tree** %9, %struct.gsgp_tree*** %6
%10 = call i32 @extract_models(%struct.gsgp_individual* %0, %struct.gsgp_tree*** %6, i32 0, i32* %5)
%11 = icmp eq double** %1, null
br i1 %11, label %15, label %12
12: ; preds = %4
%13 = load %struct.gsgp_tree**, %struct.gsgp_tree*** %6
%14 = call double* @extract_coef(%struct.gsgp_individual* %0, %struct.gsgp_tree** %13, i32 %10)
store double* %14, double** %1
br label %15
15: ; preds = %12, %4
%16 = icmp eq %struct.gsgp_tree*** %2, null
%17 = load %struct.gsgp_tree**, %struct.gsgp_tree*** %6
br i1 %16, label %20, label %18
18: ; preds = %15
%19 = call %struct.gsgp_tree** @reallocate(%struct.gsgp_tree** %17, i32 %10, i32 8, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str, i64 0, i64 0), i32 61, i32 0)
store %struct.gsgp_tree** %19, %struct.gsgp_tree*** %2
br label %22
20: ; preds = %15
%21 = call i32 @free(%struct.gsgp_tree** %17)
br label %22
22: ; preds = %20, %18
ret i32 %10
}