// File: 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
movq %rsp, %rbp
subq $0x6e0, %rsp            # imm = 0x6E0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x7cea8(%rip), %rdi     # 0x8a6e8
movb $0x0, %al
callq 0xe050
movb $0x0, %al
callq 0xdf90
movb $0x0, -0x110(%rbp)
cmpl $0x1, -0x8(%rbp)
jg 0xd893
jmp 0xd85d
leaq 0x7c7bc(%rip), %rdi     # 0x8a020
movb $0x0, %al
callq 0xcd00
leaq 0x7c7ce(%rip), %rdi     # 0x8a040
movb $0x0, %al
callq 0xcd00
leaq -0x110(%rbp), %rdi
leaq 0x7c7bb(%rip), %rsi     # 0x8a042
movb $0x0, %al
callq 0xc0f0
jmp 0xda5f
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x7e2b6(%rip), %rsi     # 0x8bb58
callq 0xc950
cmpl $0x0, %eax
jne 0xd91e
jmp 0xd8ae
leaq 0x7c793(%rip), %rdi     # 0x8a048
movb $0x0, %al
callq 0xcd00
leaq 0x7c77d(%rip), %rdi     # 0x8a040
movb $0x0, %al
callq 0xcd00
cmpl $0x2, -0x8(%rbp)
jg 0xd8e0
leaq 0x7c78e(%rip), %rax     # 0x8a065
movq %rax, -0x6c0(%rbp)
jmp 0xd8ef
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x6c0(%rbp)
movq -0x6c0(%rbp), %rax
movq %rax, -0x518(%rbp)
leaq -0x110(%rbp), %rdi
movq -0x518(%rbp), %rdx
leaq 0x7c75a(%rip), %rsi     # 0x8a06c
movb $0x0, %al
callq 0xc0f0
jmp 0xda5d
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x7e222(%rip), %rsi     # 0x8bb4f
callq 0xc950
cmpl $0x0, %eax
jne 0xd9a9
jmp 0xd939
leaq 0x7c73a(%rip), %rdi     # 0x8a07a
movb $0x0, %al
callq 0xcd00
leaq 0x7c6f2(%rip), %rdi     # 0x8a040
movb $0x0, %al
callq 0xcd00
cmpl $0x2, -0x8(%rbp)
jg 0xd96b
leaq 0x7c735(%rip), %rax     # 0x8a097
movq %rax, -0x6c8(%rbp)
jmp 0xd97a
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x6c8(%rbp)
movq -0x6c8(%rbp), %rax
movq %rax, -0x520(%rbp)
leaq -0x110(%rbp), %rdi
movq -0x520(%rbp), %rdx
leaq 0x7c704(%rip), %rsi     # 0x8a0a1
movb $0x0, %al
callq 0xc0f0
jmp 0xda5b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x7c6f7(%rip), %rsi     # 0x8a0af
callq 0xc950
cmpl $0x0, %eax
jne 0xda31
jmp 0xd9c4
leaq 0x7c6e8(%rip), %rdi     # 0x8a0b3
movb $0x0, %al
callq 0xcd00
leaq 0x7c667(%rip), %rdi     # 0x8a040
movb $0x0, %al
callq 0xcd00
cmpl $0x2, -0x8(%rbp)
jg 0xd9f6
leaq 0x7e10d(%rip), %rax     # 0x8bafa
movq %rax, -0x6d0(%rbp)
jmp 0xda05
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x6d0(%rbp)
movq -0x6d0(%rbp), %rax
movq %rax, -0x528(%rbp)
leaq -0x110(%rbp), %rdi
movq -0x528(%rbp), %rdx
leaq 0x7c6a8(%rip), %rsi     # 0x8a0d0
movb $0x0, %al
callq 0xc0f0
jmp 0xda59
jmp 0xda33
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x7c69c(%rip), %rdi     # 0x8a0de
movb $0x0, %al
callq 0xcd00
leaq 0x7c5f0(%rip), %rdi     # 0x8a040
movb $0x0, %al
callq 0xcd00
jmp 0xda59
jmp 0xda5b
jmp 0xda5d
jmp 0xda5f
movl $0x0, -0x52c(%rbp)
movq $0x3b9aca00, -0x538(%rbp) # imm = 0x3B9ACA00
movl $0x1, -0x53c(%rbp)
movl $0x1, -0x540(%rbp)
movq $0x1, -0x548(%rbp)
movq $0x64, -0x550(%rbp)
leaq -0x110(%rbp), %rdi
callq 0xc280
cmpq $0x0, %rax
jbe 0xdf6e
leaq 0x7c647(%rip), %rax     # 0x8a102
movq %rax, -0x558(%rbp)
cmpl $0x0, -0x52c(%rbp)
je 0xdc1a
leaq -0x310(%rbp), %rdi
leaq -0x110(%rbp), %rdx
movq -0x558(%rbp), %r8
leaq 0x7c621(%rip), %rsi     # 0x8a10c
leaq 0x7c573(%rip), %rcx     # 0x8a065
movb $0x0, %al
callq 0xc0f0
leaq -0x310(%rbp), %rdi
movb $0x0, %al
callq 0xf270
movq %rax, -0x560(%rbp)
movq -0x538(%rbp), %rdx
leaq -0x5b8(%rbp), %rdi
leaq 0x7c5f2(%rip), %rsi     # 0x8a115
movl $0x100000, %ecx         # imm = 0x100000
movb $0x0, %al
callq 0x31840
movq %rax, -0x5c0(%rbp)
leaq -0x510(%rbp), %rdi
movq -0x538(%rbp), %rdx
leaq 0x7c6b7(%rip), %rsi     # 0x8a202
movb $0x0, %al
callq 0xc0f0
callq 0xd7e0
movsd %xmm0, -0x5c8(%rbp)
movq -0x560(%rbp), %rdi
leaq -0x510(%rbp), %rsi
movq -0x5c0(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
movb $0x0, %al
callq 0x10100
movl %eax, -0x5cc(%rbp)
callq 0xd7e0
subsd -0x5c8(%rbp), %xmm0
movsd %xmm0, -0x5c8(%rbp)
movq -0x5c0(%rbp), %rdi
callq 0x319c0
movq -0x560(%rbp), %rdi
callq 0xf340
cmpl $0x0, -0x5cc(%rbp)
je 0xdbf8
jmp 0xdbbd
cvtsi2sdq -0x538(%rbp), %xmm0
divsd -0x5c8(%rbp), %xmm0
movsd 0x7c43a(%rip), %xmm1    # 0x8a010
mulsd %xmm1, %xmm0
leaq 0x7c541(%rip), %rdi     # 0x8a122
movb $0x1, %al
callq 0xcd00
leaq 0x7c451(%rip), %rdi     # 0x8a040
movb $0x0, %al
callq 0xcd00
jmp 0xdc18
jmp 0xdbfa
leaq 0x7c545(%rip), %rdi     # 0x8a146
movb $0x0, %al
callq 0xcd00
leaq 0x7c431(%rip), %rdi     # 0x8a040
movb $0x0, %al
callq 0xcd00
jmp 0xdc18
jmp 0xdc1a
cmpl $0x0, -0x53c(%rbp)
je 0xddd4
leaq -0x310(%rbp), %rdi
leaq -0x110(%rbp), %rdx
movq -0x558(%rbp), %r8
leaq 0x7c4c9(%rip), %rsi     # 0x8a10c
leaq 0x7c41b(%rip), %rcx     # 0x8a065
movb $0x0, %al
callq 0xc0f0
leaq -0x310(%rbp), %rdi
movb $0x0, %al
callq 0xf270
movq %rax, -0x5d8(%rbp)
movq -0x548(%rbp), %rdx
leaq -0x630(%rbp), %rdi
leaq 0x7c49a(%rip), %rsi     # 0x8a115
movl $0x100000, %ecx         # imm = 0x100000
movb $0x0, %al
callq 0x31840
movq %rax, -0x638(%rbp)
leaq -0x510(%rbp), %rdi
movq -0x548(%rbp), %rdx
leaq 0x7c55f(%rip), %rsi     # 0x8a202
movb $0x0, %al
callq 0xc0f0
callq 0xd7e0
movsd %xmm0, -0x640(%rbp)
movl $0x1, -0x648(%rbp)
movl $0x0, -0x644(%rbp)
movslq -0x644(%rbp), %rax
cmpq -0x550(%rbp), %rax
jge 0xdd3b
xorl %eax, %eax
cmpl $0x0, -0x648(%rbp)
movb %al, -0x6d1(%rbp)
je 0xdd19
movq -0x5d8(%rbp), %rdi
leaq -0x510(%rbp), %rsi
movq -0x638(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
movb $0x0, %al
callq 0x10100
cmpq $0x0, %rax
setne %al
movb %al, -0x6d1(%rbp)
movb -0x6d1(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x648(%rbp)
movl -0x644(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x644(%rbp)
jmp 0xdccb
callq 0xd7e0
subsd -0x640(%rbp), %xmm0
movsd %xmm0, -0x640(%rbp)
movq -0x638(%rbp), %rdi
callq 0x319c0
movq -0x5d8(%rbp), %rdi
callq 0xf340
cmpl $0x0, -0x648(%rbp)
je 0xddb2
jmp 0xdd73
movsd -0x640(%rbp), %xmm0
cvtsi2sdq -0x550(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x7c288(%rip), %xmm1    # 0x8a018
mulsd %xmm1, %xmm0
leaq 0x7c3d3(%rip), %rdi     # 0x8a16e
movb $0x1, %al
callq 0xcd00
leaq 0x7c297(%rip), %rdi     # 0x8a040
movb $0x0, %al
callq 0xcd00
jmp 0xddd2
jmp 0xddb4
leaq 0x7c3de(%rip), %rdi     # 0x8a199
movb $0x0, %al
callq 0xcd00
leaq 0x7c277(%rip), %rdi     # 0x8a040
movb $0x0, %al
callq 0xcd00
jmp 0xddd2
jmp 0xddd4
cmpl $0x0, -0x540(%rbp)
je 0xdf6c
xorl %eax, %eax
movl %eax, %ecx
leaq 0x7c3dc(%rip), %rsi     # 0x8a1c8
movq %rcx, %rdi
movq %rcx, %rdx
movb $0x0, %al
callq 0x10100
movq -0x548(%rbp), %rdx
leaq -0x6a0(%rbp), %rdi
leaq 0x7c307(%rip), %rsi     # 0x8a115
movl $0x100000, %ecx         # imm = 0x100000
movb $0x0, %al
callq 0x31840
movq %rax, -0x6a8(%rbp)
leaq -0x510(%rbp), %rdi
leaq -0x110(%rbp), %rdx
movq -0x558(%rbp), %r8
movq -0x548(%rbp), %r9
leaq 0x7c3b5(%rip), %rsi     # 0x8a1f9
leaq 0x7c21a(%rip), %rcx     # 0x8a065
movb $0x0, %al
callq 0xc0f0
callq 0xd7e0
movsd %xmm0, -0x6b0(%rbp)
movl $0x1, -0x6b8(%rbp)
movl $0x0, -0x6b4(%rbp)
movslq -0x6b4(%rbp), %rax
cmpq -0x550(%rbp), %rax
jge 0xdedf
xorl %eax, %eax
cmpl $0x0, -0x6b8(%rbp)
movb %al, -0x6d2(%rbp)
je 0xdebd
leaq -0x510(%rbp), %rsi
movq -0x6a8(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdi
movb $0x0, %al
callq 0x10100
cmpq $0x0, %rax
setne %al
movb %al, -0x6d2(%rbp)
movb -0x6d2(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x6b8(%rbp)
movl -0x6b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6b4(%rbp)
jmp 0xde73
callq 0xd7e0
subsd -0x6b0(%rbp), %xmm0
movsd %xmm0, -0x6b0(%rbp)
movq -0x6a8(%rbp), %rdi
callq 0x319c0
cmpl $0x0, -0x6b8(%rbp)
je 0xdf4a
jmp 0xdf0b
movsd -0x6b0(%rbp), %xmm0
cvtsi2sdq -0x550(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x7c0f0(%rip), %xmm1    # 0x8a018
mulsd %xmm1, %xmm0
leaq 0x7c2d8(%rip), %rdi     # 0x8a20b
movb $0x1, %al
callq 0xcd00
leaq 0x7c0ff(%rip), %rdi     # 0x8a040
movb $0x0, %al
callq 0xcd00
jmp 0xdf6a
jmp 0xdf4c
leaq 0x7c2e2(%rip), %rdi     # 0x8a235
movb $0x0, %al
callq 0xcd00
leaq 0x7c0df(%rip), %rdi     # 0x8a040
movb $0x0, %al
callq 0xcd00
jmp 0xdf6a
jmp 0xdf6c
jmp 0xdf6e
movb $0x0, %al
callq 0xdfc0
callq 0xe200
xorl %eax, %eax
addq $0x6e0, %rsp            # imm = 0x6E0
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop