// File: /workspace/github_c_makefile_star2_O1/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), %rcx
movq %rsi, 0x10(%rcx)
movl $0x100, %edx            # imm = 0x100
movl %eax, %edi
callq 0x1160
cmpl $0x0, 0x2d38(%rip)      # 0x50f4
je 0x23d2
xorl %eax, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x50(%rsp), %rbx
leaq 0x4(%rsp), %rsi
movl $0x7a, %r13d
movq %rbx, %rdi
callq 0x10b0
testl %eax, %eax
jne 0x2563
movl 0x4(%rsp), %r15d
shrl $0x2, %r15d
andl $0x3f, %r15d
leaq 0x114f(%rip), %rdi      # 0x3555
movl %r15d, %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)
testl %r15d, %r15d
je 0x24a6
movl %r15d, %r12d
xorl %ebp, %ebp
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
callq 0x10b0
movl %eax, %r14d
testl %eax, %eax
je 0x2458
leaq 0x10e7(%rip), %rdi      # 0x3533
movl %r14d, %esi
xorl %eax, %eax
callq 0x1080
jmp 0x2494
movl 0x8(%rsp), %eax
movq %rbp, %rdx
xorl %ecx, %ecx
cmpq %r15, %rdx
jae 0x2494
movl %eax, %esi
sarl %cl, %esi
movl %esi, %edi
andl $0x1e, %edi
andb $0x1f, %sil
addb $0x61, %sil
cmpl $0x1a, %edi
movzbl %sil, %esi
cmovael %r13d, %esi
movb %sil, 0x10(%rsp,%rdx)
addq $0x5, %rcx
incq %rdx
cmpq $0x1e, %rcx
jne 0x2461
testl %r14d, %r14d
jne 0x23be
addq $0x6, %rbp
cmpq %r12, %rbp
jb 0x2431
leaq 0x10b6(%rip), %rdi      # 0x3563
leaq 0x10(%rsp), %r14
movq %r14, %rsi
xorl %eax, %eax
callq 0x1080
movslq 0x4(%rsp), %rax
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
cmpl $0x2, %eax
je 0x2535
cmpl $0x1, %eax
je 0x2507
testl %eax, %eax
jne 0x2578
leaq 0x13c3(%rip), %rdi      # 0x38b6
callq 0x1070
movl %r15d, %esi
movq %r14, %rdi
xorl %edx, %edx
callq 0x1464
jmp 0x254c
leaq 0x13a1(%rip), %rdi      # 0x38af
callq 0x1070
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0x10b0
testl %eax, %eax
jne 0x2563
movl %r15d, %esi
movl 0xc(%rsp), %edx
movq %r14, %rdi
callq 0x18a0
jmp 0x254c
leaq 0x136c(%rip), %rdi      # 0x38a8
callq 0x1070
movl %r15d, %esi
movq %r14, %rdi
callq 0x1b06
cmpl $0x0, 0x2ba1(%rip)      # 0x50f4
leaq 0x4(%rsp), %rsi
je 0x23e2
jmp 0x23be
leaq 0xfc9(%rip), %rdi       # 0x3533
movl %eax, %esi
xorl %eax, %eax
callq 0x1080
jmp 0x23be
leaq 0xf55(%rip), %rdi       # 0x34d4
leaq 0xf50(%rip), %rsi       # 0x34d6
leaq 0xfeb(%rip), %rcx       # 0x3578
movl $0x68, %edx
callq 0x1090