// File: /workspace/github_c_makefile_star2_O0/CBaquero[P]random/Random.cc
// Function: RandomLUnif_RedisCommand(RedisModuleCtx*, RedisModuleString**, int)
int RandomLUnif_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
  double start, end;
  if (argc != 5) return RedisModule_WrongArity(ctx);
  if (RedisModule_StringToDouble(argv[3],&start) != REDISMODULE_OK)
    return RedisModule_ReplyWithError(ctx,"ERR invalid start");
  if (RedisModule_StringToDouble(argv[4],&end) != REDISMODULE_OK)
    return RedisModule_ReplyWithError(ctx,"ERR invalid end");

  /* 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::uniform_real_distribution<double> runif(start,end);
  while (count-- > 0)
  {
    RedisModuleString *ele;
    /* Make string with the same 19 digita precision of ReplyWithDouble */
    ele=RedisModule_CreateStringPrintf(ctx,"%.19f",runif(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 $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
cmpl $0x5, -0x1c(%rbp)
je 0x69a1
movq 0x75b0(%rip), %rax      # 0xdf40
movq (%rax), %rax
movq -0x10(%rbp), %rdi
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0x6bb6
movq 0x7538(%rip), %rax      # 0xdee0
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rdi
leaq -0x28(%rbp), %rsi
callq *%rax
cmpl $0x0, %eax
je 0x69dd
movq 0x73ab(%rip), %rax      # 0xdd70
movq (%rax), %rax
movq -0x10(%rbp), %rdi
leaq 0x36bf(%rip), %rsi      # 0xa092
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0x6bb6
movq 0x74fc(%rip), %rax      # 0xdee0
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rdi
leaq -0x30(%rbp), %rsi
callq *%rax
cmpl $0x0, %eax
je 0x6a19
movq 0x736f(%rip), %rax      # 0xdd70
movq (%rax), %rax
movq -0x10(%rbp), %rdi
leaq 0x3695(%rip), %rsi      # 0xa0a4
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0x6bb6
movq 0x73e8(%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 0x73ef(%rip), %rax      # 0xde30
movq (%rax), %rax
movq -0x38(%rbp), %rdi
callq *%rax
cmpl $0x2, %eax
je 0x6a93
movq 0x73da(%rip), %rax      # 0xde30
movq (%rax), %rax
movq -0x38(%rbp), %rdi
callq *%rax
cmpl $0x0, %eax
je 0x6a93
movq 0x757d(%rip), %rax      # 0xdfe8
movq (%rax), %rax
movq -0x38(%rbp), %rdi
callq *%rax
movq 0x72f5(%rip), %rax      # 0xdd70
movq (%rax), %rax
movq -0x10(%rbp), %rdi
leaq 0x362b(%rip), %rsi      # 0xa0b4
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0x6bb6
movq 0x7486(%rip), %rax      # 0xdf20
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rdi
leaq -0x40(%rbp), %rsi
callq *%rax
cmpl $0x0, %eax
jne 0x6ab7
cmpq $0x0, -0x40(%rbp)
jge 0x6ae6
movq 0x752a(%rip), %rax      # 0xdfe8
movq (%rax), %rax
movq -0x38(%rbp), %rdi
callq *%rax
movq 0x72a2(%rip), %rax      # 0xdd70
movq (%rax), %rax
movq -0x10(%rbp), %rdi
leaq 0x361a(%rip), %rsi      # 0xa0f6
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0x6bb6
movsd -0x28(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
leaq -0x50(%rbp), %rdi
callq 0x6110
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x40(%rbp)
cmpq $0x0, %rax
jle 0x6b77
movq 0x730b(%rip), %rax      # 0xde20
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x50(%rbp), %rdi
movq 0x7469(%rip), %rsi      # 0xdf98
callq 0x64d0
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rcx
leaq 0x35c5(%rip), %rsi      # 0xa108
movb $0x1, %al
callq *%rcx
movq %rax, -0x58(%rbp)
movq 0x73de(%rip), %rax      # 0xdf30
movq (%rax), %rax
movq -0x38(%rbp), %rdi
movq -0x58(%rbp), %rdx
xorl %esi, %esi
callq *%rax
movq 0x7108(%rip), %rax      # 0xdc70
movq (%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq *%rax
jmp 0x6af9
movq 0x709a(%rip), %rax      # 0xdc18
movq (%rax), %rax
movq -0x38(%rbp), %rdi
callq *%rax
movq %rax, -0x60(%rbp)
movq 0x7456(%rip), %rax      # 0xdfe8
movq (%rax), %rax
movq -0x38(%rbp), %rdi
callq *%rax
movq 0x73ce(%rip), %rax      # 0xdf70
movq (%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq *%rax
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop