// File: /workspace/github_c_makefile_star2_O3/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 0x2631(%rip), %rsi      # 0x6ad0
callq 0x11c0
testq %rax, %rax
je 0x4657
movq %rax, %r15
movl $0x278, %esi            # imm = 0x278
movl $0x1, %edx
movq %r12, %rdi
movq %rax, %rcx
callq 0x1070
cmpq $0x1, %rax
jne 0x466a
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 0x4635
movl %ebp, %edi
movl $0x4, %esi
callq 0x1110
testq %rax, %rax
je 0x4635
movq %rax, %r14
leal 0x5(%r13), %eax
cmpl $0x3, %eax
ja 0x45e4
cmpl $0x1, %eax
je 0x45e4
movslq %r13d, %rax
movss 0x28(%r12,%rax,4), %xmm0
ucomiss 0x256d(%rip), %xmm0     # 0x6aa8
jne 0x4543
jnp 0x467d
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 0x469b
addl %ebx, %ebp
js 0x469b
testl %ebx, %ebx
js 0x45f6
movl %ebx, %esi
shlq $0x2, %rsi
movq %r15, %rdi
movl $0x1, %edx
callq 0x11a0
movq %r14, %rdi
testl %eax, %eax
jns 0x4605
movq 0x5a23(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2682(%rip), %rsi      # 0x6c61
jmp 0x46be
xorps %xmm0, %xmm0
cmpl $0x9, %r13d
jbe 0x452a
jmp 0x4543
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 0x46ad
movq %r15, %rdi
callq 0x1090
jmp 0x469b
movq 0x59bc(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x25d0(%rip), %rsi      # 0x6c16
xorl %r14d, %r14d
movq %rbx, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x1120
jmp 0x469b
movq 0x599a(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x246b(%rip), %rsi      # 0x6ad3
jmp 0x468e
movq 0x5987(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x246b(%rip), %rsi      # 0x6ae6
jmp 0x468e
movq 0x5974(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x25b8(%rip), %rsi      # 0x6c46
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 0x5944(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2473(%rip), %rsi      # 0x6b31
xorl %r14d, %r14d
movq 0x10(%rsp), %rdx
jmp 0x4694