// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
cmpl $0x3, -0x14(%rbp)
jne 0x4821
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0x4980
movl %eax, -0x4(%rbp)
jmp 0x496b
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x5600
cmpl $0x0, %eax
je 0x484b
movl $0x1, -0x4(%rbp)
jmp 0x496b
movq -0x30(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0x488b
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x38(%rbp), %rdx
callq 0x4a40
cmpl $0x0, %eax
je 0x4875
movl $0x1, -0x4(%rbp)
jmp 0x496b
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movl %eax, %ecx
subl $0x1, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x30(%rbp), %rcx
movslq (%rcx), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x38(%rbp), %rax
jae 0x48ed
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x38(%rbp), %rcx
callq 0x3990
cmpl $0x0, %eax
je 0x48e1
movl $0x1, -0x4(%rbp)
jmp 0x496b
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x14(%rbp), %eax
movl %eax, -0x44(%rbp)
testl %eax, %eax
je 0x490d
jmp 0x48f9
movl -0x44(%rbp), %eax
subl $0x1, %eax
je 0x4924
jmp 0x4903
movl -0x44(%rbp), %eax
subl $0x2, %eax
je 0x4942
jmp 0x4964
movq -0x10(%rbp), %rax
movl $0x21, 0x88(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x496b
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x38(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x5680
movl %eax, -0x4(%rbp)
jmp 0x496b
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x38(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
callq 0x4db0
movl %eax, -0x4(%rbp)
jmp 0x496b
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)