// File: /workspace/github_c_makefile_star2_O3/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, 0x2cee(%rip)      # 0x50f4
jne 0x2591
leaq 0x50(%rsp), %rbx
leaq 0x4(%rsp), %r13
leaq 0x8(%rsp), %rbp
movl $0x7a, %r15d
movq %rbx, %rdi
movq %r13, %rsi
callq 0x10b0
testl %eax, %eax
jne 0x2581
movl 0x4(%rsp), %r12d
shrl $0x2, %r12d
andl $0x3f, %r12d
leaq 0x110d(%rip), %rdi      # 0x3555
movl %r12d, %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 %r12d, %r12d
je 0x24c9
xorl %r14d, %r14d
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x10b0
testl %eax, %eax
jne 0x2581
movl 0x8(%rsp), %eax
movq %r14, %rdx
xorl %ecx, %ecx
cmpq %r12, %rdx
jae 0x24c0
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 %r15d, %esi
movb %sil, 0x10(%rsp,%rdx)
addq $0x5, %rcx
incq %rdx
cmpq $0x1e, %rcx
jne 0x248d
addq $0x6, %r14
cmpq %r12, %r14
jb 0x2471
leaq 0x1093(%rip), %rdi      # 0x3563
leaq 0x10(%rsp), %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 0x2559
cmpl $0x1, %eax
je 0x2529
testl %eax, %eax
jne 0x25a5
leaq 0x13a3(%rip), %rdi      # 0x38b6
callq 0x1070
movl %r12d, %esi
leaq 0x10(%rsp), %rdi
xorl %edx, %edx
callq 0x1462
jmp 0x2572
leaq 0x137f(%rip), %rdi      # 0x38af
callq 0x1070
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0x10b0
testl %eax, %eax
jne 0x2581
movl %r12d, %esi
movl 0xc(%rsp), %edx
leaq 0x10(%rsp), %rdi
callq 0x18a1
jmp 0x2572
leaq 0x1348(%rip), %rdi      # 0x38a8
callq 0x1070
movl %r12d, %esi
leaq 0x10(%rsp), %rdi
callq 0x1b32
cmpl $0x0, 0x2b7b(%rip)      # 0x50f4
je 0x2421
jmp 0x2591
leaq 0xfab(%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 0xf28(%rip), %rdi       # 0x34d4
leaq 0xf23(%rip), %rsi       # 0x34d6
leaq 0xfbe(%rip), %rcx       # 0x3578
movl $0x68, %edx
callq 0x1090