// File: /workspace/github_cpp_makefile_star2_O2/mh0fm4[P]SCDC/test/bench/simpat/simpat_cli.c
// Function: main
int main(int argc, char *argv[])
{
  /* scdc.log_init("log_FILE", sys.stdout, sys.stderr)*/

  scdc_init(SCDC_INIT_DEFAULT);

  simpat_init();

  char uri_base[256], uri[512], cmd[512];

  uri_base[0] = '\0';

  if (argc <= 1)
  {
    SIMPAT_TRACE("test: direct");
    sprintf(uri_base, "scdc:");

  } else if (strcmp(argv[1], "uds") == 0)
  {
    SIMPAT_TRACE("test: UDS");

    const char *socketname = (argc <= 2)?"simpat":argv[2];

    sprintf(uri_base, "scdc+uds://%s", socketname);

  } else if (strcmp(argv[1], "tcp") == 0)
  {
    SIMPAT_TRACE("test: TCP");

    const char *hostname = (argc <= 2)?"localhost":argv[2];

    sprintf(uri_base, "scdc+tcp://%s", hostname);

  } else if (strcmp(argv[1], "mpi") == 0)
  {
    SIMPAT_TRACE("test: MPI");

    const char *rank = (argc <= 2)?"0":argv[2];

    sprintf(uri_base, "scdc+mpi://%s", rank);

  } else SIMPAT_TRACE("unknown mode: %s", argv[1]);


  int bw_put = 0;

  scdcint_t bw_size = 1000000000;

  int lat_ds = 1;
  int lat_ah = 1;
  scdcint_t lat_size = 1;
  scdcint_t lat_num = 100;

  if (strlen(uri_base) > 0)
  {
    const char *mode = "file/zero";

    /* bandwidth: put */
    if (bw_put)
    {
      sprintf(uri, "%s/%s/%s", uri_base, SIMPAT_BASE, mode);

      scdc_dataset_t ds = scdc_dataset_open(uri);

      scdc_dataset_input_t input_;
      scdc_dataset_input_t *input = scdc_dataset_input_create(&input_, "produce:size", bw_size, BUF_SIZE);

      sprintf(cmd, "put %" scdcint_fmt, bw_size);

      double t = z_time_wtime();
      int ret = scdc_dataset_cmd(ds, cmd, input, NULL);
      t = z_time_wtime() - t;

      scdc_dataset_input_destroy(input);

      scdc_dataset_close(ds);

      if (ret) SIMPAT_TRACE("bandwith put: %f", bw_size / t * 1e-6);
      else SIMPAT_TRACE("bandwith put: FAILED");
    }

/*  # bandwidth: get
  if bw_get:
    ds = scdc.dataset_open(uri + "/" + simpat.simpat_base + "/" + mode)

    output = output_init(bw_size)

    t = time.time()
    ret = scdc.dataset_cmd(ds, "get " + str(bw_size), None, output)
    t = time.time() - t

    output_release(output)

    scdc.dataset_close(ds)

    if ret:
      SIMPAT_TRACE("bandwith get: " + str(bw_size / t * 1e-6))
    else:
      SIMPAT_TRACE("bandwith get: FAILED")
*/

    /* latency: dataset put */
    if (lat_ds)
    {
      sprintf(uri, "%s/%s/%s", uri_base, SIMPAT_BASE, mode);

      scdc_dataset_t ds = scdc_dataset_open(uri);

      scdc_dataset_input_t input_;
      scdc_dataset_input_t *input = scdc_dataset_input_create(&input_, "produce:size", lat_size, BUF_SIZE);

      sprintf(cmd, "put %" scdcint_fmt, lat_size);

      double t = z_time_wtime();
      int i, ret = 1;
      for (i = 0; i < lat_num; ++i) ret = ret && scdc_dataset_cmd(ds, cmd, input, NULL);
      t = z_time_wtime() - t;

      scdc_dataset_input_destroy(input);

      scdc_dataset_close(ds);

      if (ret) SIMPAT_TRACE("latency dataset put: %f", t / lat_num * 1e3);
      else SIMPAT_TRACE("latency dataset put: FAILED");
    }

    /* latency: ad-hoc put */
    if (lat_ah)
    {
      scdc_dataset_cmd(SCDC_DATASET_NULL, "scdc:////CONFIG put nodeconn_cache_connections 0", NULL, NULL);

      scdc_dataset_input_t input_;
      scdc_dataset_input_t *input = scdc_dataset_input_create(&input_, "produce:size", lat_size, BUF_SIZE);

      sprintf(cmd, "%s/%s/%s put %" scdcint_fmt, uri_base, SIMPAT_BASE, mode, lat_size);

      double t = z_time_wtime();
      int i, ret = 1;
      for (i = 0; i < lat_num; ++i) ret = ret && scdc_dataset_cmd(SCDC_DATASET_NULL, cmd, input, NULL);
      t = z_time_wtime() - t;

      scdc_dataset_input_destroy(input);

      if (ret) SIMPAT_TRACE("latency ad-hoc put: %f", t / lat_num * 1e3);
      else SIMPAT_TRACE("latency ad-hoc put: FAILED");
    }
  }

  simpat_release();

  scdc_release();

  /*scdc.log_release()*/

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x570, %rsp            # imm = 0x570
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x393e7(%rip), %rdi     # 0x455ed
xorl %eax, %eax
callq 0xc5c5
xorl %eax, %eax
callq 0xc580
movb $0x0, 0x10(%rsp)
cmpl $0x1, %ebp
jg 0xc248
leaq 0x37dfb(%rip), %rdi     # 0x44020
xorl %eax, %eax
callq 0xb070
pushq $0xa
popq %rdi
callq 0xb760
movl $0x63646373, 0x10(%rsp) # imm = 0x63646373
movw $0x3a, 0x14(%rsp)
jmp 0xc340
movq 0x8(%rbx), %r14
leaq 0x398bd(%rip), %rsi     # 0x45b10
movq %r14, %rdi
callq 0xb770
testl %eax, %eax
je 0xc2a3
leaq 0x398a1(%rip), %rsi     # 0x45b07
movq %r14, %rdi
callq 0xb770
testl %eax, %eax
je 0xc2c7
leaq 0x37e34(%rip), %rsi     # 0x440ad
movq %r14, %rdi
callq 0xb770
testl %eax, %eax
je 0xc2f8
leaq 0x37e50(%rip), %rdi     # 0x440dc
movq %r14, %rsi
xorl %eax, %eax
callq 0xb070
pushq $0xa
popq %rdi
callq 0xb760
jmp 0xc340
leaq 0x37d9c(%rip), %rdi     # 0x44046
xorl %eax, %eax
callq 0xb070
pushq $0xa
popq %rdi
callq 0xb760
cmpl $0x2, %ebp
jne 0xc2eb
leaq 0x37d9e(%rip), %rdx     # 0x44063
jmp 0xc2ef
leaq 0x37daa(%rip), %rdi     # 0x44078
xorl %eax, %eax
callq 0xb070
pushq $0xa
popq %rdi
callq 0xb760
cmpl $0x2, %ebp
jne 0xc31c
leaq 0x37dac(%rip), %rdx     # 0x44095
jmp 0xc320
movq 0x10(%rbx), %rdx
leaq 0x37d74(%rip), %rsi     # 0x4406a
jmp 0xc334
leaq 0x37db2(%rip), %rdi     # 0x440b1
xorl %eax, %eax
callq 0xb070
pushq $0xa
popq %rdi
callq 0xb760
cmpl $0x2, %ebp
jne 0xc329
leaq 0x39798(%rip), %rdx     # 0x45ab2
jmp 0xc32d
movq 0x10(%rbx), %rdx
leaq 0x37d78(%rip), %rsi     # 0x4409f
jmp 0xc334
movq 0x10(%rbx), %rdx
leaq 0x37d9a(%rip), %rsi     # 0x440ce
leaq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0xb0c0
cmpb $0x0, 0x10(%rsp)
je 0xc562
leaq 0x37db8(%rip), %rsi     # 0x4410a
leaq 0x37d0a(%rip), %rcx     # 0x44063
leaq 0x37da0(%rip), %r8      # 0x44100
leaq 0x370(%rsp), %rbx
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xb0c0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xd13f
movq %rax, %rbx
leaq 0x37d88(%rip), %rsi     # 0x44113
leaq 0x118(%rsp), %rdi
pushq $0x1
popq %r12
movq %r12, %rdx
movl $0x100000, %ecx         # imm = 0x100000
xorl %eax, %eax
callq 0x1a9da
movq %rax, %r14
leaq 0x37e04(%rip), %rsi     # 0x441b4
leaq 0x170(%rsp), %r15
movq %r15, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xb0c0
pushq $0x1
popq %r12
pushq $0x64
popq %rbp
callq 0xc1bc
movsd %xmm0, 0x8(%rsp)
subl $0x1, %ebp
jb 0xc404
testl %r12d, %r12d
je 0xc3ff
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xda00
xorl %r12d, %r12d
testq %rax, %rax
setne %r12b
jmp 0xc3d7
xorl %r12d, %r12d
jmp 0xc3d7
callq 0xc1bc
movsd %xmm0, (%rsp)
movq %r14, %rdi
callq 0x1aade
movq %rbx, %rdi
callq 0xd1f7
testl %r12d, %r12d
je 0xc44e
movsd (%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
divsd 0x37bda(%rip), %xmm0    # 0x44010
mulsd 0x37bda(%rip), %xmm0    # 0x44018
leaq 0x37cdb(%rip), %rdi     # 0x44120
movb $0x1, %al
callq 0xb070
jmp 0xc45c
leaq 0x37cf6(%rip), %rdi     # 0x4414b
xorl %eax, %eax
callq 0xb070
pushq $0xa
popq %rdi
callq 0xb760
leaq 0x37d0f(%rip), %rsi     # 0x4417a
xorl %edi, %edi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xda00
leaq 0x37c94(%rip), %rsi     # 0x44113
leaq 0x118(%rsp), %rdi
pushq $0x1
popq %r15
movq %r15, %rdx
movl $0x100000, %ecx         # imm = 0x100000
xorl %eax, %eax
callq 0x1a9da
movq %rax, %rbx
leaq 0x37d07(%rip), %rsi     # 0x441ab
leaq 0x37bb8(%rip), %rcx     # 0x44063
leaq 0x37c4e(%rip), %r8      # 0x44100
leaq 0x170(%rsp), %r14
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
movq %r15, %r9
xorl %eax, %eax
callq 0xb0c0
pushq $0x1
popq %r15
pushq $0x64
popq %rbp
callq 0xc1bc
movsd %xmm0, 0x8(%rsp)
subl $0x1, %ebp
jb 0xc50a
testl %r15d, %r15d
je 0xc505
xorl %edi, %edi
movq %r14, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xda00
xorl %r15d, %r15d
testq %rax, %rax
setne %r15b
jmp 0xc4de
xorl %r15d, %r15d
jmp 0xc4de
callq 0xc1bc
movsd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x1aade
testl %r15d, %r15d
je 0xc54c
movsd (%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
divsd 0x37adc(%rip), %xmm0    # 0x44010
mulsd 0x37adc(%rip), %xmm0    # 0x44018
leaq 0x37c7a(%rip), %rdi     # 0x441bd
movb $0x1, %al
callq 0xb070
jmp 0xc55a
leaq 0x37c94(%rip), %rdi     # 0x441e7
xorl %eax, %eax
callq 0xb070
pushq $0xa
popq %rdi
callq 0xb760
xorl %eax, %eax
callq 0xc59f
callq 0xc6da
xorl %eax, %eax
addq $0x570, %rsp            # imm = 0x570
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq