// File: /workspace/github_c_makefile_star2_O1/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 0x3a3b
cmpl $-0x1, (%r13)
je 0x3ac5
movslq (%r13), %rax
leaq (%rax,%rax,4), %r12
shlq $0x3, %r12
addq 0x70(%rbx), %r12
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x44d4
movl $0x1, %ebp
testl %eax, %eax
jne 0x3b3f
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x454e
xorl %ebp, %ebp
testl %eax, %eax
setne %bpl
jmp 0x3b3f
movl %esi, %r12d
movq %rsp, %rdx
movq $0x0, (%rdx)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x43c8
movl $0x1, %ebp
testl %eax, %eax
jne 0x3b3f
cmpl $-0x1, (%r13)
je 0x3aee
movq 0x70(%rbx), %rax
movslq (%r13), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %r13
movq 0x10(%r13), %rdx
movq (%rsp), %rcx
cmpq %rcx, %rdx
jae 0x3aa4
movq 0x8(%r13), %rsi
movq %rbx, %rdi
callq 0x3108
testl %eax, %eax
jne 0x3b3f
movq (%rsp), %rax
movq %rax, 0x10(%r13)
cmpl $0x2, %r12d
je 0x3b27
cmpl $0x1, %r12d
je 0x3b12
testl %r12d, %r12d
jne 0x3b3f
movl $0x21, 0x88(%rbx)
jmp 0x3b3f
movq %rbx, %rdi
movl $0x3, %esi
xorl %edx, %edx
callq 0x3b50
movl $0x1, %ebp
testl %eax, %eax
jne 0x3b3f
movl 0x80(%rbx), %eax
decl %eax
movl %eax, (%r13)
jmp 0x39f5
movq (%rsp), %rdx
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3b50
testl %eax, %eax
jne 0x3b3f
movl 0x80(%rbx), %eax
decl %eax
movl %eax, (%r13)
jmp 0x3a6b
movq 0x8(%r13), %rsi
movq (%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rcx
callq 0x4425
jmp 0x3b3d
movq 0x8(%r13), %rsi
movq (%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rcx
movq %r14, %r8
callq 0x3d6c
movl %eax, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq