// File: /workspace/github_c_makefile_star2_O1/YunyiQian[P]multitel3/sacio.c
// Function: read_sac2
float*	read_sac2(const char	*name,
		SACHEAD		*hd,
		int		tmark,
		float		t1,
		float		t2
	)
{
  FILE		*strm;
  int		nn, nt1, nt2, npts;
  float		tref, *ar, *fpt;

  if ((strm = fopen(name, "rb")) == NULL) {
     fprintf(stderr, "Unable to open %s\n",name);
     return NULL;
  }

  if (fread(hd, sizeof(SACHEAD), 1, strm) != 1) {
     fprintf(stderr, "Error in reading SAC header %s\n",name);
     return NULL;
  }

#ifdef BYTE_SWAP
  swab4((char *) hd, HD_SIZE);
#endif

  nn = (int) rint((t2-t1)/hd->delta);
  if (nn<=0 || (ar = (float *) calloc(nn,sizeof(float)))==NULL) {
     fprintf(stderr, "Error in allocating memory for reading %s n=%d\n",name,nn);
     return NULL;
  }
  tref = 0.;
  if (tmark==-5 || tmark==-3 || tmark==-2 || (tmark>=0&&tmark<10) ) {
     tref = *( (float *) hd + 10 + tmark);
     if (tref==-12345.) {
        fprintf(stderr,"Time mark undefined in %s\n",name);
        return NULL;
     }
  }
  t1 += tref;
  nt1 = (int) rint((t1-hd->b)/hd->delta);
  nt2 = nt1+nn;
  npts = hd->npts;
  hd->npts = nn;
  hd->b = t1;
  hd->e = t1+nn*hd->delta;

  if ( nt1>=npts || nt2<0 ) return ar;

  if (nt1<0) {
     fpt = ar-nt1;
     nt1 = 0;
  } else {
     if (fseek(strm,nt1*sizeof(float),SEEK_CUR) < 0) {
	fprintf(stderr, "error in seek %s\n",name);
	return NULL;
     }
     fpt = ar;
  }
  if (nt2>npts) nt2=npts;
  nn = nt2-nt1;
  if (fread((char *) fpt, sizeof(float), nn, strm) != nn) {
     fprintf(stderr, "Error in reading SAC data %s\n",name);
     return NULL;
  }
  fclose(strm);
#ifdef BYTE_SWAP
  swab4((char *) fpt, nn*sizeof(float));
#endif
  return ar;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movss %xmm1, 0x8(%rsp)
movss %xmm0, 0xc(%rsp)
movl %edx, %r13d
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x271b(%rip), %rsi      # 0x6a60
callq 0x11c0
testq %rax, %rax
je 0x44fd
movq %rax, %r15
movl $0x278, %esi            # imm = 0x278
movl $0x1, %edx
movq %r12, %rdi
movq %rax, %rcx
callq 0x1070
cmpq $0x1, %rax
jne 0x4510
movss 0x8(%rsp), %xmm0
subss 0xc(%rsp), %xmm0
movss (%r12), %xmm1
movss %xmm1, 0x8(%rsp)
divss %xmm1, %xmm0
callq 0x1170
cvttss2si %xmm0, %ebp
testl %ebp, %ebp
jle 0x44db
movl %ebp, %edi
movl $0x4, %esi
callq 0x1110
testq %rax, %rax
je 0x44db
movq %rax, %r14
leal 0x5(%r13), %eax
cmpl $0x3, %eax
ja 0x448a
cmpl $0x1, %eax
je 0x448a
movslq %r13d, %rax
movss 0x28(%r12,%rax,4), %xmm0
ucomiss 0x2667(%rip), %xmm0     # 0x6a48
jne 0x43e9
jnp 0x4523
movq %rbx, 0x10(%rsp)
addss 0xc(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
subss 0x14(%r12), %xmm0
divss 0x8(%rsp), %xmm0
callq 0x1170
cvttss2si %xmm0, %ebx
movl 0x13c(%r12), %r13d
movl %ebp, 0x13c(%r12)
movss 0xc(%rsp), %xmm1
movss %xmm1, 0x14(%r12)
xorps %xmm0, %xmm0
cvtsi2ss %ebp, %xmm0
mulss 0x8(%rsp), %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x18(%r12)
cmpl %ebx, %r13d
jle 0x4541
addl %ebx, %ebp
js 0x4541
testl %ebx, %ebx
js 0x449c
movl %ebx, %esi
shlq $0x2, %rsi
movq %r15, %rdi
movl $0x1, %edx
callq 0x11a0
movq %r14, %rdi
testl %eax, %eax
jns 0x44ab
movq 0x5b7d(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x276c(%rip), %rsi      # 0x6bf1
jmp 0x4564
xorps %xmm0, %xmm0
cmpl $0x9, %r13d
jbe 0x43d0
jmp 0x43e9
movslq %ebx, %rax
shlq $0x2, %rax
movq %r14, %rdi
subq %rax, %rdi
xorl %ebx, %ebx
cmpl %r13d, %ebp
cmovll %ebp, %r13d
subl %ebx, %r13d
movslq %r13d, %r12
movl $0x4, %esi
movq %r12, %rdx
movq %r15, %rcx
callq 0x1070
cmpq %r12, %rax
jne 0x4553
movq %r15, %rdi
callq 0x1090
jmp 0x4541
movq 0x5b16(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x26ba(%rip), %rsi      # 0x6ba6
xorl %r14d, %r14d
movq %rbx, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x1120
jmp 0x4541
movq 0x5af4(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2555(%rip), %rsi      # 0x6a63
jmp 0x4534
movq 0x5ae1(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2555(%rip), %rsi      # 0x6a76
jmp 0x4534
movq 0x5ace(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x26a2(%rip), %rsi      # 0x6bd6
xorl %r14d, %r14d
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1120
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5a9e(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x255d(%rip), %rsi      # 0x6ac1
xorl %r14d, %r14d
movq 0x10(%rsp), %rdx
jmp 0x453a