// File: /workspace/github_c_makefile_star2_O0/YunyiQian[P]multitel3/sacio.c
// Function: write_sac
int	write_sac(const char	*name,
		SACHEAD		hd,
		const float	*ar
	)
{
  FILE		*strm;
  unsigned	sz;
  float		*data;
  int		error = 0;

  sz = hd.npts*sizeof(float);
  if (hd.iftype == IXY) sz *= 2;

  if ((data = (float *) malloc(sz)) == NULL) {
     fprintf(stderr, "Error in allocating memory for writing %s\n",name);
     error = 1;
  }

  if ( !error && memcpy(data, ar, sz) == NULL) {
     fprintf(stderr, "Error in copying data for writing %s\n",name);
     error = 1;
  }

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

  if ( !error && (strm = fopen(name, "w")) == NULL ) {
     fprintf(stderr,"Error in opening file for writing %s\n",name);
     error = 1;
  }

  if ( !error && fwrite(&hd, sizeof(SACHEAD), 1, strm) != 1 ) {
     fprintf(stderr,"Error in writing SAC header for writing %s\n",name);
     error = 1;
  }

  if ( !error && fwrite(data, sz, 1, strm) != 1 ) {
     fprintf(stderr,"Error in writing SAC data for writing %s\n",name);
     error = 1;
  }

  free(data);
  fclose(strm);

  return (error==0) ? 0 : -1;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x2c(%rbp)
movslq 0x13c(%rax), %rcx
shlq $0x2, %rcx
movl %ecx, -0x1c(%rbp)
cmpl $0x4, 0x154(%rax)
jne 0x4bce
movl -0x1c(%rbp), %eax
shll %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, %edi
callq 0x1130
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x4c05
movq 0x640f(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x3ed8(%rip), %rsi      # 0x8acf
movb $0x0, %al
callq 0x1100
movl $0x1, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x4c4e
movq -0x28(%rbp), %rdi
movq %rdi, -0x40(%rbp)
movq -0x10(%rbp), %rsi
movl -0x1c(%rbp), %eax
movl %eax, %edx
callq 0x1110
movq -0x40(%rbp), %rax
cmpq $0x0, %rax
jne 0x4c4e
movq 0x63c6(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x3eba(%rip), %rsi      # 0x8afa
movb $0x0, %al
callq 0x1100
movl $0x1, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x4c91
movq -0x8(%rbp), %rdi
leaq 0x3ec1(%rip), %rsi      # 0x8b20
callq 0x1180
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x4c91
movq 0x6383(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x3e9f(%rip), %rsi      # 0x8b22
movb $0x0, %al
callq 0x1100
movl $0x1, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x4cd7
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x278, %esi            # imm = 0x278
movl $0x1, %edx
callq 0x11e0
cmpq $0x1, %rax
je 0x4cd7
movq 0x633d(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x3e7f(%rip), %rsi      # 0x8b48
movb $0x0, %al
callq 0x1100
movl $0x1, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x4d1d
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
movq -0x18(%rbp), %rcx
movl $0x1, %edx
callq 0x11e0
cmpq $0x1, %rax
je 0x4d1d
movq 0x62f7(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x3e65(%rip), %rsi      # 0x8b74
movb $0x0, %al
callq 0x1100
movl $0x1, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1040
movq -0x18(%rbp), %rdi
callq 0x1090
movl -0x2c(%rbp), %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)