// File: /workspace/github_c_makefile_star2_O2/0xADE1A1DE[P]MeasureSuite/lib/src/loader.c
// Function: load_file
int load_file(measuresuite_t ms, enum load_type type, const char *filename,
              const char *symbol, int *id) {

  if (type == SHARED_OBJECT) {
    return load_file_so(ms, type, filename, symbol, id);
  }

  size_t size = 0;
  if (filesize(ms, filename, &size)) {
    return 1;
  }

  if (*id == -1) {
    /*
   size should suffice for
   - ASM, as a string instructions are typically longer than the encoded
   version
   - BIN (its equal anyway)
   - ELF, as we'd need less because we skip the header stuff
   */
    if (create_new_function(ms, type, size)) {
      return 1;
    }
    *id = (int)ms->num_functions - 1;
  }
  struct function_tuple *fct = &ms->functions[*id];
  /** make sure we got enough space in case we are re-using */
  if (fct->code_size_bytes < size) {
    if (realloc_rwx_or_fail(ms, fct->code, fct->code_size_bytes, size)) {
      return 1;
    }
    fct->code_size_bytes = size;
  }

  switch (type) {
  case ASM: {
#ifdef USE_ASSEMBLYLINE
    if (asm_assemble_file_counting_chunks(fct->al, (char *)filename,
                                          (int)ms->chunk_size, &fct->chunks)) {
      ms->errorno = E_LOAD__ASM_FILE;
      return 1;
    }
    return 0;
#else
    ms->errorno = E_NO_ASSEMBLYLINE;
    return 1;
#endif
  }

  case BIN:
    return filecopy(ms, fct->code, size, filename);

  case ELF:
    return elf_load_symbol(ms, fct->code, size, filename, symbol);

  default:
    return 1;
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r13
movq %rcx, %r14
movq %rdx, %r15
movq %rdi, %rbx
cmpl $0x3, %esi
jne 0x3767
movl (%r13), %eax
cmpl $-0x1, %eax
je 0x37e1
cltq
imulq $0x28, %rax, %r12
addq 0x70(%rbx), %r12
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x419c
testl %eax, %eax
jne 0x37f2
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x4210
xorl %ebp, %ebp
testl %eax, %eax
setne %bpl
jmp 0x37f5
movl %esi, %r12d
movq %rsp, %rdx
andq $0x0, (%rdx)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4098
pushq $0x1
popq %rbp
testl %eax, %eax
jne 0x37f5
movl (%r13), %eax
cmpl $-0x1, %eax
je 0x3806
movq 0x70(%rbx), %rcx
cltq
imulq $0x28, %rax, %rax
leaq (%rcx,%rax), %r13
movq 0x10(%rcx,%rax), %rdx
movq (%rsp), %rcx
cmpq %rcx, %rdx
jae 0x37c0
movq 0x8(%r13), %rsi
movq %rbx, %rdi
callq 0x2f52
testl %eax, %eax
jne 0x37f5
movq (%rsp), %rcx
movq %rcx, 0x10(%r13)
cmpl $0x2, %r12d
je 0x384f
cmpl $0x1, %r12d
je 0x383b
testl %r12d, %r12d
jne 0x37f5
movl $0x21, 0x88(%rbx)
jmp 0x37f5
pushq $0x3
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3868
testl %eax, %eax
je 0x382a
pushq $0x1
popq %rbp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rdx
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3868
testl %eax, %eax
jne 0x37f5
movl 0x80(%rbx), %eax
decl %eax
movl %eax, (%r13)
jmp 0x378c
movl 0x80(%rbx), %eax
decl %eax
movl %eax, (%r13)
jmp 0x372c
movq 0x8(%r13), %rsi
movq %rbx, %rdi
movq %rcx, %rdx
movq %r15, %rcx
callq 0x40f3
jmp 0x3864
movq 0x8(%r13), %rsi
movq %rbx, %rdi
movq %rcx, %rdx
movq %r15, %rcx
movq %r14, %r8
callq 0x3a68
movl %eax, %ebp
jmp 0x37f5