// File: /workspace/github_c_makefile_star2_O0/radforddc[P]icpc_siggen/signal_tester.c
// Function: write_spectrum
static int write_spectrum(float *spec, int nchs, char *name){  
  FILE *fp;
  int record_length;
  struct spe_header header;
  char *suffix_start;
  char *fname_start;

  header.reclA = header.reclB = 24; 
  header.title[0] = header.title[1] = 0;
  header.a1 = header.a2 = header.a3 = 1;

  fp = fopen(name,"w");
  if (fp == NULL){
    fprintf(stderr,"Error! Unable to open spectrum file %s \n",name);
    return 0;
  }
  header.dim = nchs;
  if ((suffix_start = strstr(name,".spe")) == NULL){
    suffix_start = name + strlen(name);
  }
  if ((fname_start = rindex(name,'/')) == NULL){
    fname_start = name; 
  }else{
    fname_start++;/*get rid of the '/'*/
  }
  if (suffix_start - fname_start < 8){
    memcpy(header.title,"       ",8);/*blank the title*/
    memcpy(header.title,fname_start,suffix_start - fname_start);
  }else{ 
    memcpy(header.title,suffix_start - 8,8);
  }
  record_length = sizeof(float)*header.dim;

  fwrite(&header, sizeof(header), 1, fp);
  fwrite(&record_length, sizeof(record_length), 1, fp);
  fwrite(spec, sizeof(float), nchs, fp); 
  fwrite(&record_length, sizeof(record_length), 1,fp);
  fclose(fp);

  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x18, -0x30(%rbp)
movl $0x18, -0x4c(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x1, -0x34(%rbp)
movl $0x1, -0x38(%rbp)
movl $0x1, -0x3c(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x2795(%rip), %rsi      # 0xe884
callq 0x20c0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xc127
movq 0x4eea(%rip), %rax      # 0x10ff0
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0x2772(%rip), %rsi      # 0xe886
movb $0x0, %al
callq 0x2220
movl $0x0, -0x4(%rbp)
jmp 0xc250
movl -0x14(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x2777(%rip), %rsi      # 0xe8af
callq 0x2170
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
jne 0xc166
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2130
movq %rax, %rcx
movq -0x68(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rdi
movl $0x2f, %esi
callq 0x20f0
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
jne 0xc188
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0xc194
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movq -0x60(%rbp), %rcx
subq %rcx, %rax
cmpq $0x8, %rax
jge 0xc1ce
movq 0x2708(%rip), %rax      # 0xe8b4
movq %rax, -0x48(%rbp)
leaq -0x4c(%rbp), %rdi
addq $0x4, %rdi
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x60(%rbp), %rax
subq %rax, %rdx
callq 0x2260
jmp 0xc1da
movq -0x58(%rbp), %rax
movq -0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movslq -0x40(%rbp), %rax
shlq $0x2, %rax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rcx
leaq -0x4c(%rbp), %rdi
movl $0x20, %esi
movl $0x1, %edx
callq 0x2200
movq -0x28(%rbp), %rcx
leaq -0x2c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x2200
movq -0x10(%rbp), %rdi
movslq -0x14(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x4, %esi
callq 0x2200
movq -0x28(%rbp), %rcx
leaq -0x2c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x2200
movq -0x28(%rbp), %rdi
callq 0x21e0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq