// File: /workspace/github_c_makefile_star2_O0/zpole[P]IICV/src/test_imopv.c
// Function: main
int
main (int argc, char** argv)
{
  int width = 256 ;
  int height = 256 ;
  int const W = 7 ;

  float * image ;
  float * dest  ;
  float * dest2 ;
  float * filt ;

  int x, y ;

  if (argc < 2) {
    image = vl_malloc (sizeof(float) * width * height) ;
    for (y = 0 ; y < height ; ++y) {
      for (x = 0  ; x < width ; ++x) {
        image [x + width * y] =
        128.0f * (((x % 16) < 8) ^ ((y % 16) < 8)) ;
      }
    }
  } else {
    VlPgmImage im ;
    int err ;
    err = vl_pgm_read_new_f (argv[1], &im, &image) ;
    if (err) {
      VL_PRINTF("test_imopv: error: %s (%d)\n",
                vl_get_last_error_message(),
                vl_get_last_error()) ;
      return -1 ;
    }
    width = im.width ;
    height = im.height ;
  }

  VL_PRINTF("test_imopv: width: %d, height: %d\n", width, height);

  dest  = vl_malloc (sizeof(float) * width * height) ;
  dest2 = vl_malloc (sizeof(float) * width * height) ;
  filt  = vl_malloc (sizeof(float) * (2*W+1)) ;

  for (x = 0 ; x < 2*W+1 ; ++ x) {
    filt [x] = 1.0f / (2*W+1) ;
  }

#if 1
  vl_set_simd_enabled (0) ;
  vl_tic() ;
  {
    int trial = 0 ;
    for (trial = 0 ; trial < 1000 ; ++trial)
      vl_imconvcol_vf (dest, height,
                       image, width, height, width,
                       filt, -W, W, 1,
                       VL_TRANSPOSE|VL_PAD_BY_CONTINUITY) ;
  }
  VL_PRINTF ("Elapsed time no SIMD: %f [s]\n", vl_toc()) ;

  vl_set_simd_enabled (1) ;
  vl_tic() ;
  {
    int trial = 0 ;
    for (trial = 0 ; trial < 1000 ; ++trial)
      vl_imconvcol_vf (dest2, height,
                       image, width, height, width,
                       filt, -W, W, 1,
                       VL_TRANSPOSE|VL_PAD_BY_CONTINUITY) ;
  }
  VL_PRINTF ("Elapsed time with SIMD: %f [s]\n", vl_toc()) ;

#else

  vl_imconvcoltri_vf (dest, height,
                      image, width, height, width,
                      5, 1, VL_TRANSPOSE|VL_PAD_BY_CONTINUITY) ;

  vl_imconvcoltri_vf (dest2, height,
                      image, width, height, width,
                      5, 1, VL_TRANSPOSE|VL_PAD_BY_ZERO) ;
#endif

  vl_pgm_write_f("/tmp/src.pgm", image, width, height) ;
  vl_pgm_write_f("/tmp/test.pgm", dest, height, width) ;
  vl_pgm_write_f("/tmp/test2.pgm", dest2, height, width) ;


  vl_free(image) ;
  vl_free(filt) ;
  vl_free(dest) ;
  vl_free(dest2) ;

  return 0 ;
}

// Assembly:
subq $0xc8, %rsp
movl $0x0, 0xc4(%rsp)
movl %edi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
movl $0x100, 0xb4(%rsp) # imm = 0x100
movl $0x100, 0xb0(%rsp) # imm = 0x100
movl $0x7, 0xac(%rsp)
cmpl $0x2, 0xc0(%rsp)
jge 0x133d
movslq 0xb4(%rsp), %rdi
shlq $0x2, %rdi
movslq 0xb0(%rsp), %rax
imulq %rax, %rdi
callq 0x10c0
movq %rax, 0xa0(%rsp)
movl $0x0, 0x80(%rsp)
movl 0x80(%rsp), %eax
cmpl 0xb0(%rsp), %eax
jge 0x1338
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
cmpl 0xb4(%rsp), %eax
jge 0x1320
movl 0x84(%rsp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
cmpl $0x8, %edx
setl %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x50(%rsp)
movl 0x80(%rsp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl 0x50(%rsp), %eax
cmpl $0x8, %edx
setl %cl
andb $0x1, %cl
movzbl %cl, %ecx
xorl %ecx, %eax
cvtsi2ss %eax, %xmm1
movss 0xd2a(%rip), %xmm0      # 0x2008
mulss %xmm1, %xmm0
movq 0xa0(%rsp), %rax
movl 0x84(%rsp), %ecx
movl 0xb4(%rsp), %edx
imull 0x80(%rsp), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x127f
jmp 0x1322
movl 0x80(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x80(%rsp)
jmp 0x1260
jmp 0x13be
movq 0xb8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x60(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0x10b0
movl %eax, 0x5c(%rsp)
cmpl $0x0, 0x5c(%rsp)
je 0x13a6
callq 0x1050
movq %rax, 0x48(%rsp)
callq 0x1030
movq %rax, 0x40(%rsp)
callq 0x1090
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rcx
movl %eax, %edx
leaq 0xc7a(%rip), %rdi       # 0x200c
movb $0x0, %al
callq *%rcx
movl $0xffffffff, 0xc4(%rsp) # imm = 0xFFFFFFFF
jmp 0x1692
movq 0x60(%rsp), %rax
movl %eax, 0xb4(%rsp)
movq 0x68(%rsp), %rax
movl %eax, 0xb0(%rsp)
callq 0x1050
movq %rax, %rcx
movl 0xb4(%rsp), %esi
movl 0xb0(%rsp), %edx
leaq 0xc4d(%rip), %rdi       # 0x2028
movb $0x0, %al
callq *%rcx
movslq 0xb4(%rsp), %rdi
shlq $0x2, %rdi
movslq 0xb0(%rsp), %rax
imulq %rax, %rdi
callq 0x10c0
movq %rax, 0x98(%rsp)
movslq 0xb4(%rsp), %rdi
shlq $0x2, %rdi
movslq 0xb0(%rsp), %rax
imulq %rax, %rdi
callq 0x10c0
movq %rax, 0x90(%rsp)
movl $0x3c, %edi
callq 0x10c0
movq %rax, 0x88(%rsp)
movl $0x0, 0x84(%rsp)
cmpl $0xf, 0x84(%rsp)
jge 0x1480
movq 0x88(%rsp), %rax
movslq 0x84(%rsp), %rcx
movss 0xb9c(%rip), %xmm0      # 0x2004
movss %xmm0, (%rax,%rcx,4)
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x1446
xorl %edi, %edi
callq 0x10d0
callq 0x1040
movl $0x0, 0x58(%rsp)
movl $0x0, 0x58(%rsp)
cmpl $0x3e8, 0x58(%rsp)      # imm = 0x3E8
jge 0x1516
movq 0x98(%rsp), %rdi
movslq 0xb0(%rsp), %rsi
movq 0xa0(%rsp), %rdx
movslq 0xb4(%rsp), %rcx
movslq 0xb0(%rsp), %r8
movslq 0xb4(%rsp), %r9
movq 0x88(%rsp), %rax
movq %rax, (%rsp)
movq $-0x7, 0x8(%rsp)
movq $0x7, 0x10(%rsp)
movl $0x1, 0x18(%rsp)
movl $0x5, 0x20(%rsp)
callq 0x1070
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x149c
callq 0x1050
movq %rax, 0x38(%rsp)
callq 0x1080
movq 0x38(%rsp), %rcx
leaq 0xb1a(%rip), %rdi       # 0x204b
movb $0x1, %al
callq *%rcx
movl $0x1, %edi
callq 0x10d0
callq 0x1040
movl $0x0, 0x54(%rsp)
movl $0x0, 0x54(%rsp)
cmpl $0x3e8, 0x54(%rsp)      # imm = 0x3E8
jge 0x15ce
movq 0x90(%rsp), %rdi
movslq 0xb0(%rsp), %rsi
movq 0xa0(%rsp), %rdx
movslq 0xb4(%rsp), %rcx
movslq 0xb0(%rsp), %r8
movslq 0xb4(%rsp), %r9
movq 0x88(%rsp), %rax
movq %rax, (%rsp)
movq $-0x7, 0x8(%rsp)
movq $0x7, 0x10(%rsp)
movl $0x1, 0x18(%rsp)
movl $0x5, 0x20(%rsp)
callq 0x1070
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x1554
callq 0x1050
movq %rax, 0x30(%rsp)
callq 0x1080
movq 0x30(%rsp), %rcx
leaq 0xa80(%rip), %rdi       # 0x2069
movb $0x1, %al
callq *%rcx
movq 0xa0(%rsp), %rsi
movl 0xb4(%rsp), %edx
movl 0xb0(%rsp), %ecx
leaq 0xa7f(%rip), %rdi       # 0x2089
callq 0x1060
movq 0x98(%rsp), %rsi
movl 0xb0(%rsp), %edx
movl 0xb4(%rsp), %ecx
leaq 0xa6a(%rip), %rdi       # 0x2096
callq 0x1060
movq 0x90(%rsp), %rsi
movl 0xb0(%rsp), %edx
movl 0xb4(%rsp), %ecx
leaq 0xa56(%rip), %rdi       # 0x20a4
callq 0x1060
movq 0xa0(%rsp), %rdi
callq 0x10a0
movq 0x88(%rsp), %rdi
callq 0x10a0
movq 0x98(%rsp), %rdi
callq 0x10a0
movq 0x90(%rsp), %rdi
callq 0x10a0
movl $0x0, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
addq $0xc8, %rsp
retq