// File: /workspace/github_c_makefile_star2_O3/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 0x3a2e
movl (%r13), %eax
cmpl $-0x1, %eax
je 0x3ab8
cltq
leaq (%rax,%rax,4), %r12
shlq $0x3, %r12
addq 0x70(%rbx), %r12
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x44b4
movl $0x1, %ebp
testl %eax, %eax
jne 0x3b30
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x452e
xorl %ebp, %ebp
testl %eax, %eax
setne %bpl
jmp 0x3b30
movl %esi, %r12d
movq %rsp, %rdx
movq $0x0, (%rdx)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x43a8
movl $0x1, %ebp
testl %eax, %eax
jne 0x3b30
movl (%r13), %eax
cmpl $-0x1, %eax
je 0x3ae1
movq 0x70(%rbx), %rcx
cltq
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,8), %r13
movq 0x10(%r13), %rdx
movq (%rsp), %rcx
cmpq %rcx, %rdx
jae 0x3a97
movq 0x8(%r13), %rsi
movq %rbx, %rdi
callq 0x308c
testl %eax, %eax
jne 0x3b30
movq (%rsp), %rcx
movq %rcx, 0x10(%r13)
cmpl $0x2, %r12d
je 0x3b19
cmpl $0x1, %r12d
je 0x3b05
testl %r12d, %r12d
jne 0x3b30
movl $0x21, 0x88(%rbx)
jmp 0x3b30
movq %rbx, %rdi
movl $0x3, %esi
xorl %edx, %edx
callq 0x3b41
movl $0x1, %ebp
testl %eax, %eax
jne 0x3b30
movl 0x80(%rbx), %eax
decl %eax
movl %eax, (%r13)
jmp 0x39ea
movq (%rsp), %rdx
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3b41
testl %eax, %eax
jne 0x3b30
movl 0x80(%rbx), %eax
decl %eax
movl %eax, (%r13)
jmp 0x3a60
movq 0x8(%r13), %rsi
movq %rbx, %rdi
movq %rcx, %rdx
movq %r15, %rcx
callq 0x4405
jmp 0x3b2e
movq 0x8(%r13), %rsi
movq %rbx, %rdi
movq %rcx, %rdx
movq %r15, %rcx
movq %r14, %r8
callq 0x3d5c
movl %eax, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq