// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/unifi-motion.c
// Function: ev_handler
static void ev_handler(struct mg_connection *nc, int ev, void *p) {
  struct mg_mqtt_message *msg = (struct mg_mqtt_message *)p;
  (void)nc;

  //if (ev != MG_EV_POLL) LOG("MQTT handler got event %d\n", ev);
  switch (ev) {
    case MG_EV_CONNECT: {
      struct mg_send_mqtt_handshake_opts opts;
      memset(&opts, 0, sizeof(opts));
      opts.user_name = _config.mqtt_user;
      opts.password = _config.mqtt_passwd;
      opts.keep_alive = 5;
      opts.flags |= MG_MQTT_CLEAN_SESSION; // NFS Need to readup on this
      mg_set_protocol_mqtt(nc);
      mg_send_mqtt_handshake_opt(nc, _config.mqtt_ID, opts);
      fprintf(stderr, "Connected to mqtt %s with id of: %s\n", _config.mqtt_address, _config.mqtt_ID);
      _mqtt_status = mqttrunning;
      _mqtt_connection = nc;
    } break;
    case MG_EV_MQTT_CONNACK:
      if (msg->connack_ret_code != MG_EV_MQTT_CONNACK_ACCEPTED) {
        LOG("Got mqtt connection error: %d\n", msg->connack_ret_code);
        _mqtt_status = mqttstopped;
        _mqtt_connection = NULL;
      }
    break;
    case MG_EV_MQTT_PUBACK:
      LOG("Message publishing acknowledged (msg_id: %d)\n", msg->message_id);
    break;
    case MG_EV_CLOSE:
      fprintf( stderr, "MQTT Connection closed\n");
      _mqtt_status = mqttstopped;
      _mqtt_connection = NULL;
    break;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x4c(%rbp)
subl $0x2, %eax
je 0x3c0c
jmp 0x3bdb
movl -0x4c(%rbp), %eax
subl $0x5, %eax
je 0x3ce7
jmp 0x3be9
movl -0x4c(%rbp), %eax
subl $0xca, %eax
je 0x3cc1
jmp 0x3bf9
movl -0x4c(%rbp), %eax
subl $0xcc, %eax
je 0x3ce5
jmp 0x3d14
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x3260
movq 0x23865(%rip), %rax     # 0x27488
movq %rax, -0x30(%rbp)
movq 0x23862(%rip), %rax     # 0x27490
movq %rax, -0x28(%rbp)
movw $0x5, -0x46(%rbp)
movzbl -0x48(%rbp), %eax
orl $0x2, %eax
movb %al, -0x48(%rbp)
movq -0x8(%rbp), %rdi
callq 0x17120
movq -0x8(%rbp), %rdi
leaq 0x2382a(%rip), %rax     # 0x27480
addq $0x30, %rax
movq -0x28(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x20(%rax)
movups -0x48(%rbp), %xmm0
movups -0x38(%rbp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq 0x23835(%rip), %rsi     # 0x274b0
callq 0x173f0
movq 0x23369(%rip), %rax     # 0x26ff0
movq (%rax), %rdi
movq 0x237ef(%rip), %rdx     # 0x27480
leaq 0x1b618(%rip), %rsi     # 0x1f2b0
leaq 0x237e1(%rip), %rcx     # 0x27480
addq $0x30, %rcx
movb $0x0, %al
callq 0x3370
movl $0x1, 0x236bc(%rip)     # 0x27370
movq -0x8(%rbp), %rax
movq %rax, 0x237b9(%rip)     # 0x27478
jmp 0x3d14
movq -0x20(%rbp), %rax
movzbl 0x30(%rax), %eax
cmpl $0x0, %eax
je 0x3ce3
movl $0x2, 0x23698(%rip)     # 0x27370
movq $0x0, 0x23795(%rip) # 0x27478
jmp 0x3d14
jmp 0x3d14
movq 0x23302(%rip), %rax     # 0x26ff0
movq (%rax), %rdi
leaq 0x1b5dd(%rip), %rsi     # 0x1f2d5
movb $0x0, %al
callq 0x3370
movl $0x2, 0x23667(%rip)     # 0x27370
movq $0x0, 0x23764(%rip) # 0x27478
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)