// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movss %xmm0, -0x20(%rbp)
movss %xmm1, -0x24(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x35c8(%rip), %rsi      # 0x8a50
callq 0x1180
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x54c0
movq 0x5b5a(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x35a7(%rip), %rsi      # 0x8a53
movb $0x0, %al
callq 0x1100
movq $0x0, -0x8(%rbp)
jmp 0x5770
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rcx
movl $0x278, %esi            # imm = 0x278
movl $0x1, %edx
callq 0x1070
cmpq $0x1, %rax
je 0x5506
movq 0x5b14(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x3574(%rip), %rsi      # 0x8a66
movb $0x0, %al
callq 0x1100
movq $0x0, -0x8(%rbp)
jmp 0x5770
movss -0x24(%rbp), %xmm0
subss -0x20(%rbp), %xmm0
movq -0x18(%rbp), %rax
divss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1120
cvttsd2si %xmm0, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0x5546
movslq -0x34(%rbp), %rdi
movl $0x4, %esi
callq 0x10f0
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
jne 0x5572
movq 0x5aab(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
movl -0x34(%rbp), %ecx
leaq 0x3678(%rip), %rsi      # 0x8bd6
movb $0x0, %al
callq 0x1100
movq $0x0, -0x8(%rbp)
jmp 0x5770
xorps %xmm0, %xmm0
movss %xmm0, -0x44(%rbp)
cmpl $-0x5, -0x1c(%rbp)
je 0x5598
cmpl $-0x3, -0x1c(%rbp)
je 0x5598
cmpl $-0x2, -0x1c(%rbp)
je 0x5598
cmpl $0x0, -0x1c(%rbp)
jl 0x55ef
cmpl $0xa, -0x1c(%rbp)
jge 0x55ef
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movss 0x28(%rax,%rcx,4), %xmm0
movss %xmm0, -0x44(%rbp)
movss -0x44(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x348c(%rip), %xmm1     # 0x8a48
ucomisd %xmm1, %xmm0
jne 0x55ed
jp 0x55ed
movq 0x5a2d(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x362d(%rip), %rsi      # 0x8c06
movb $0x0, %al
callq 0x1100
movq $0x0, -0x8(%rbp)
jmp 0x5770
jmp 0x55ef
movss -0x44(%rbp), %xmm0
addss -0x20(%rbp), %xmm0
movss %xmm0, -0x20(%rbp)
movss -0x20(%rbp), %xmm0
movq -0x18(%rbp), %rax
subss 0x14(%rax), %xmm0
movq -0x18(%rbp), %rax
divss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1120
cvttsd2si %xmm0, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movl 0x13c(%rax), %eax
movl %eax, -0x40(%rbp)
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x13c(%rax)
movss -0x20(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x14(%rax)
movss -0x20(%rbp), %xmm1
cvtsi2ssl -0x34(%rbp), %xmm0
movq -0x18(%rbp), %rax
movss (%rax), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x18(%rax)
movl -0x38(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x5686
cmpl $0x0, -0x3c(%rbp)
jge 0x5693
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x5770
cmpl $0x0, -0x38(%rbp)
jge 0x56ba
movq -0x50(%rbp), %rax
movslq -0x38(%rbp), %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x38(%rbp)
jmp 0x5703
movq -0x30(%rbp), %rdi
movslq -0x38(%rbp), %rsi
shlq $0x2, %rsi
movl $0x1, %edx
callq 0x1160
cmpl $0x0, %eax
jge 0x56fb
movq 0x591c(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x3537(%rip), %rsi      # 0x8c21
movb $0x0, %al
callq 0x1100
movq $0x0, -0x8(%rbp)
jmp 0x5770
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jle 0x5711
movl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
subl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x58(%rbp), %rdi
movslq -0x34(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl $0x4, %esi
callq 0x1070
movslq -0x34(%rbp), %rcx
cmpq %rcx, %rax
je 0x575f
movq 0x58b8(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x3363(%rip), %rsi      # 0x8ab1
movb $0x0, %al
callq 0x1100
movq $0x0, -0x8(%rbp)
jmp 0x5770
movq -0x30(%rbp), %rdi
callq 0x1090
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)