// File: /workspace/github_c_makefile_star2_O2/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 0x2b3d(%rip), %rsi      # 0x6a70
callq 0x11b0
testq %rax, %rax
je 0x40e0
movq %rax, %r15
pushq $0x1
popq %rdx
movl $0x278, %esi            # imm = 0x278
movq %r12, %rdi
movq %rax, %rcx
callq 0x1070
cmpq $0x1, %rax
jne 0x40f3
movss 0x8(%rsp), %xmm0
subss 0xc(%rsp), %xmm0
movss (%r12), %xmm1
movss %xmm1, 0x8(%rsp)
divss %xmm1, %xmm0
callq 0x1160
cvttss2si %xmm0, %ebp
testl %ebp, %ebp
jle 0x40be
movl %ebp, %edi
pushq $0x4
popq %rsi
callq 0x1100
testq %rax, %rax
je 0x40be
movq %rax, %r14
leal 0x5(%r13), %eax
cmpl $0x3, %eax
ja 0x406f
cmpl $0x1, %eax
je 0x406f
movslq %r13d, %rax
movss 0x28(%r12,%rax,4), %xmm0
ucomiss 0x2a7d(%rip), %xmm0     # 0x6a48
jne 0x3fd3
jnp 0x4106
movq %rbx, 0x10(%rsp)
addss 0xc(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
subss 0x14(%r12), %xmm0
divss 0x8(%rsp), %xmm0
callq 0x1160
cvttss2si %xmm0, %ebx
movl 0x13c(%r12), %r13d
movl %ebp, 0x13c(%r12)
movss 0xc(%rsp), %xmm1
movss %xmm1, 0x14(%r12)
cvtsi2ss %ebp, %xmm0
mulss 0x8(%rsp), %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x18(%r12)
cmpl %ebx, %r13d
jle 0x4124
addl %ebx, %ebp
js 0x4124
testl %ebx, %ebx
js 0x4081
movl %ebx, %esi
shlq $0x2, %rsi
pushq $0x1
popq %rdx
movq %r15, %rdi
callq 0x1190
movq %r14, %rdi
testl %eax, %eax
jns 0x4090
movq 0x5f98(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2b97(%rip), %rsi      # 0x6c01
jmp 0x4147
xorps %xmm0, %xmm0
cmpl $0x9, %r13d
jbe 0x3fba
jmp 0x3fd3
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
pushq $0x4
popq %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x1070
cmpq %r12, %rax
jne 0x4136
movq %r15, %rdi
callq 0x1090
jmp 0x4124
movq 0x5f33(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2ae7(%rip), %rsi      # 0x6bb6
xorl %r14d, %r14d
movq %rbx, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x1110
jmp 0x4124
movq 0x5f11(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2982(%rip), %rsi      # 0x6a73
jmp 0x4117
movq 0x5efe(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2982(%rip), %rsi      # 0x6a86
jmp 0x4117
movq 0x5eeb(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2acf(%rip), %rsi      # 0x6be6
xorl %r14d, %r14d
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1110
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5ebb(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x298a(%rip), %rsi      # 0x6ad1
xorl %r14d, %r14d
movq 0x10(%rsp), %rdx
jmp 0x411d