// File: /workspace/github_c_makefile_star2_O0/zpole[P]IICV/src/sift.c
// Function: save_gss
static int
save_gss (VlSiftFilt * filt, VlFileMeta * fm, const char * basename,
          int verbose)
{
  char tmp [1024] ;
  int S = filt -> S ;
  int i ;
  int s, err = 0 ;
  int w, h ;
  int o = filt -> o_cur ;
  VlPgmImage pim ;
  vl_uint8 *buffer = 0 ;
  vl_size q ;

  if (! fm -> active) {
    return VL_ERR_OK ;
  }

  w = vl_sift_get_octave_width  (filt) ;
  h = vl_sift_get_octave_height (filt) ;

  pim.width     = w ;
  pim.height    = h ;
  pim.max_value = 255 ;
  pim.is_raw    = 1 ;

  buffer = malloc (sizeof(vl_uint8) * w * h) ;
  if (! buffer) {
    err = VL_ERR_ALLOC ;
    goto save_gss_quit ;
  }

  q = vl_string_copy (tmp, sizeof(tmp), basename) ;
  if (q >= sizeof(tmp)) {
    err = VL_ERR_OVERFLOW ;
    goto save_gss_quit ;
  }

  for (s = 0 ; s < S ; ++s) {
    vl_sift_pix * pt = vl_sift_get_octave (filt, s) ;

    /* conversion */
    for (i = 0 ; i < w * h ; ++i) {
      buffer [i] = (vl_uint8) pt [i] ;
    }

    /* save */
    snprintf(tmp + q, sizeof(tmp) - q, "_%02d_%03d", o, s) ;

    err = vl_file_meta_open (fm, tmp, "wb") ;
    if (err) goto save_gss_quit ;

    err = vl_pgm_insert (fm -> file, &pim, buffer) ;
    if (err) goto save_gss_quit ;

    if (verbose) {
      printf("sift: saved gss level to '%s'\n", fm -> name) ;
    }

    vl_file_meta_close (fm) ;
  }

 save_gss_quit : ;
  if (buffer) free (buffer) ;
  vl_file_meta_close (fm) ;
  return err ;
}

// Assembly:
subq $0x488, %rsp            # imm = 0x488
movq %rdi, 0x478(%rsp)
movq %rsi, 0x470(%rsp)
movq %rdx, 0x468(%rsp)
movl %ecx, 0x464(%rsp)
movq 0x478(%rsp), %rax
movl 0x2c(%rax), %eax
movl %eax, 0x5c(%rsp)
movl $0x0, 0x50(%rsp)
movq 0x478(%rsp), %rax
movl 0x3c(%rax), %eax
movl %eax, 0x44(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x470(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x4b42
movl $0x0, 0x484(%rsp)
jmp 0x4d4a
movq 0x478(%rsp), %rdi
callq 0x4fb0
movl %eax, 0x4c(%rsp)
movq 0x478(%rsp), %rdi
callq 0x4fc0
movl %eax, 0x48(%rsp)
movslq 0x4c(%rsp), %rax
movq %rax, 0x20(%rsp)
movslq 0x48(%rsp), %rax
movq %rax, 0x28(%rsp)
movq $0xff, 0x30(%rsp)
movl $0x1, 0x38(%rsp)
movslq 0x4c(%rsp), %rdi
shlq $0x0, %rdi
movslq 0x48(%rsp), %rax
imulq %rax, %rdi
callq 0x2160
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x4bba
movl $0x2, 0x50(%rsp)
jmp 0x4d20
leaq 0x60(%rsp), %rdi
movq 0x468(%rsp), %rdx
movl $0x400, %esi            # imm = 0x400
callq 0x2280
movq %rax, 0x10(%rsp)
cmpq $0x400, 0x10(%rsp)      # imm = 0x400
jb 0x4bee
movl $0x1, 0x50(%rsp)
jmp 0x4d20
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jge 0x4d1e
movq 0x478(%rsp), %rdi
movl 0x54(%rsp), %esi
callq 0x4fd0
movq %rax, 0x8(%rsp)
movl $0x0, 0x58(%rsp)
movl 0x58(%rsp), %eax
movl 0x4c(%rsp), %ecx
imull 0x48(%rsp), %ecx
cmpl %ecx, %eax
jge 0x4c5e
movq 0x8(%rsp), %rax
movslq 0x58(%rsp), %rcx
cvttss2si (%rax,%rcx,4), %eax
movb %al, %dl
movq 0x18(%rsp), %rax
movslq 0x58(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x4c22
leaq 0x60(%rsp), %rdi
addq 0x10(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
subq 0x10(%rsp), %rsi
movl 0x44(%rsp), %ecx
movl 0x54(%rsp), %r8d
leaq 0x4687(%rip), %rdx      # 0x9309
movb $0x0, %al
callq 0x20e0
movq 0x470(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x439c(%rip), %rdx      # 0x9039
callq 0x4790
movl %eax, 0x50(%rsp)
cmpl $0x0, 0x50(%rsp)
je 0x4caf
jmp 0x4d20
movq 0x470(%rsp), %rax
movq 0x808(%rax), %rdi
movq 0x18(%rsp), %rdx
leaq 0x20(%rsp), %rsi
callq 0x2050
movl %eax, 0x50(%rsp)
cmpl $0x0, 0x50(%rsp)
je 0x4cda
jmp 0x4d20
cmpl $0x0, 0x464(%rsp)
je 0x4d01
movq 0x470(%rsp), %rsi
addq $0x408, %rsi            # imm = 0x408
leaq 0x461a(%rip), %rdi      # 0x9314
movb $0x0, %al
callq 0x20c0
movq 0x470(%rsp), %rdi
callq 0x4990
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x4bf6
jmp 0x4d20
cmpq $0x0, 0x18(%rsp)
je 0x4d32
movq 0x18(%rsp), %rdi
callq 0x2030
movq 0x470(%rsp), %rdi
callq 0x4990
movl 0x50(%rsp), %eax
movl %eax, 0x484(%rsp)
movl 0x484(%rsp), %eax
addq $0x488, %rsp            # imm = 0x488
retq
nopl (%rax)