// File: /workspace/github_c_makefile_star2_O3/PoulinV[P]AxiCLASS/build/../source/output.c
// Function: output_distortions
int output_distortions(
                       struct distortions * psd,
                       struct output * pop
                       ) {

  /** Local variables*/
  FileName file_name_heat, file_name_distortion;
  FILE * out_heat, * out_distortion;

  char titles_heat[_MAXTITLESTRINGLENGTH_]={0};
  char titles_distortion[_MAXTITLESTRINGLENGTH_]={0};

  double * data_heat, * data_distortion;
  int size_data_heat, size_data_distortion;
  int number_of_titles_heat, number_of_titles_distortion;

  if (pop->write_distortions==_TRUE_ && psd->has_distortions == _TRUE_){

    /* File name */
    class_sprintf(file_name_heat,"%s%s",pop->root,"sd_heating.dat");

    /* Titles */
    class_call(distortions_output_heat_titles(psd,titles_heat),
               psd->error_message,
               pop->error_message);
    number_of_titles_heat = get_number_of_titles(titles_heat);

    /* Data array */
    size_data_heat = number_of_titles_heat*psd->z_size;
    class_alloc(data_heat,
                sizeof(double)*size_data_heat,
                pop->error_message);
    class_call(distortions_output_heat_data(psd,
                                            number_of_titles_heat,
                                            data_heat),
               psd->error_message,
               pop->error_message);

    /* File IO */
    class_open(out_heat,
               file_name_heat,
               "w",
               pop->error_message);

    if (pop->write_header == _TRUE_){
      fprintf(out_heat,"# Heat is d(Q/rho)/dz\n");
      fprintf(out_heat,"# LHeat is d(Q/rho)/dlnz\n");
      fprintf(out_heat,"#\n");
    }

    output_print_data(out_heat,
                      titles_heat,
                      data_heat,
                      size_data_heat);
    free(data_heat);
    fclose(out_heat);

    /* File name */
    class_sprintf(file_name_distortion,"%s%s",pop->root,"sd_distortions.dat");

    /* Titles */
    class_call(distortions_output_sd_titles(psd,titles_distortion),
               psd->error_message,
               pop->error_message);
    number_of_titles_distortion = get_number_of_titles(titles_distortion);

    /* Data array */
    size_data_distortion = number_of_titles_distortion*psd->x_size;
    class_alloc(data_distortion,
                sizeof(double)*size_data_distortion,
                pop->error_message);
    class_call(distortions_output_sd_data(psd,
                                          number_of_titles_distortion,
                                          data_distortion),
               psd->error_message,
               pop->error_message);

    /* File IO */
    class_open(out_distortion,
               file_name_distortion,
               "w",
               pop->error_message);

    if (pop->write_header == _TRUE_){
      fprintf(out_distortion,"# SD_tot is the amplitude of the overall spectral distortion (SD)\n");
      fprintf(out_distortion,"# The SD[i] are the amplitudes of the individual SDs\n");
      fprintf(out_distortion,"# The SDs are given in units [10^-26 W m^-2 Hz^-1 sr^-1] \n");
      fprintf(out_distortion,"#\n");
    }

    output_print_data(out_distortion,
                      titles_distortion,
                      data_distortion,
                      size_data_distortion);
    free(data_distortion);
    fclose(out_distortion);
  }

  return _SUCCESS_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4888, %rsp           # imm = 0x4888
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x2940(%rsp), %rdi
xorl %ebp, %ebp
movl $0x1f40, %edx           # imm = 0x1F40
xorl %esi, %esi
callq 0x8200
leaq 0xa00(%rsp), %rdi
movl $0x1f40, %edx           # imm = 0x1F40
xorl %esi, %esi
callq 0x8200
cmpw $0x1, 0x41c(%rbx)
jne 0xec005
cmpl $0x1, 0xcd0(%r14)
jne 0xec005
leaq 0x43d73(%rip), %r15     # 0x12f890
leaq 0x44b85(%rip), %r12     # 0x1306a9
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
leaq 0x100(%rsp), %rdi
movq %r15, %rdx
movq %rbx, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x8550
leaq 0x2940(%rsp), %rsi
movq %r14, %rdi
callq 0xcd68c
cmpl $0x1, %eax
jne 0xebbb6
addq $0x1602, %r14           # imm = 0x1602
leaq 0x2878(%rip), %rsi      # 0xee3f0
leaq 0x44b39(%rip), %rdx     # 0x1306b8
leaq 0x200(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x2492(%rip), %rsi      # 0xee034
leaq 0x44b3f(%rip), %rdx     # 0x1306e8
movq %rbx, %rdi
movl $0x5e5, %ecx            # imm = 0x5E5
jmp 0xebeaf
leaq 0x2940(%rsp), %rdi
callq 0x30c32
movl %eax, %ebp
movslq 0x330(%r14), %rax
movslq %ebp, %r15
imulq %rax, %r15
leaq (,%r15,8), %r13
movq %r13, %rdi
callq 0x8460
testq %rax, %rax
je 0xebc4d
movq %rax, %r12
movq %r14, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0xcd71d
cmpl $0x1, %eax
jne 0xebc92
addq $0x1602, %r14           # imm = 0x1602
leaq 0x27e1(%rip), %rsi      # 0xee3f0
leaq 0x44aef(%rip), %rdx     # 0x130705
leaq 0x200(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x23fb(%rip), %rsi      # 0xee034
leaq 0x44aa8(%rip), %rdx     # 0x1306e8
movq %rbx, %rdi
movl $0x5f1, %ecx            # imm = 0x5F1
jmp 0xebeaf
leaq 0x23b0(%rip), %rsi      # 0xee004
leaq 0x44aa0(%rip), %rdx     # 0x1306fb
leaq 0x200(%rsp), %r14
movq %r14, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x23b6(%rip), %rsi      # 0xee034
leaq 0x44a63(%rip), %rdx     # 0x1306e8
movq %rbx, %rdi
movl $0x5ec, %ecx            # imm = 0x5EC
jmp 0xebff6
leaq 0x5788(%rip), %rsi      # 0xf1421
leaq 0x100(%rsp), %rdi
callq 0x8400
testq %rax, %rax
je 0xebdcc
movq %rax, %r13
cmpw $0x1, 0x408(%rbx)
jne 0xebd07
leaq 0x44a8f(%rip), %rdi     # 0x130752
movl $0x16, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x86d0
leaq 0x44a8d(%rip), %rdi     # 0x130769
movl $0x19, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x86d0
leaq 0x1e7e0(%rip), %rdi     # 0x10a4d5
movl $0x2, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x86d0
leaq 0x2940(%rsp), %rsi
movq %r13, %rdi
movq %r12, %rdx
movl %r15d, %ecx
callq 0xed1c2
movq %r12, %rdi
callq 0x8410
movq %r13, %rdi
callq 0x83a0
leaq 0x43b5c(%rip), %r15     # 0x12f890
leaq 0x44a48(%rip), %r12     # 0x130783
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x8550
incl %eax
movslq %eax, %rsi
movq %rsp, %rdi
movq %r15, %rdx
movq %rbx, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x8550
leaq 0xa00(%rsp), %rsi
movq %r14, %rdi
callq 0xcd783
cmpl $0x1, %eax
jne 0xebe1d
addq $0x1602, %r14           # imm = 0x1602
leaq 0x2662(%rip), %rsi      # 0xee3f0
leaq 0x44a01(%rip), %rdx     # 0x130796
leaq 0x200(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x227c(%rip), %rsi      # 0xee034
leaq 0x44929(%rip), %rdx     # 0x1306e8
movq %rbx, %rdi
movl $0x60c, %ecx            # imm = 0x60C
jmp 0xebeaf
leaq 0x4c15(%rip), %rsi      # 0xf09e8
leaq 0x4496f(%rip), %rdx     # 0x130749
leaq 0x1e64b(%rip), %r8      # 0x10a42c
leaq 0x200(%rsp), %r14
leaq 0x100(%rsp), %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x222b(%rip), %rsi      # 0xee034
leaq 0x448d8(%rip), %rdx     # 0x1306e8
movq %rbx, %rdi
movl $0x5f7, %ecx            # imm = 0x5F7
jmp 0xebff6
leaq 0xa00(%rsp), %rdi
callq 0x30c32
movl %eax, %ebp
movslq 0x368(%r14), %rax
movslq %ebp, %r15
imulq %rax, %r15
leaq (,%r15,8), %r13
movq %r13, %rdi
callq 0x8460
testq %rax, %rax
je 0xebeb7
movq %rax, %r12
movq %r14, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0xcd8df
cmpl $0x1, %eax
jne 0xebefc
addq $0x1602, %r14           # imm = 0x1602
leaq 0x257a(%rip), %rsi      # 0xee3f0
leaq 0x4495d(%rip), %rdx     # 0x1307da
leaq 0x200(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x2194(%rip), %rsi      # 0xee034
leaq 0x44841(%rip), %rdx     # 0x1306e8
movq %rbx, %rdi
movl $0x618, %ecx            # imm = 0x618
movq %r15, %r8
jmp 0xebff9
leaq 0x2146(%rip), %rsi      # 0xee004
leaq 0x44905(%rip), %rdx     # 0x1307ca
leaq 0x200(%rsp), %r14
movq %r14, %rdi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x214c(%rip), %rsi      # 0xee034
leaq 0x447f9(%rip), %rdx     # 0x1306e8
movq %rbx, %rdi
movl $0x613, %ecx            # imm = 0x613
jmp 0xebff6
leaq 0x551e(%rip), %rsi      # 0xf1421
movq %rsp, %rdi
callq 0x8400
testq %rax, %rax
je 0xebfaf
movq %rax, %r14
cmpw $0x1, 0x408(%rbx)
jne 0xebf85
leaq 0x4490f(%rip), %rdi     # 0x130837
movl $0x42, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x86d0
leaq 0x44939(%rip), %rdi     # 0x13087a
movl $0x35, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x86d0
leaq 0x44956(%rip), %rdi     # 0x1308b0
movl $0x3a, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x86d0
leaq 0x1e562(%rip), %rdi     # 0x10a4d5
movl $0x2, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x86d0
leaq 0xa00(%rsp), %rsi
movq %r14, %rdi
movq %r12, %rdx
movl %r15d, %ecx
callq 0xed1c2
movq %r12, %rdi
callq 0x8410
movq %r14, %rdi
callq 0x83a0
xorl %ebp, %ebp
jmp 0xec005
leaq 0x4a32(%rip), %rsi      # 0xf09e8
leaq 0x4486b(%rip), %rdx     # 0x130828
leaq 0x1e468(%rip), %r8      # 0x10a42c
leaq 0x200(%rsp), %r14
movq %rsp, %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x30af0
addq $0x420, %rbx            # imm = 0x420
leaq 0x204d(%rip), %rsi      # 0xee034
leaq 0x446fa(%rip), %rdx     # 0x1306e8
movq %rbx, %rdi
movl $0x61e, %ecx            # imm = 0x61E
movq %r14, %r8
xorl %eax, %eax
callq 0x30af0
movl $0x1, %ebp
movl %ebp, %eax
addq $0x4888, %rsp           # imm = 0x4888
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq