// File: /workspace/github_c_makefile_star2_O2/stevenmherring[P]DNS/main.c
// Function: client
static void *
client(void *arg)
{
  struct random_data rd;
  char rand_state[256];
  int32_t salt = time(0);

  // See http://lists.debian.org/debian-glibc/2006/01/msg00037.html
  rd.state = (int32_t*)rand_state;

  // Initialize the prng.  For testing, it may be helpful to reduce noise by
  // temporarily setting this to a fixed value.
  initstate_r(salt, rand_state, sizeof(rand_state), &rd);

  while (!finished) {

    /* Pick a random operation, string, and ip */
    int32_t code;
    int rv = random_r(&rd, &code);
    int length = (code >> 2) & (64-1);
    char buf[64];
    int j;
    int32_t ip4_addr;

    if (rv) {
      printf("Failed to get random number - %d\n", rv);
      return NULL;
    }

    DEBUG_PRINT("Length is %d\n", length);
    memset(buf, 0, 64);
    /* Generate a random string in lowercase */
    for (j = 0; j < length; j+= 6) {
      int i;
      int32_t chars;

      rv = random_r(&rd, &chars);
      if (rv) {
        printf("Failed to get random number - %d\n", rv);
        return NULL;
      }

      for (i = 0; i < 6 && (i+j) < length; i++) {
        char val = ( (chars >> (5 * i)) & 31);
        if (val > 25)
        val = 25;
        buf[j+i] = 'a' + val;
      }
    }

    DEBUG_PRINT ("Random string is %s\n", buf);


    switch (code % 3) {
      case 0: // Search
      DEBUG_PRINT ("Search\n");
      search (buf, length, NULL);
      break;
      case 1: // insert
      DEBUG_PRINT ("insert\n");
      rv = random_r(&rd, &ip4_addr);
      if (rv) {
        printf("Failed to get random number - %d\n", rv);
        return NULL;
      }

      insert (buf, length, ip4_addr);
      break;
      case 2: // delete
      DEBUG_PRINT ("delete\n");
      delete (buf, length);
      break;
      default:
      assert(0);
    }
  }

  return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
xorl %edi, %edi
callq 0x10d0
leaq 0x80(%rsp), %rsi
leaq 0x50(%rsp), %rbx
movq %rsi, 0x10(%rbx)
movl $0x100, %edx            # imm = 0x100
movl %eax, %edi
movq %rbx, %rcx
callq 0x1160
leaq 0x4(%rsp), %rsi
leaq 0x121e(%rip), %r14      # 0x3555
leaq 0x10(%rsp), %r12
pushq $0x7a
popq %r15
cmpl $0x0, 0x3dad(%rip)      # 0x60f4
jne 0x24c8
movq %rbx, %rdi
callq 0x10b0
testl %eax, %eax
jne 0x24b8
movl 0x4(%rsp), %ebp
shrl $0x2, %ebp
andl $0x3f, %ebp
movq %r14, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x1080
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
xorl %r14d, %r14d
movl %ebp, %r13d
cmpq %rbp, %r14
jae 0x23fe
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
callq 0x10b0
testl %eax, %eax
jne 0x24b8
movl %r13d, %eax
leaq (%rax,%rax,4), %rax
movl 0x8(%rsp), %edx
movq %r12, %rsi
xorl %ecx, %ecx
cmpq $0x1e, %rcx
je 0x23f0
cmpq %rcx, %rax
je 0x23f0
movl %edx, %edi
sarl %cl, %edi
movl %edi, %r8d
andl $0x1e, %r8d
andb $0x1f, %dil
addb $0x61, %dil
cmpl $0x1a, %r8d
movzbl %dil, %edi
cmovael %r15d, %edi
movb %dil, (%rsi)
addq $0x5, %rcx
incq %rsi
jmp 0x23ba
addq $0x6, %r14
addl $-0x6, %r13d
addq $0x6, %r12
jmp 0x2390
leaq 0x115e(%rip), %rdi      # 0x3563
leaq 0x10(%rsp), %r12
movq %r12, %rsi
xorl %eax, %eax
callq 0x1080
movl 0x4(%rsp), %eax
cltd
pushq $0x3
popq %rcx
idivl %ecx
cmpl $0x2, %edx
je 0x2490
cmpl $0x1, %edx
leaq 0x1128(%rip), %r14      # 0x3555
je 0x245a
testl %edx, %edx
jne 0x24dc
leaq 0x1478(%rip), %rdi      # 0x38b6
callq 0x1070
movq %r12, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x144b
leaq 0x4(%rsp), %rsi
jmp 0x2340
leaq 0x144e(%rip), %rdi      # 0x38af
callq 0x1070
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0x10b0
testl %eax, %eax
jne 0x24b8
movl 0xc(%rsp), %edx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x189f
leaq 0x4(%rsp), %rsi
jmp 0x2340
leaq 0x1411(%rip), %rdi      # 0x38a8
callq 0x1070
movq %r12, %rdi
movq %rbp, %rsi
callq 0x1aec
leaq 0x4(%rsp), %rsi
leaq 0x10a2(%rip), %r14      # 0x3555
jmp 0x2340
leaq 0x1074(%rip), %rdi      # 0x3533
movl %eax, %esi
xorl %eax, %eax
callq 0x1080
xorl %eax, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xff1(%rip), %rdi       # 0x34d4
leaq 0xfec(%rip), %rsi       # 0x34d6
leaq 0x1087(%rip), %rcx      # 0x3578
pushq $0x68
popq %rdx
callq 0x1090