// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %r12
movq (%rsi), %rbx
leaq 0xbc12e(%rip), %rsi     # 0xeb2c4
leaq 0x1460(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movq %rbx, %rdi
movq %r13, %r8
callq 0x1caf9
cmpl $0x1, %eax
jne 0x2f1ee
leaq 0xb6236(%rip), %rsi     # 0xe53f0
leaq 0xbadef(%rip), %rdx     # 0xe9fb0
leaq 0x460(%rsp), %r14
movq %r14, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xb5e57(%rip), %rsi     # 0xe5034
leaq 0xbae02(%rip), %rdx     # 0xe9fe6
movq %r13, %rdi
movl $0xf9, %ecx
jmp 0x2f255
movq %r15, 0x28(%rsp)
leaq 0xbadfb(%rip), %rsi     # 0xe9ff5
leaq 0x60(%rsp), %rbp
leaq 0x38(%rsp), %rcx
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
movq %rbp, %rdx
movq %r13, %r8
callq 0x1caf9
cmpl $0x1, %eax
jne 0x2f278
leaq 0xb61cd(%rip), %rsi     # 0xe53f0
leaq 0xbadda(%rip), %rdx     # 0xea004
leaq 0x460(%rsp), %r14
movq %r14, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xb5dee(%rip), %rsi     # 0xe5034
leaq 0xbad99(%rip), %rdx     # 0xe9fe6
movq %r13, %rdi
movl $0xfd, %ecx
movq %r14, %r8
xorl %eax, %eax
callq 0x2e014
pushq $0x1
popq %r12
movl %r12d, %eax
addq $0x1868, %rsp           # imm = 0x1868
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bl
cmpl $0x1, 0x38(%rsp)
jne 0x2f2a9
leaq 0x60(%rsp), %rdi
pushq $0x79
popq %rsi
callq 0x2e1bc
testl %eax, %eax
jne 0x2f2a7
leaq 0x60(%rsp), %rdi
pushq $0x59
popq %rsi
callq 0x2e1bc
testl %eax, %eax
je 0x2f6f0
xorl %ebx, %ebx
movq %r14, 0x18(%rsp)
movq %r13, 0x10(%rsp)
cmpl $0x0, 0xc(%rsp)
je 0x2f308
movl %ebx, 0x8(%rsp)
movq 0x20(%rsp), %rbp
movl 0x8(%rbp), %ebx
xorl %eax, %eax
testl %ebx, %ebx
movl $0x0, %r15d
cmovlel %eax, %ebx
movq %rbx, %r13
shlq $0xa, %r13
leaq 0xbbfe3(%rip), %r12     # 0xeb2c4
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x2f34f
movq 0x10(%rbp), %rdi
addq %r14, %rdi
movq %r12, %rsi
callq 0x84e0
testl %eax, %eax
je 0x2f354
addq $0x400, %r14            # imm = 0x400
incl %r15d
jmp 0x2f2e4
leaq 0x67(%rsp), %r14
movl $0x2f747570, -0x4(%r14) # imm = 0x2F747570
movl $0x7074756f, -0x7(%r14) # imm = 0x7074756F
movq %r12, %rdi
callq 0x8190
movq %rax, %r13
leaq -0x4(%rax), %rdx
movq %r14, %rdi
movq %r12, %rsi
callq 0x82f0
movb $0x0, 0x3(%r13,%rbp)
testb %bl, %bl
je 0x2f4bc
pushq $-0x1
popq %rax
movq %rax, 0x30(%rsp)
jmp 0x2f375
movl %ebx, %r15d
jmp 0x2f365
addq 0x18(%rbp), %r14
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x8370
cmpb $0x0, 0x8(%rsp)
je 0x2f472
movq %r15, 0x30(%rsp)
xorl %ebp, %ebp
cmpl $0x64, %ebp
je 0x2f410
movl %ebp, 0x8(%rsp)
xorl %r8d, %r8d
xorl %r15d, %r15d
cmpq $0x38, %r8
je 0x2f400
leaq 0x112299(%rip), %rax    # 0x141630
movq (%r8,%rax), %rbx
xorl %edi, %edi
xorl %esi, %esi
leaq 0xbacde(%rip), %r13     # 0xea084
movq %r13, %rdx
leaq 0x60(%rsp), %rcx
movq %r8, %r14
movl 0x8(%rsp), %r12d
movl %r12d, %r8d
movq %rbx, %r9
xorl %eax, %eax
callq 0x8580
incl %eax
movslq %eax, %rsi
leaq 0xc60(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rdx
leaq 0x60(%rsp), %rcx
movl %r12d, %r8d
movq %rbx, %r9
xorl %eax, %eax
callq 0x8580
movq %rbp, %rdi
callq 0x2e17d
movq %r14, %r8
cmpl $0x1, %eax
cmovel %eax, %r15d
addq $0x8, %r8
jmp 0x2f38a
testl %r15d, %r15d
movl 0x8(%rsp), %ebp
je 0x2f410
incl %ebp
jmp 0x2f377
cmpl $0x0, 0xc(%rsp)
je 0x2f525
leaq 0xbac9c(%rip), %rbx     # 0xea0be
xorl %r12d, %r12d
leaq 0x60(%rsp), %r14
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x8580
movslq 0x30(%rsp), %rdi
shlq $0xa, %rdi
movq 0x20(%rsp), %r15
addq 0x18(%r15), %rdi
incl %eax
movslq %eax, %rsi
movq %rbx, %rdx
movq %r14, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x8580
movq 0x18(%rsp), %rax
movq %r15, (%rax)
jmp 0x2f263
leaq 0xbaca3(%rip), %rbx     # 0xea11c
xorl %r12d, %r12d
leaq 0x60(%rsp), %r14
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x8580
movl %r15d, %edi
shlq $0xa, %rdi
addq 0x18(%rbp), %rdi
incl %eax
movslq %eax, %rsi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x8580
movq 0x18(%rsp), %rax
movq %rbp, (%rax)
jmp 0x2f263
movq 0x20(%rsp), %rbp
movq (%rbp), %rdx
leaq 0x38(%rsp), %rdi
pushq $0x1
popq %r12
movl %r12d, %esi
movq 0x10(%rsp), %r14
movq %r14, %rcx
callq 0x1c40b
cmpl $0x1, %eax
jne 0x2f58d
leaq 0xb5f02(%rip), %rsi     # 0xe53f0
leaq 0xbab99(%rip), %rdx     # 0xea08e
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xb5b23(%rip), %rsi     # 0xe5034
leaq 0xbaace(%rip), %rdx     # 0xe9fe6
movq %r14, %rdi
movl $0x14b, %ecx            # imm = 0x14B
jmp 0x2f8ad
movq 0x20(%rsp), %rbx
movq (%rbx), %rdx
leaq 0x38(%rsp), %rdi
pushq $0x1
popq %r12
movl %r12d, %esi
movq 0x10(%rsp), %r14
movq %r14, %rcx
callq 0x1c40b
cmpl $0x1, %eax
jne 0x2f63a
leaq 0xb5e9a(%rip), %rsi     # 0xe53f0
leaq 0xbab31(%rip), %rdx     # 0xea08e
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xb5abb(%rip), %rsi     # 0xe5034
leaq 0xbaa66(%rip), %rdx     # 0xe9fe6
movq %r14, %rdi
movl $0x12a, %ecx            # imm = 0x12A
jmp 0x2f8ad
leaq 0x38(%rsp), %r14
movq 0x10(%r14), %rax
movb $0x0, 0x4(%rax)
movl $0x746f6f72, (%rax)     # imm = 0x746F6F72
leaq 0xbab75(%rip), %rbx     # 0xea11c
leaq 0x60(%rsp), %r13
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x8580
movq 0x18(%r14), %rdi
incl %eax
movslq %eax, %rsi
movq %rbx, %rdx
movq %r13, %rcx
movq 0x10(%rsp), %r15
xorl %eax, %eax
callq 0x8580
movq 0x20(%r14), %rax
andw $0x0, (%rax)
movq %rbp, %rdi
movq %r14, %rsi
movq 0x28(%rsp), %rdx
movq %r15, %rcx
callq 0x1d48c
cmpl $0x1, %eax
jne 0x2f779
leaq 0xb5ded(%rip), %rsi     # 0xe53f0
leaq 0xbaabc(%rip), %rdx     # 0xea0c6
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xb5a0e(%rip), %rsi     # 0xe5034
leaq 0xba9b9(%rip), %rdx     # 0xe9fe6
movq %r15, %rdi
movl $0x154, %ecx            # imm = 0x154
jmp 0x2f8ad
leaq 0x38(%rsp), %r14
movq 0x10(%r14), %rax
movb $0x0, 0x4(%rax)
movl $0x746f6f72, (%rax)     # imm = 0x746F6F72
leaq 0xbaa6a(%rip), %r15     # 0xea0be
leaq 0x60(%rsp), %r13
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %r13, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x8580
movq 0x18(%r14), %rdi
incl %eax
movslq %eax, %rsi
movq %r15, %rdx
movq %r13, %rcx
movq 0x10(%rsp), %r15
movl %ebp, %r8d
xorl %eax, %eax
callq 0x8580
movq 0x20(%r14), %rax
andw $0x0, (%rax)
movq %rbx, %rdi
movq %r14, %rsi
movq 0x28(%rsp), %r14
movq %r14, %rdx
movq %r15, %rcx
callq 0x1d48c
cmpl $0x1, %eax
jne 0x2f7c8
leaq 0xb5d37(%rip), %rsi     # 0xe53f0
leaq 0xbaa06(%rip), %rdx     # 0xea0c6
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xb5958(%rip), %rsi     # 0xe5034
leaq 0xba903(%rip), %rdx     # 0xe9fe6
movq %r15, %rdi
movl $0x133, %ecx            # imm = 0x133
jmp 0x2f8ad
leaq 0x60(%rsp), %rdi
pushq $0x6e
popq %rsi
callq 0x2e1bc
testl %eax, %eax
jne 0x2f2a9
leaq 0x60(%rsp), %rdi
pushq $0x4e
popq %rsi
callq 0x2e1bc
testl %eax, %eax
jne 0x2f2a9
leaq 0xba92b(%rip), %rsi     # 0xea04c
leaq 0xba8cd(%rip), %rcx     # 0xe9ff5
leaq 0x460(%rsp), %r14
leaq 0x60(%rsp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x2e014
leaq 0xb5e3f(%rip), %rsi     # 0xe5585
leaq 0xc60(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2e014
leaq 0xb58d2(%rip), %rsi     # 0xe5034
leaq 0xba87d(%rip), %rdx     # 0xe9fe6
movq %r13, %rdi
movl $0xfd, %ecx
movq %r15, %r8
jmp 0x2f258
movq %rbp, %rdi
callq 0x1c593
cmpl $0x1, %eax
jne 0x2f817
leaq 0xb5c5f(%rip), %rsi     # 0xe53f0
leaq 0xba95d(%rip), %rdx     # 0xea0f5
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xb5880(%rip), %rsi     # 0xe5034
leaq 0xba82b(%rip), %rdx     # 0xe9fe6
movq %r15, %rdi
movl $0x157, %ecx            # imm = 0x157
jmp 0x2f8ad
movq %rbx, %rdi
callq 0x1c593
cmpl $0x1, %eax
jne 0x2f865
leaq 0xb5c10(%rip), %rsi     # 0xe53f0
leaq 0xba90e(%rip), %rdx     # 0xea0f5
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xb5831(%rip), %rsi     # 0xe5034
leaq 0xba7dc(%rip), %rdx     # 0xe9fe6
movq %r15, %rdi
movl $0x136, %ecx            # imm = 0x136
jmp 0x2f8ad
leaq 0x38(%rsp), %rdi
callq 0x1c593
cmpl $0x1, %eax
jne 0x2f8bc
leaq 0xb5bbf(%rip), %rsi     # 0xe53f0
leaq 0xba8ce(%rip), %rdx     # 0xea106
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xb57e0(%rip), %rsi     # 0xe5034
leaq 0xba78b(%rip), %rdx     # 0xe9fe6
movq %r15, %rdi
movl $0x15a, %ecx            # imm = 0x15A
jmp 0x2f8ad
leaq 0x38(%rsp), %rdi
callq 0x1c593
cmpl $0x1, %eax
jne 0x2f8cb
leaq 0xb5b75(%rip), %rsi     # 0xe53f0
leaq 0xba884(%rip), %rdx     # 0xea106
leaq 0x460(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2e014
leaq 0xb5796(%rip), %rsi     # 0xe5034
leaq 0xba741(%rip), %rdx     # 0xe9fe6
movq %r15, %rdi
movl $0x139, %ecx            # imm = 0x139
movq %rbx, %r8
xorl %eax, %eax
callq 0x2e014
jmp 0x2f263
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, (%rax)
jmp 0x2f8d3
movq 0x18(%rsp), %rax
movq %r14, (%rax)
xorl %r12d, %r12d
jmp 0x2f263