// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x10(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x10d0
movl %eax, -0x144(%rbp)
leaq -0x140(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x144(%rbp), %edi
leaq -0x140(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
leaq -0x40(%rbp), %rcx
callq 0x1160
movl 0x25da(%rip), %eax      # 0x50f4
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2b2b
jmp 0x2df3
leaq -0x40(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x10b0
movl %eax, -0x14c(%rbp)
movl -0x148(%rbp), %eax
sarl $0x2, %eax
andl $0x3f, %eax
movl %eax, -0x150(%rbp)
cmpl $0x0, -0x14c(%rbp)
je 0x2b7d
movl -0x14c(%rbp), %esi
leaq 0xdaa(%rip), %rdi       # 0x3913
movb $0x0, %al
callq 0x1070
movq $0x0, -0x8(%rbp)
jmp 0x2dfb
movl -0x150(%rbp), %esi
leaq 0xdab(%rip), %rdi       # 0x3935
movb $0x0, %al
callq 0x1070
leaq -0x190(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x1090
movl $0x0, -0x194(%rbp)
movl -0x194(%rbp), %eax
cmpl -0x150(%rbp), %eax
jge 0x2cb8
leaq -0x40(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x10b0
movl %eax, -0x14c(%rbp)
cmpl $0x0, -0x14c(%rbp)
je 0x2c00
movl -0x14c(%rbp), %esi
leaq 0xd27(%rip), %rdi       # 0x3913
movb $0x0, %al
callq 0x1070
movq $0x0, -0x8(%rbp)
jmp 0x2dfb
movl $0x0, -0x19c(%rbp)
xorl %eax, %eax
cmpl $0x6, -0x19c(%rbp)
movb %al, -0x1a2(%rbp)
jge 0x2c36
movl -0x19c(%rbp), %eax
addl -0x194(%rbp), %eax
cmpl -0x150(%rbp), %eax
setl %al
movb %al, -0x1a2(%rbp)
movb -0x1a2(%rbp), %al
testb $0x1, %al
jne 0x2c42
jmp 0x2ca2
movl -0x1a0(%rbp), %eax
imull $0x5, -0x19c(%rbp), %ecx
sarl %cl, %eax
andl $0x1f, %eax
movb %al, -0x1a1(%rbp)
movsbl -0x1a1(%rbp), %eax
cmpl $0x19, %eax
jle 0x2c6d
movb $0x19, -0x1a1(%rbp)
movsbl -0x1a1(%rbp), %eax
addl $0x61, %eax
movb %al, %cl
movl -0x194(%rbp), %eax
addl -0x19c(%rbp), %eax
cltq
movb %cl, -0x190(%rbp,%rax)
movl -0x19c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x19c(%rbp)
jmp 0x2c0a
jmp 0x2ca4
movl -0x194(%rbp), %eax
addl $0x6, %eax
movl %eax, -0x194(%rbp)
jmp 0x2bae
leaq 0xc84(%rip), %rdi       # 0x3943
xorl %eax, %eax
leaq -0x190(%rbp), %rsi
callq 0x1070
movslq -0x148(%rbp), %rcx
movl %ecx, %eax
imulq $0x55555556, %rcx, %rdx # imm = 0x55555556
movq %rdx, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rdx
addl %ecx, %edx
movl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
movl %eax, -0x1a8(%rbp)
je 0x2d1c
jmp 0x2cfb
movl -0x1a8(%rbp), %eax
subl $0x1, %eax
je 0x2d46
jmp 0x2d08
movl -0x1a8(%rbp), %eax
subl $0x2, %eax
je 0x2dac
jmp 0x2dcf
leaq 0xc35(%rip), %rdi       # 0x3958
movb $0x0, %al
callq 0x1070
leaq -0x190(%rbp), %rdi
movslq -0x150(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x15c0
jmp 0x2dee
leaq 0xc13(%rip), %rdi       # 0x3960
movb $0x0, %al
callq 0x1070
leaq -0x40(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x10b0
movl %eax, -0x14c(%rbp)
cmpl $0x0, -0x14c(%rbp)
je 0x2d91
movl -0x14c(%rbp), %esi
leaq 0xb93(%rip), %rdi       # 0x3913
movb $0x0, %al
callq 0x1070
movq $0x0, -0x8(%rbp)
jmp 0x2dfb
leaq -0x190(%rbp), %rdi
movslq -0x150(%rbp), %rsi
movl -0x198(%rbp), %edx
callq 0x1c10
jmp 0x2dee
leaq 0xbb5(%rip), %rdi       # 0x3968
movb $0x0, %al
callq 0x1070
leaq -0x190(%rbp), %rdi
movslq -0x150(%rbp), %rsi
callq 0x1fc0
jmp 0x2dee
leaq 0xabe(%rip), %rdi       # 0x3894
leaq 0xab9(%rip), %rsi       # 0x3896
movl $0x68, %edx
leaq 0xb87(%rip), %rcx       # 0x3970
callq 0x1080
jmp 0x2b14
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq