// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x588, %rsp            # imm = 0x588
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x501b5(%rip), %rdi     # 0x5b62d
xorl %eax, %eax
callq 0xb8e5
xorl %eax, %eax
callq 0xb8a0
movb $0x0, 0x20(%rsp)
cmpl $0x1, %ebp
jg 0xb4bc
leaq 0x4eb89(%rip), %rdi     # 0x5a020
xorl %eax, %eax
callq 0xa080
movl $0xa, %edi
callq 0xa730
movl $0x63646373, 0x20(%rsp) # imm = 0x63646373
movw $0x3a, 0x24(%rsp)
jmp 0xb5bc
movq 0x8(%rbx), %r14
leaq 0x50689(%rip), %rsi     # 0x5bb50
movq %r14, %rdi
callq 0xa740
testl %eax, %eax
je 0xb519
leaq 0x5066d(%rip), %rsi     # 0x5bb47
movq %r14, %rdi
callq 0xa740
testl %eax, %eax
je 0xb53f
leaq 0x4ebc0(%rip), %rsi     # 0x5a0ad
movq %r14, %rdi
callq 0xa740
testl %eax, %eax
je 0xb572
leaq 0x4ebdc(%rip), %rdi     # 0x5a0dc
movq %r14, %rsi
xorl %eax, %eax
callq 0xa080
movl $0xa, %edi
callq 0xa730
jmp 0xb5bc
leaq 0x4eb26(%rip), %rdi     # 0x5a046
xorl %eax, %eax
callq 0xa080
movl $0xa, %edi
callq 0xa730
cmpl $0x2, %ebp
jne 0xb565
leaq 0x4eb26(%rip), %rdx     # 0x5a063
jmp 0xb569
leaq 0x4eb32(%rip), %rdi     # 0x5a078
xorl %eax, %eax
callq 0xa080
movl $0xa, %edi
callq 0xa730
cmpl $0x2, %ebp
jne 0xb598
leaq 0x4eb32(%rip), %rdx     # 0x5a095
jmp 0xb59c
movq 0x10(%rbx), %rdx
leaq 0x4eafa(%rip), %rsi     # 0x5a06a
jmp 0xb5b0
leaq 0x4eb38(%rip), %rdi     # 0x5a0b1
xorl %eax, %eax
callq 0xa080
movl $0xa, %edi
callq 0xa730
cmpl $0x2, %ebp
jne 0xb5a5
leaq 0x5055c(%rip), %rdx     # 0x5baf2
jmp 0xb5a9
movq 0x10(%rbx), %rdx
leaq 0x4eafc(%rip), %rsi     # 0x5a09f
jmp 0xb5b0
movq 0x10(%rbx), %rdx
leaq 0x4eb1e(%rip), %rsi     # 0x5a0ce
leaq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0xa0d0
cmpb $0x0, 0x20(%rsp)
je 0xb87f
leaq 0x4eb3c(%rip), %rsi     # 0x5a10a
leaq 0x4ea8e(%rip), %rcx     # 0x5a063
leaq 0x4eb24(%rip), %r8      # 0x5a100
leaq 0x380(%rsp), %rbx
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xa0d0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc70d
movq %rax, %rbx
leaq 0x4eb0c(%rip), %rsi     # 0x5a113
leaq 0x128(%rsp), %rdi
movl $0x1, %edx
movl $0x100000, %ecx         # imm = 0x100000
xorl %eax, %eax
callq 0x1ee2b
movq %rax, %r14
leaq 0x4eb8a(%rip), %rsi     # 0x5a1b4
leaq 0x180(%rsp), %r15
movl $0x1, %edx
movq %r15, %rdi
xorl %eax, %eax
callq 0xa0d0
leaq 0x10(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0xa8d0
movq (%r12), %r13
cvtsi2sdq 0x8(%r12), %xmm0
divsd 0x4e9a5(%rip), %xmm0    # 0x5a008
movsd %xmm0, 0x8(%rsp)
movl $0x1, %ebp
movl $0x64, %r12d
testl %ebp, %ebp
movl $0x0, %ebp
je 0xb698
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xd30b
xorl %ebp, %ebp
testq %rax, %rax
setne %bpl
decl %r12d
jne 0xb674
leaq 0x10(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0xa8d0
movq (%r15), %r12
movq 0x8(%r15), %r15
movq %r14, %rdi
callq 0x1ef1b
movq %rbx, %rdi
callq 0xc7ff
testl %ebp, %ebp
je 0xb716
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
movsd 0x8(%rsp), %xmm2
addsd %xmm0, %xmm2
cvtsi2sd %r15, %xmm1
divsd 0x4e922(%rip), %xmm1    # 0x5a008
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
addsd %xmm1, %xmm0
subsd %xmm2, %xmm0
divsd 0x4e912(%rip), %xmm0    # 0x5a010
mulsd 0x4e912(%rip), %xmm0    # 0x5a018
leaq 0x4ea13(%rip), %rdi     # 0x5a120
movb $0x1, %al
callq 0xa080
jmp 0xb724
leaq 0x4ea2e(%rip), %rdi     # 0x5a14b
xorl %eax, %eax
callq 0xa080
movl $0xa, %edi
callq 0xa730
leaq 0x4ea45(%rip), %rsi     # 0x5a17a
xorl %edi, %edi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xd30b
leaq 0x4e9ca(%rip), %rsi     # 0x5a113
leaq 0x128(%rsp), %rdi
movl $0x1, %edx
movl $0x100000, %ecx         # imm = 0x100000
xorl %eax, %eax
callq 0x1ee2b
movq %rax, %rbx
leaq 0x4ea3f(%rip), %rsi     # 0x5a1ab
leaq 0x4e8f0(%rip), %rcx     # 0x5a063
leaq 0x4e986(%rip), %r8      # 0x5a100
leaq 0x180(%rsp), %r14
leaq 0x20(%rsp), %rdx
movl $0x1, %r9d
movq %r14, %rdi
xorl %eax, %eax
callq 0xa0d0
leaq 0x10(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0xa8d0
movq (%r15), %r12
xorps %xmm0, %xmm0
cvtsi2sdq 0x8(%r15), %xmm0
divsd 0x4e84e(%rip), %xmm0    # 0x5a008
movsd %xmm0, 0x8(%rsp)
movl $0x1, %ebp
movl $0x64, %r15d
testl %ebp, %ebp
movl $0x0, %ebp
je 0xb7ee
xorl %edi, %edi
movq %r14, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xd30b
xorl %ebp, %ebp
testq %rax, %rax
setne %bpl
decl %r15d
jne 0xb7cb
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xa8d0
movq (%r14), %r15
movq 0x8(%r14), %r14
movq %rbx, %rdi
callq 0x1ef1b
testl %ebp, %ebp
je 0xb867
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
movsd 0x8(%rsp), %xmm2
addsd %xmm0, %xmm2
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
divsd 0x4e7d1(%rip), %xmm1    # 0x5a008
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
addsd %xmm1, %xmm0
subsd %xmm2, %xmm0
divsd 0x4e7c1(%rip), %xmm0    # 0x5a010
mulsd 0x4e7c1(%rip), %xmm0    # 0x5a018
leaq 0x4e95f(%rip), %rdi     # 0x5a1bd
movb $0x1, %al
callq 0xa080
jmp 0xb875
leaq 0x4e979(%rip), %rdi     # 0x5a1e7
xorl %eax, %eax
callq 0xa080
movl $0xa, %edi
callq 0xa730
xorl %eax, %eax
callq 0xb8bf
callq 0xb9e6
xorl %eax, %eax
addq $0x588, %rsp            # imm = 0x588
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop