// File: /workspace/github_c_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpl $0x1, %edi
jg 0x1293
movl $0x40000, %edi          # imm = 0x40000
callq 0x10c0
movq %rax, 0x8(%rsp)
xorl %ecx, %ecx
movdqa 0xe04(%rip), %xmm0      # 0x2010
movdqa 0xe0c(%rip), %xmm1      # 0x2020
movdqa 0xe14(%rip), %xmm2      # 0x2030
movdqa 0xe1c(%rip), %xmm3      # 0x2040
movq %rcx, %xmm4
pshufd $0x44, %xmm4, %xmm4     # xmm4 = xmm4[0,1,0,1]
xorl %edx, %edx
movdqa %xmm1, %xmm5
movdqa %xmm0, %xmm6
movdqa %xmm5, %xmm7
pxor %xmm4, %xmm7
movdqa %xmm6, %xmm8
pxor %xmm4, %xmm8
shufps $0x88, %xmm8, %xmm7     # xmm7 = xmm7[0,2],xmm8[0,2]
pslld $0x4, %xmm7
pand %xmm2, %xmm7
cvtdq2ps %xmm7, %xmm7
movups %xmm7, (%rax,%rdx,4)
addq $0x4, %rdx
paddq %xmm3, %xmm5
paddq %xmm3, %xmm6
cmpq $0x100, %rdx            # imm = 0x100
jne 0x1238
incq %rcx
addq $0x400, %rax            # imm = 0x400
cmpq $0x100, %rcx            # imm = 0x100
jne 0x1224
movl $0x100, %ebp            # imm = 0x100
movl $0x100, %r14d           # imm = 0x100
jmp 0x12f7
movq 0x8(%rsi), %rdi
leaq 0x18(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x10b0
movl %eax, %ebx
testl %eax, %eax
je 0x12e4
callq 0x1050
movq %rax, %r14
callq 0x1030
movq %rax, %r15
callq 0x1090
leaq 0xda8(%rip), %rdi       # 0x2070
movq %r15, %rsi
movl %eax, %edx
xorl %eax, %eax
callq *%r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x100, %ebp            # imm = 0x100
movl $0x100, %r14d           # imm = 0x100
jmp 0x12ef
movl 0x18(%rsp), %r14d
movl 0x20(%rsp), %ebp
xorl %eax, %eax
testl %ebx, %ebx
jne 0x1532
callq 0x1050
movq %rax, %rcx
leaq 0xd86(%rip), %rdi       # 0x208c
movl %r14d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq *%rcx
movl %r14d, 0x10(%rsp)
movslq %r14d, %r13
movslq %ebp, %rbx
movq %r13, %r15
imulq %rbx, %r15
shlq $0x2, %r15
movq %r15, %rdi
callq 0x10c0
movq %rax, %r14
movq %r15, %rdi
callq 0x10c0
movq %rax, %r15
movl $0x3c, %edi
callq 0x10c0
movq %rax, %r12
movdqa 0xcc0(%rip), %xmm0      # 0x2010
movdqa 0xcc8(%rip), %xmm1      # 0x2020
movl $0x3, %eax
movdqa 0xceb(%rip), %xmm2      # 0x2050
movdqa 0xcf3(%rip), %xmm3      # 0x2060
pshufd $0xf5, %xmm3, %xmm4     # xmm4 = xmm3[1,1,3,3]
movdqa 0xcc6(%rip), %xmm5      # 0x2040
movdqa %xmm1, %xmm6
pxor %xmm2, %xmm6
movdqa %xmm3, %xmm7
pcmpgtd %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
pcmpeqd %xmm4, %xmm6
pand %xmm7, %xmm6
movd %xmm6, %ecx
testb $0x1, %cl
je 0x13a9
movl $0x3d888889, -0xc(%r12,%rax,4) # imm = 0x3D888889
pextrw $0x4, %xmm6, %ecx
testb $0x1, %cl
je 0x13bc
movl $0x3d888889, -0x8(%r12,%rax,4) # imm = 0x3D888889
movdqa %xmm0, %xmm6
pxor %xmm2, %xmm6
movdqa %xmm3, %xmm7
pcmpgtd %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
pcmpeqd %xmm4, %xmm6
pand %xmm7, %xmm6
pextrw $0x0, %xmm6, %ecx
testb $0x1, %cl
je 0x13ec
movl $0x3d888889, -0x4(%r12,%rax,4) # imm = 0x3D888889
pextrw $0x4, %xmm6, %ecx
testb $0x1, %cl
je 0x13fe
movl $0x3d888889, (%r12,%rax,4) # imm = 0x3D888889
paddq %xmm5, %xmm1
paddq %xmm5, %xmm0
addq $0x4, %rax
cmpq $0x13, %rax
jne 0x137a
movl %ebp, 0x14(%rsp)
xorl %edi, %edi
callq 0x10d0
callq 0x1040
movl $0x3e8, %ebp            # imm = 0x3E8
movq 0x8(%rsp), %rdx
subq $0x8, %rsp
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rcx
movq %rbx, %r8
movq %r13, %r9
pushq $0x5
pushq $0x1
pushq $0x7
pushq $-0x7
pushq %r12
callq 0x1070
addq $0x30, %rsp
decl %ebp
jne 0x1429
callq 0x1050
movq %rax, %rbp
callq 0x1080
leaq 0xc43(%rip), %rdi       # 0x20af
movb $0x1, %al
callq *%rbp
movl $0x1, %edi
callq 0x10d0
callq 0x1040
movl $0x3e8, %ebp            # imm = 0x3E8
movq 0x8(%rsp), %rdx
subq $0x8, %rsp
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rcx
movq %rbx, %r8
movq %r13, %r9
pushq $0x5
pushq $0x1
pushq $0x7
pushq $-0x7
pushq %r12
callq 0x1070
addq $0x30, %rsp
decl %ebp
jne 0x1484
callq 0x1050
movq %rax, %rbx
callq 0x1080
leaq 0xc06(%rip), %rdi       # 0x20cd
movb $0x1, %al
callq *%rbx
movq 0x8(%rsp), %rsi
leaq 0xc16(%rip), %rdi       # 0x20ed
movl 0x10(%rsp), %ebp
movl %ebp, %edx
movl 0x14(%rsp), %ebx
movl %ebx, %ecx
callq 0x1060
leaq 0xc0b(%rip), %rdi       # 0x20fa
movq %r14, %rsi
movl %ebx, %edx
movl %ebp, %ecx
callq 0x1060
leaq 0xc06(%rip), %rdi       # 0x2108
movq %r15, %rsi
movl %ebx, %edx
movl %ebp, %ecx
callq 0x1060
movq 0x8(%rsp), %rdi
callq 0x10a0
movq %r12, %rdi
callq 0x10a0
movq %r14, %rdi
callq 0x10a0
movq %r15, %rdi
callq 0x10a0
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq