// File: /workspace/github_c_makefile_star2_O0/CBaquero[P]random/Random.cc
// Function: RandomLNorm_RedisCommand(RedisModuleCtx*, RedisModuleString**, int)
int RandomLNorm_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
  double mean=0.0, sd=1.0;
  if (argc > 5) return RedisModule_WrongArity(ctx);
  if (argc >= 4) /* Get mean */
  {
    if (RedisModule_StringToDouble(argv[3],&mean) != REDISMODULE_OK)
      return RedisModule_ReplyWithError(ctx,"ERR invalid mean");
  }
  if (argc == 5) /* get stddev */
  {
    if (RedisModule_StringToDouble(argv[4],&sd) != REDISMODULE_OK)
      return RedisModule_ReplyWithError(ctx,"ERR invalid standard deviation");
  }

  /* Open key */
  RedisModuleKey *key = (RedisModuleKey *) RedisModule_OpenKey(ctx, argv[1], REDISMODULE_READ | REDISMODULE_WRITE);
 /* Key must be empty or list */
  if ((RedisModule_KeyType(key) != REDISMODULE_KEYTYPE_LIST &&
       RedisModule_KeyType(key) != REDISMODULE_KEYTYPE_EMPTY)) 
  {
     RedisModule_CloseKey(key);
     return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE);
  }

  /* Get count */
  long long count;
  if ((RedisModule_StringToLongLong(argv[2],&count) != REDISMODULE_OK) ||
        (count < 0)) 
  {
     RedisModule_CloseKey(key);
     return RedisModule_ReplyWithError(ctx,"ERR invalid count");
  }

  /* Push count randoms */
  std::normal_distribution<double> rnorm(mean,sd);
  while (count-- > 0)
  {
    RedisModuleString *ele;
    /* Make string with the same 19 digita precision of ReplyWithDouble */
    ele=RedisModule_CreateStringPrintf(ctx,"%.19f",rnorm(gen));
    RedisModule_ListPush(key,REDISMODULE_LIST_HEAD,ele);
    RedisModule_FreeString(ctx,ele);
  }
 
  size_t len = RedisModule_ValueLength(key);
  RedisModule_CloseKey(key);
  RedisModule_ReplyWithLongLong(ctx, len);
  return REDISMODULE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd 0x341a(%rip), %xmm0     # 0xa000
movsd %xmm0, -0x30(%rbp)
cmpl $0x5, -0x1c(%rbp)
jle 0x6c09
movq 0x7348(%rip), %rax      # 0xdf40
movq (%rax), %rax
movq -0x10(%rbp), %rdi
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0x6e2e
cmpl $0x4, -0x1c(%rbp)
jl 0x6c4d
movq 0x72ca(%rip), %rax      # 0xdee0
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rdi
leaq -0x28(%rbp), %rsi
callq *%rax
cmpl $0x0, %eax
je 0x6c4b
movq 0x713d(%rip), %rax      # 0xdd70
movq (%rax), %rax
movq -0x10(%rbp), %rdi
leaq 0x3421(%rip), %rsi      # 0xa062
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0x6e2e
jmp 0x6c4d
cmpl $0x5, -0x1c(%rbp)
jne 0x6c91
movq 0x7286(%rip), %rax      # 0xdee0
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rdi
leaq -0x30(%rbp), %rsi
callq *%rax
cmpl $0x0, %eax
je 0x6c8f
movq 0x70f9(%rip), %rax      # 0xdd70
movq (%rax), %rax
movq -0x10(%rbp), %rdi
leaq 0x33ee(%rip), %rsi      # 0xa073
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0x6e2e
jmp 0x6c91
movq 0x7170(%rip), %rax      # 0xde08
movq (%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rsi
movl $0x3, %edx
callq *%rax
movq %rax, -0x38(%rbp)
movq 0x7177(%rip), %rax      # 0xde30
movq (%rax), %rax
movq -0x38(%rbp), %rdi
callq *%rax
cmpl $0x2, %eax
je 0x6d0b
movq 0x7162(%rip), %rax      # 0xde30
movq (%rax), %rax
movq -0x38(%rbp), %rdi
callq *%rax
cmpl $0x0, %eax
je 0x6d0b
movq 0x7305(%rip), %rax      # 0xdfe8
movq (%rax), %rax
movq -0x38(%rbp), %rdi
callq *%rax
movq 0x707d(%rip), %rax      # 0xdd70
movq (%rax), %rax
movq -0x10(%rbp), %rdi
leaq 0x33b3(%rip), %rsi      # 0xa0b4
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0x6e2e
movq 0x720e(%rip), %rax      # 0xdf20
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rdi
leaq -0x40(%rbp), %rsi
callq *%rax
cmpl $0x0, %eax
jne 0x6d2f
cmpq $0x0, -0x40(%rbp)
jge 0x6d5e
movq 0x72b2(%rip), %rax      # 0xdfe8
movq (%rax), %rax
movq -0x38(%rbp), %rdi
callq *%rax
movq 0x702a(%rip), %rax      # 0xdd70
movq (%rax), %rax
movq -0x10(%rbp), %rdi
leaq 0x33a2(%rip), %rsi      # 0xa0f6
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0x6e2e
movsd -0x28(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
leaq -0x60(%rbp), %rdi
callq 0x6510
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x40(%rbp)
cmpq $0x0, %rax
jle 0x6def
movq 0x7093(%rip), %rax      # 0xde20
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x60(%rbp), %rdi
movq 0x71f1(%rip), %rsi      # 0xdf98
callq 0x6220
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rcx
leaq 0x334d(%rip), %rsi      # 0xa108
movb $0x1, %al
callq *%rcx
movq %rax, -0x68(%rbp)
movq 0x7166(%rip), %rax      # 0xdf30
movq (%rax), %rax
movq -0x38(%rbp), %rdi
movq -0x68(%rbp), %rdx
xorl %esi, %esi
callq *%rax
movq 0x6e90(%rip), %rax      # 0xdc70
movq (%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq *%rax
jmp 0x6d71
movq 0x6e22(%rip), %rax      # 0xdc18
movq (%rax), %rax
movq -0x38(%rbp), %rdi
callq *%rax
movq %rax, -0x70(%rbp)
movq 0x71de(%rip), %rax      # 0xdfe8
movq (%rax), %rax
movq -0x38(%rbp), %rdi
callq *%rax
movq 0x7156(%rip), %rax      # 0xdf70
movq (%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq *%rax
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)