// File: /workspace/github_c_makefile_star2_O0/0xADE1A1DE[P]MeasureSuite/lib/src/loader.c
// Function: create_new_function
static int create_new_function(measuresuite_t ms, enum load_type type,
                               size_t code_size_bytes) {

  DEBUG("Creating new function. type: %d\n", type);
  // check size and allocate more if needed
  if (ms->size_functions <= ms->num_functions) {
    ms->size_functions *= 2;
    DEBUG("Doubled size_functions to %lu\n", ms->size_functions);
    if (realloc_or_fail(ms, (void **)&ms->functions,
                        ms->size_functions * sizeof(struct function_tuple))) {
      return 1;
    }
  }

  // convenience pointer to the new tuple
  struct function_tuple *new = &ms->functions[ms->num_functions];

  new->type = type;

  // initialize the memory for arith_result
  init_arithmetic_results(ms, new);

  // if we need the 'code' segment, initialize that memory
  if (type == ELF || type == BIN || type == ASM) {

    new->code_size_bytes =
        code_size_bytes == 0 ? DEFAULT_CODE_SIZE : code_size_bytes;
    if (map_rwx(ms, (void **)&new->code, new->code_size_bytes)) {
      return 1;
    }
  }

  // Because we don't have any batch_size yet.
  new->cycle_results = NULL;

#ifdef USE_ASSEMBLYLINE
  new->chunks = 0;

  if (type == ASM) {
    // create asm instance
    new->al = asm_create_instance(new->code, (int)new->code_size_bytes);
  } else {
    new->al = NULL;
  }
#else
  if (type == ASM) {
    ms->errorno = E_NO_ASSEMBLYLINE;
    return 1;
  }

#endif

  // specify that we have a new one now
  ms->num_functions += 1;
  reset_permutaions(ms);
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x80(%rcx), %rax
ja 0x4aa4
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rcx
shlq %rcx
movq %rcx, 0x78(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x70, %rsi
movq -0x10(%rbp), %rax
imulq $0x28, 0x78(%rax), %rdx
callq 0x37f0
cmpl $0x0, %eax
je 0x4aa2
movl $0x1, -0x4(%rbp)
jmp 0x4b85
jmp 0x4aa4
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rcx
imulq $0x28, 0x80(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x3a90
cmpl $0x2, -0x14(%rbp)
je 0x4ae7
cmpl $0x1, -0x14(%rbp)
je 0x4ae7
cmpl $0x0, -0x14(%rbp)
jne 0x4b36
cmpq $0x0, -0x20(%rbp)
jne 0x4af9
movl $0xea60, %eax           # imm = 0xEA60
movq %rax, -0x30(%rbp)
jmp 0x4b01
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x3870
cmpl $0x0, %eax
je 0x4b34
movl $0x1, -0x4(%rbp)
jmp 0x4b85
jmp 0x4b36
movq -0x28(%rbp), %rax
movq $0x0, 0x20(%rax)
cmpl $0x0, -0x14(%rbp)
jne 0x4b5f
movq -0x10(%rbp), %rax
movl $0x21, 0x88(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x4b85
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x80(%rax)
movq -0x10(%rbp), %rdi
callq 0x4720
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop