// File: /workspace/github_cpp_makefile_star2_O1/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     # 0x5c62d
xorl %eax, %eax
callq 0xc8e5
xorl %eax, %eax
callq 0xc8a0
movb $0x0, 0x20(%rsp)
cmpl $0x1, %ebp
jg 0xc4bc
leaq 0x4eb89(%rip), %rdi     # 0x5b020
xorl %eax, %eax
callq 0xb080
movl $0xa, %edi
callq 0xb730
movl $0x63646373, 0x20(%rsp) # imm = 0x63646373
movw $0x3a, 0x24(%rsp)
jmp 0xc5bc
movq 0x8(%rbx), %r14
leaq 0x50689(%rip), %rsi     # 0x5cb50
movq %r14, %rdi
callq 0xb740
testl %eax, %eax
je 0xc519
leaq 0x5066d(%rip), %rsi     # 0x5cb47
movq %r14, %rdi
callq 0xb740
testl %eax, %eax
je 0xc53f
leaq 0x4ebc0(%rip), %rsi     # 0x5b0ad
movq %r14, %rdi
callq 0xb740
testl %eax, %eax
je 0xc572
leaq 0x4ebdc(%rip), %rdi     # 0x5b0dc
movq %r14, %rsi
xorl %eax, %eax
callq 0xb080
movl $0xa, %edi
callq 0xb730
jmp 0xc5bc
leaq 0x4eb26(%rip), %rdi     # 0x5b046
xorl %eax, %eax
callq 0xb080
movl $0xa, %edi
callq 0xb730
cmpl $0x2, %ebp
jne 0xc565
leaq 0x4eb26(%rip), %rdx     # 0x5b063
jmp 0xc569
leaq 0x4eb32(%rip), %rdi     # 0x5b078
xorl %eax, %eax
callq 0xb080
movl $0xa, %edi
callq 0xb730
cmpl $0x2, %ebp
jne 0xc598
leaq 0x4eb32(%rip), %rdx     # 0x5b095
jmp 0xc59c
movq 0x10(%rbx), %rdx
leaq 0x4eafa(%rip), %rsi     # 0x5b06a
jmp 0xc5b0
leaq 0x4eb38(%rip), %rdi     # 0x5b0b1
xorl %eax, %eax
callq 0xb080
movl $0xa, %edi
callq 0xb730
cmpl $0x2, %ebp
jne 0xc5a5
leaq 0x5055c(%rip), %rdx     # 0x5caf2
jmp 0xc5a9
movq 0x10(%rbx), %rdx
leaq 0x4eafc(%rip), %rsi     # 0x5b09f
jmp 0xc5b0
movq 0x10(%rbx), %rdx
leaq 0x4eb1e(%rip), %rsi     # 0x5b0ce
leaq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0xb0d0
cmpb $0x0, 0x20(%rsp)
je 0xc87f
leaq 0x4eb3c(%rip), %rsi     # 0x5b10a
leaq 0x4ea8e(%rip), %rcx     # 0x5b063
leaq 0x4eb24(%rip), %r8      # 0x5b100
leaq 0x380(%rsp), %rbx
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xb0d0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xd72a
movq %rax, %rbx
leaq 0x4eb0c(%rip), %rsi     # 0x5b113
leaq 0x128(%rsp), %rdi
movl $0x1, %edx
movl $0x100000, %ecx         # imm = 0x100000
xorl %eax, %eax
callq 0x1fff5
movq %rax, %r14
leaq 0x4eb8a(%rip), %rsi     # 0x5b1b4
leaq 0x180(%rsp), %r15
movl $0x1, %edx
movq %r15, %rdi
xorl %eax, %eax
callq 0xb0d0
leaq 0x10(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0xb8d0
movq (%r12), %r13
cvtsi2sdq 0x8(%r12), %xmm0
divsd 0x4e9a5(%rip), %xmm0    # 0x5b008
movsd %xmm0, 0x8(%rsp)
movl $0x1, %ebp
movl $0x64, %r12d
testl %ebp, %ebp
movl $0x0, %ebp
je 0xc698
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xe328
xorl %ebp, %ebp
testq %rax, %rax
setne %bpl
decl %r12d
jne 0xc674
leaq 0x10(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0xb8d0
movq (%r15), %r12
movq 0x8(%r15), %r15
movq %r14, %rdi
callq 0x200e5
movq %rbx, %rdi
callq 0xd81c
testl %ebp, %ebp
je 0xc716
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
movsd 0x8(%rsp), %xmm2
addsd %xmm0, %xmm2
cvtsi2sd %r15, %xmm1
divsd 0x4e922(%rip), %xmm1    # 0x5b008
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
addsd %xmm1, %xmm0
subsd %xmm2, %xmm0
divsd 0x4e912(%rip), %xmm0    # 0x5b010
mulsd 0x4e912(%rip), %xmm0    # 0x5b018
leaq 0x4ea13(%rip), %rdi     # 0x5b120
movb $0x1, %al
callq 0xb080
jmp 0xc724
leaq 0x4ea2e(%rip), %rdi     # 0x5b14b
xorl %eax, %eax
callq 0xb080
movl $0xa, %edi
callq 0xb730
leaq 0x4ea45(%rip), %rsi     # 0x5b17a
xorl %edi, %edi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xe328
leaq 0x4e9ca(%rip), %rsi     # 0x5b113
leaq 0x128(%rsp), %rdi
movl $0x1, %edx
movl $0x100000, %ecx         # imm = 0x100000
xorl %eax, %eax
callq 0x1fff5
movq %rax, %rbx
leaq 0x4ea3f(%rip), %rsi     # 0x5b1ab
leaq 0x4e8f0(%rip), %rcx     # 0x5b063
leaq 0x4e986(%rip), %r8      # 0x5b100
leaq 0x180(%rsp), %r14
leaq 0x20(%rsp), %rdx
movl $0x1, %r9d
movq %r14, %rdi
xorl %eax, %eax
callq 0xb0d0
leaq 0x10(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0xb8d0
movq (%r15), %r12
xorps %xmm0, %xmm0
cvtsi2sdq 0x8(%r15), %xmm0
divsd 0x4e84e(%rip), %xmm0    # 0x5b008
movsd %xmm0, 0x8(%rsp)
movl $0x1, %ebp
movl $0x64, %r15d
testl %ebp, %ebp
movl $0x0, %ebp
je 0xc7ee
xorl %edi, %edi
movq %r14, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xe328
xorl %ebp, %ebp
testq %rax, %rax
setne %bpl
decl %r15d
jne 0xc7cb
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xb8d0
movq (%r14), %r15
movq 0x8(%r14), %r14
movq %rbx, %rdi
callq 0x200e5
testl %ebp, %ebp
je 0xc867
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
movsd 0x8(%rsp), %xmm2
addsd %xmm0, %xmm2
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
divsd 0x4e7d1(%rip), %xmm1    # 0x5b008
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
addsd %xmm1, %xmm0
subsd %xmm2, %xmm0
divsd 0x4e7c1(%rip), %xmm0    # 0x5b010
mulsd 0x4e7c1(%rip), %xmm0    # 0x5b018
leaq 0x4e95f(%rip), %rdi     # 0x5b1bd
movb $0x1, %al
callq 0xb080
jmp 0xc875
leaq 0x4e979(%rip), %rdi     # 0x5b1e7
xorl %eax, %eax
callq 0xb080
movl $0xa, %edi
callq 0xb730
xorl %eax, %eax
callq 0xc8bf
callq 0xc9ea
xorl %eax, %eax
addq $0x588, %rsp            # imm = 0x588
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop