// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../source/input.c
// Function: input_set_root
int input_set_root(char* input_file,
                   struct file_content** ppfc_input,
                   struct file_content * pfc_setroot,
                   ErrorMsg errmsg) {

  /** Define local variables */
  int flag1, filenum, iextens;
  int index_root_in_fc_input = -1;
  int overwrite_root;
  int found_filenum;

  /* The filename of the output root INCLUDING 'output/' */
  FileArg outfname;

  /* Temporary variables for parser reading etc. */
  char tmp_file[_ARGUMENT_LENGTH_MAX_+26]; // 26 is enough to extend the file name [...] with the
                                           // characters "output/[...]%02d_parameters.ini" (as done below)
  struct file_content fc_root;             // Temporary structure with only the root name

  FileArg string1;                         //Is ignored

  int n_extensions = 7;                    //Keep this as the length of the below list
  char* output_extensions[7] = {"cl.dat","pk.dat","tk.dat","parameters.ini","background.dat","thermodynamics.dat","perturbations_k0.dat"};

  /* Shorthand notation */
  struct file_content * pfc = *ppfc_input;


  /** Check whether a root name has been set, and wether overwrite_root is true */
  class_call(parser_read_string(pfc,"root",&string1,&flag1,errmsg),
             errmsg, errmsg);

  /* Set overwrite_root */
  overwrite_root = _FALSE_;
  class_read_flag("overwrite_root",overwrite_root);

  /** If root has not been set, use the default of 'output/<this-filename>' */
  if (flag1 == _FALSE_){
    memcpy(outfname, "output/", 7);
    memcpy(outfname+7, input_file, strlen(input_file)-4);
    outfname[7+strlen(input_file)-4] = '\0';
  }
  /* Check here for the index of the 'root' field in case it was set in fc_input */
  else{
    for (index_root_in_fc_input=0;index_root_in_fc_input<pfc->size;++index_root_in_fc_input){
      if (strcmp(pfc->name[index_root_in_fc_input],"root") == 0){
        strcpy(outfname,pfc->value[index_root_in_fc_input]);
        break;
      }
    }
  }

  /** If we don't want to overwrite the root name, check now for the existence of output for the given root name + N */
  if (overwrite_root == _FALSE_){

    /* Assume files exist, until proven otherwise */
    found_filenum = _TRUE_;
    /** For each 'filenum', test if it exists. Only stop if it has not been found. */
    for (filenum = 0; filenum < _N_FILEROOT_ && found_filenum; filenum++){
      /* No file has been found yet */
      found_filenum = _FALSE_;
      for (iextens = 0; iextens < n_extensions; ++iextens){
        class_sprintf(tmp_file,"%s%02d_%s", outfname, filenum, output_extensions[iextens]);
        if (file_exists(tmp_file) == _TRUE_){
          /* Found a file, the outer loop is forced to keep searching */
          found_filenum = _TRUE_;
        }
      }
      /* Didn't find a file. This is the correct number. Break the loop. */
      if (found_filenum == _FALSE_){
        break;
      }
    }
    /* If no root was found, add root through the parser routine */
    if (flag1 == _FALSE_){
      class_call(parser_init(&fc_root,
                             1,
                             pfc->filename,
                             errmsg),
                 errmsg,errmsg);
      class_sprintf(fc_root.name[0],"root");
      class_sprintf(fc_root.value[0],"%s%02d_",outfname,filenum);
      fc_root.read[0] = _FALSE_;
      class_call(parser_cat(pfc,
                            &fc_root,
                            pfc_setroot,
                            errmsg),
                 errmsg,
                 errmsg);
      class_call(parser_free(pfc),
                 errmsg,
                 errmsg);
      class_call(parser_free(&fc_root),
                 errmsg,
                 errmsg);
      (*ppfc_input) = pfc_setroot;
    }
    /* If root was found, set the index in the fc_input struct */
    else{
      class_sprintf(pfc->value[index_root_in_fc_input],"%s%02d_",outfname,filenum);
      (*ppfc_input) = pfc;
    }
  }

  /** If we do want to overwrite, just take the given root name */
  else{
    /* If no root was found, add root through the parser routine */
    if (flag1 == _FALSE_){
      class_call(parser_init(&fc_root,
                             1,
                             pfc->filename,
                             errmsg),
                 errmsg,errmsg);
      class_sprintf(fc_root.name[0],"root");
      class_sprintf(fc_root.value[0],"%s_",outfname);
      fc_root.read[0] = _FALSE_;
      class_call(parser_cat(pfc,
                            &fc_root,
                            pfc_setroot,
                            errmsg),
                 errmsg,
                 errmsg);
      class_call(parser_free(pfc),
                 errmsg,
                 errmsg);
      class_call(parser_free(&fc_root),
                 errmsg,
                 errmsg);
      (*ppfc_input) = pfc_setroot;
    }
    /* If root was found, set the index in the fc_input struct */
    else{
      class_sprintf(pfc->value[index_root_in_fc_input],"%s_",outfname);
      (*ppfc_input) = pfc;
    }
  }

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1868, %rsp           # imm = 0x1868
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r13
movq (%rsi), %r15
leaq 0xc277c(%rip), %rsi     # 0xf43fc
leaq 0x1460(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movq %r15, %rdi
movq %r12, %r8
callq 0x1ec7f
cmpl $0x1, %eax
jne 0x31cd8
leaq 0xbc74c(%rip), %rsi     # 0xee3f0
leaq 0xc143d(%rip), %rdx     # 0xf30e8
leaq 0x460(%rsp), %r14
movq %r14, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xbc36d(%rip), %rsi     # 0xee034
leaq 0xc1450(%rip), %rdx     # 0xf311e
movq %r12, %rdi
movl $0xf9, %ecx
jmp 0x31d35
leaq 0xc144e(%rip), %rsi     # 0xf312d
leaq 0x60(%rsp), %rbp
leaq 0x38(%rsp), %rcx
movq %r15, %rdi
movq %rbp, %rdx
movq %r12, %r8
callq 0x1ec7f
cmpl $0x1, %eax
jne 0x31d5a
leaq 0xbc6ed(%rip), %rsi     # 0xee3f0
leaq 0xc1432(%rip), %rdx     # 0xf313c
leaq 0x460(%rsp), %r14
movq %r14, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xbc30e(%rip), %rsi     # 0xee034
leaq 0xc13f1(%rip), %rdx     # 0xf311e
movq %r12, %rdi
movl $0xfd, %ecx
movq %r14, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %r13d
movl %r13d, %eax
addq $0x1868, %rsp           # imm = 0x1868
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, 0x10(%rsp)
movb $0x1, %bl
cmpl $0x1, 0x38(%rsp)
jne 0x31d94
leaq 0x60(%rsp), %rdi
movl $0x79, %esi
callq 0x30ca3
testl %eax, %eax
jne 0x31d92
leaq 0x60(%rsp), %rdi
movl $0x59, %esi
callq 0x30ca3
testl %eax, %eax
je 0x3220c
xorl %ebx, %ebx
cmpl $0x0, 0xc(%rsp)
movq %r12, 0x28(%rsp)
movq %r14, 0x18(%rsp)
je 0x31e0d
movq %r15, %rax
movslq 0x8(%r15), %r15
testq %r15, %r15
jle 0x31eb6
movl %ebx, 0x8(%rsp)
movq %rax, 0x20(%rsp)
movq 0x10(%rax), %r14
movq %r15, %rbp
shlq $0xa, %rbp
xorl %r13d, %r13d
leaq 0xc2629(%rip), %r12     # 0xf43fc
xorl %ebx, %ebx
movq %r14, %rdi
movq %r12, %rsi
callq 0x84b0
testl %eax, %eax
je 0x31ebd
incl %ebx
addq $-0x400, %r13           # imm = 0xFC00
addq $0x400, %r14            # imm = 0x400
movq %rbp, %rax
addq %r13, %rax
jne 0x31dd5
movl %r15d, %ebp
movq 0x20(%rsp), %r15
jmp 0x31ed5
leaq 0x67(%rsp), %r14
movl $0x2f747570, -0x4(%r14) # imm = 0x2F747570
movl $0x7074756f, -0x7(%r14) # imm = 0x7074756F
movq %r13, %rdi
callq 0x8180
movq %rax, %r12
leaq -0x4(%rax), %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x82d0
movb $0x0, 0x3(%r12,%rbp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb %bl, %bl
jne 0x31ee1
movq (%r15), %rdx
leaq 0x38(%rsp), %rdi
movl $0x1, %r13d
movl $0x1, %esi
movq 0x28(%rsp), %r14
movq %r14, %rcx
callq 0x1e567
cmpl $0x1, %eax
jne 0x320a4
leaq 0xbc571(%rip), %rsi     # 0xee3f0
leaq 0xc1340(%rip), %rdx     # 0xf31c6
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xbc192(%rip), %rsi     # 0xee034
leaq 0xc1275(%rip), %rdx     # 0xf311e
movq %r14, %rdi
movl $0x14b, %ecx            # imm = 0x14B
jmp 0x32095
xorl %ebp, %ebp
movq %rax, %r15
jmp 0x31ed9
movq 0x20(%rsp), %r15
movq 0x18(%r15), %rsi
subq %r13, %rsi
leaq 0x60(%rsp), %rdi
callq 0x8350
movl %ebx, %ebp
movl 0x8(%rsp), %ebx
testb %bl, %bl
je 0x31f93
movl %ebp, 0x34(%rsp)
movq %r15, 0x20(%rsp)
leaq 0x11574f(%rip), %rax    # 0x147640
leaq 0xc12c4(%rip), %r14     # 0xf31bc
leaq 0x60(%rsp), %rbp
movl $0x0, 0x8(%rsp)
xorl %r13d, %r13d
xorl %r15d, %r15d
movq (%r13,%rax), %rbx
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movq %rbp, %rcx
movl 0x8(%rsp), %r12d
movl %r12d, %r8d
movq %rbx, %r9
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
leaq 0xc60(%rsp), %rdi
movq %r14, %rdx
movq %rbp, %rcx
movl %r12d, %r8d
movq %rbx, %r9
leaq 0xc60(%rsp), %rbx
xorl %eax, %eax
callq 0x8550
movq %rbx, %rdi
callq 0x30c60
cmpl $0x1, %eax
cmovel %eax, %r15d
leaq 0x1156d6(%rip), %rax    # 0x147640
addq $0x8, %r13
cmpq $0x38, %r13
jne 0x31f0b
testl %r15d, %r15d
je 0x31fd1
movl 0x8(%rsp), %ecx
incl %ecx
movl %ecx, 0x8(%rsp)
cmpl $0x64, %ecx
jne 0x31f05
movl $0x64, %ebp
jmp 0x31fd5
leaq 0xc12ba(%rip), %rbx     # 0xf3254
xorl %r13d, %r13d
leaq 0x60(%rsp), %r14
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x8550
movl %ebp, %edi
shlq $0xa, %rdi
addq 0x18(%r15), %rdi
incl %eax
movslq %eax, %rsi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x8550
jmp 0x3202b
movl 0x8(%rsp), %ebp
cmpl $0x0, 0xc(%rsp)
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r15
je 0x32038
leaq 0xc1209(%rip), %rbx     # 0xf31f6
xorl %r13d, %r13d
leaq 0x60(%rsp), %r14
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x8550
movslq 0x34(%rsp), %rdi
shlq $0xa, %rdi
addq 0x18(%r15), %rdi
incl %eax
movslq %eax, %rsi
movq %rbx, %rdx
movq %r14, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x8550
movq 0x18(%rsp), %rax
movq %r15, (%rax)
jmp 0x31d45
movq (%r15), %rdx
leaq 0x38(%rsp), %rdi
movl $0x1, %r13d
movl $0x1, %esi
movq %r14, %rcx
callq 0x1e567
cmpl $0x1, %eax
jne 0x32155
leaq 0xbc38d(%rip), %rsi     # 0xee3f0
leaq 0xc115c(%rip), %rdx     # 0xf31c6
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xbbfae(%rip), %rsi     # 0xee034
leaq 0xc1091(%rip), %rdx     # 0xf311e
movq %r14, %rdi
movl $0x12a, %ecx            # imm = 0x12A
movq %rbx, %r8
xorl %eax, %eax
callq 0x30af0
jmp 0x31d45
leaq 0x38(%rsp), %r14
movq 0x10(%r14), %rax
movb $0x0, 0x4(%rax)
movl $0x746f6f72, (%rax)     # imm = 0x746F6F72
leaq 0xc1196(%rip), %rbx     # 0xf3254
leaq 0x60(%rsp), %r12
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x8550
movq 0x18(%r14), %rdi
incl %eax
movslq %eax, %rsi
movq %rbx, %rdx
movq %r12, %rcx
movq %r15, %rbx
movq 0x28(%rsp), %r15
xorl %eax, %eax
callq 0x8550
movq 0x20(%r14), %rax
movw $0x0, (%rax)
movq %rbx, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
callq 0x1f5f0
cmpl $0x1, %eax
jne 0x32299
leaq 0xbc2d2(%rip), %rsi     # 0xee3f0
leaq 0xc10d9(%rip), %rdx     # 0xf31fe
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xbbef3(%rip), %rsi     # 0xee034
leaq 0xc0fd6(%rip), %rdx     # 0xf311e
movq %r15, %rdi
movl $0x154, %ecx            # imm = 0x154
jmp 0x323cd
leaq 0x38(%rsp), %r14
movq 0x10(%r14), %rax
movb $0x0, 0x4(%rax)
movl $0x746f6f72, (%rax)     # imm = 0x746F6F72
leaq 0xc1087(%rip), %rbx     # 0xf31f6
leaq 0x60(%rsp), %r12
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r12, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x8550
movq 0x18(%r14), %rdi
incl %eax
movslq %eax, %rsi
movq %rbx, %rdx
movq %r12, %rcx
movq %r15, %rbx
movq 0x28(%rsp), %r15
movl %ebp, %r8d
xorl %eax, %eax
callq 0x8550
movq 0x20(%r14), %rax
movw $0x0, (%rax)
movq %rbx, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
callq 0x1f5f0
cmpl $0x1, %eax
jne 0x322e8
leaq 0xbc21b(%rip), %rsi     # 0xee3f0
leaq 0xc1022(%rip), %rdx     # 0xf31fe
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xbbe3c(%rip), %rsi     # 0xee034
leaq 0xc0f1f(%rip), %rdx     # 0xf311e
movq %r15, %rdi
movl $0x133, %ecx            # imm = 0x133
jmp 0x323cd
leaq 0x60(%rsp), %rdi
movl $0x6e, %esi
callq 0x30ca3
testl %eax, %eax
jne 0x31d94
leaq 0x60(%rsp), %rdi
movl $0x4e, %esi
callq 0x30ca3
testl %eax, %eax
jne 0x31d94
leaq 0xc0f43(%rip), %rsi     # 0xf3184
leaq 0xc0ee5(%rip), %rcx     # 0xf312d
leaq 0x460(%rsp), %r14
leaq 0x60(%rsp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
leaq 0xbc31f(%rip), %rsi     # 0xee585
leaq 0xc60(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x30af0
leaq 0xbbdb2(%rip), %rsi     # 0xee034
leaq 0xc0e95(%rip), %rdx     # 0xf311e
movq %r12, %rdi
movl $0xfd, %ecx
movq %r15, %r8
jmp 0x31d38
movq %rbx, %rdi
callq 0x1e705
cmpl $0x1, %eax
jne 0x32337
leaq 0xbc13f(%rip), %rsi     # 0xee3f0
leaq 0xc0f75(%rip), %rdx     # 0xf322d
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xbbd60(%rip), %rsi     # 0xee034
leaq 0xc0e43(%rip), %rdx     # 0xf311e
movq %r15, %rdi
movl $0x157, %ecx            # imm = 0x157
jmp 0x323cd
movq %rbx, %rdi
callq 0x1e705
cmpl $0x1, %eax
jne 0x32385
leaq 0xbc0f0(%rip), %rsi     # 0xee3f0
leaq 0xc0f26(%rip), %rdx     # 0xf322d
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xbbd11(%rip), %rsi     # 0xee034
leaq 0xc0df4(%rip), %rdx     # 0xf311e
movq %r15, %rdi
movl $0x136, %ecx            # imm = 0x136
jmp 0x323cd
leaq 0x38(%rsp), %rdi
callq 0x1e705
cmpl $0x1, %eax
jne 0x323d5
leaq 0xbc09f(%rip), %rsi     # 0xee3f0
leaq 0xc0ee6(%rip), %rdx     # 0xf323e
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xbbcc0(%rip), %rsi     # 0xee034
leaq 0xc0da3(%rip), %rdx     # 0xf311e
movq %r15, %rdi
movl $0x15a, %ecx            # imm = 0x15A
jmp 0x323cd
leaq 0x38(%rsp), %rdi
callq 0x1e705
cmpl $0x1, %eax
jne 0x323d5
leaq 0xbc055(%rip), %rsi     # 0xee3f0
leaq 0xc0e9c(%rip), %rdx     # 0xf323e
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x30af0
leaq 0xbbc76(%rip), %rsi     # 0xee034
leaq 0xc0d59(%rip), %rdx     # 0xf311e
movq %r15, %rdi
movl $0x139, %ecx            # imm = 0x139
movq %rbx, %r8
jmp 0x31d38
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
xorl %r13d, %r13d
jmp 0x31d45