// File: /workspace/github_c_makefile_star2_O0/umbrant[P]Non-blocking-Buffers/nameserver.c
// Function: handle_service
void handle_service(char* arg)
{
  printf("** Handling service\n");

  char* service_name = strtok(arg, " ");
  int num_channels = atoi(strtok(NULL, " "));
  int service_pid = atoi(strtok(NULL, " "));
  int slot;
  char* msg = (char*)calloc(50,sizeof(char));
  int i;

  slot = reserve_service_slot();

//printf("test\n");
  if(slot == -1) {
    return;
  }

  service_lists[slot].name = (char*)malloc(strlen(service_name));
  strcpy(service_lists[slot].name, service_name);
  service_lists[slot].num_channels = num_channels;
  service_lists[slot].channel_ids = (int*)malloc(sizeof(int)*num_channels);
  service_lists[slot].is_channel_busy = (int*)calloc(num_channels,sizeof(int));
  service_lists[slot].pid = service_pid;

  printf("** Name: %s, num_channel:%d, pid: %d\n", service_lists[slot].name, num_channels, service_pid);

  if(reserve_channel(slot)) { 
    printf("** Unable to reserve %d channels\n", num_channels);
    strcpy(msg, NAMESERVER_CHANNEL_FULL);
  }
  else {
    printf("** Able to reserve %d channels\n", num_channels);
    for(i = 0;i < service_lists[slot].num_channels;i++) {
      char tmp[5] = "\0"; 
      sprintf(tmp, "%d", service_lists[slot].channel_ids[i]);
      strcat(msg, tmp);
      strcat(msg, " "); 
    }
  }

  nbb_insert_item(CHANNEL_ID, msg, strlen(msg));
  free(msg); 
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
leaq 0x1618(%rip), %rdi      # 0x4acb
movb $0x0, %al
callq 0x10b0
movq -0x8(%rbp), %rdi
leaq 0xc9b(%rip), %rsi       # 0x4160
callq 0x11d0
movq %rax, -0x10(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0xc87(%rip), %rsi       # 0x4160
callq 0x11d0
movq %rax, %rdi
callq 0x1200
movl %eax, -0x14(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0xc6c(%rip), %rsi       # 0x4160
callq 0x11d0
movq %rax, %rdi
callq 0x1200
movl %eax, -0x18(%rbp)
movl $0x32, %edi
movl $0x1, %esi
callq 0x1100
movq %rax, -0x28(%rbp)
callq 0x38c0
movl %eax, -0x1c(%rbp)
cmpl $-0x1, -0x1c(%rbp)
jne 0x352a
jmp 0x3710
movq -0x10(%rbp), %rdi
callq 0x10a0
movq %rax, %rdi
callq 0x1170
movq %rax, %rcx
movslq -0x1c(%rbp), %rdx
leaq 0x43a7(%rip), %rax      # 0x78f0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movslq -0x1c(%rbp), %rcx
leaq 0x4392(%rip), %rax      # 0x78f0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x1040
movl -0x14(%rbp), %ecx
movslq -0x1c(%rbp), %rdx
leaq 0x4371(%rip), %rax      # 0x78f0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x18(%rax)
movslq -0x14(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1170
movq %rax, %rcx
movslq -0x1c(%rbp), %rdx
leaq 0x434c(%rip), %rax      # 0x78f0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movslq -0x14(%rbp), %rdi
movl $0x4, %esi
callq 0x1100
movq %rax, %rcx
movslq -0x1c(%rbp), %rdx
leaq 0x4325(%rip), %rax      # 0x78f0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movl -0x18(%rbp), %ecx
movslq -0x1c(%rbp), %rdx
leaq 0x430c(%rip), %rax      # 0x78f0
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x1c(%rax)
movslq -0x1c(%rbp), %rcx
leaq 0x42f7(%rip), %rax      # 0x78f0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
leaq 0x14d0(%rip), %rdi      # 0x4ae0
movb $0x0, %al
callq 0x10b0
movl -0x1c(%rbp), %edi
callq 0x3720
cmpl $0x0, %eax
je 0x364a
movl -0x14(%rbp), %esi
leaq 0x14d8(%rip), %rdi      # 0x4b06
movb $0x0, %al
callq 0x10b0
movq -0x28(%rbp), %rdi
leaq 0x1540(%rip), %rsi      # 0x4b80
callq 0x1040
jmp 0x36e8
movl -0x14(%rbp), %esi
leaq 0x14d4(%rip), %rdi      # 0x4b28
movb $0x0, %al
callq 0x10b0
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movslq -0x1c(%rbp), %rdx
leaq 0x4280(%rip), %rcx      # 0x78f0
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x18(%rcx), %eax
jge 0x36e6
leaq -0x31(%rbp), %rdi
xorl %esi, %esi
movl $0x5, %edx
callq 0x10d0
leaq -0x31(%rbp), %rdi
movslq -0x1c(%rbp), %rcx
leaq 0x4255(%rip), %rax      # 0x78f0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x9ed(%rip), %rsi       # 0x40a1
movb $0x0, %al
callq 0x1220
movq -0x28(%rbp), %rdi
leaq -0x31(%rbp), %rsi
callq 0x1210
movq -0x28(%rbp), %rdi
leaq 0xa8d(%rip), %rsi       # 0x4160
callq 0x1210
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3662
jmp 0x36e8
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10a0
movq -0x40(%rbp), %rsi
movq %rax, %rdx
xorl %edi, %edi
callq 0x1840
movq -0x28(%rbp), %rdi
callq 0x1030
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)