// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/mongoose/mongoose.c
// Function: mg_set_option
const char *mg_set_option(struct mg_server *server, const char *name,
                          const char *value) {
  int ind = get_option_index(name);
  const char *error_msg = NULL;
  char **v = NULL;

  if (ind < 0) return  "No such option";
  v = &server->config_options[ind];

  // Return success immediately if setting to the same value
  if ((*v == NULL && value == NULL) ||
      (value != NULL && *v != NULL && !strcmp(value, *v))) {
    return NULL;
  }

  if (*v != NULL) {
    NS_FREE(*v);
    *v = NULL;
  }

  if (value == NULL || value[0] == '\0') return NULL;

  *v = mg_strdup(value);
  DBG(("%s [%s]", name, *v));

  if (ind == LISTENING_PORT) {
    char buf[500] = "";
    size_t n = 0;
    struct vec vec;

    /*
     * Ports can be specified as 0, meaning that OS has to choose any
     * free port that is available. In order to pass chosen port number to
     * the user, we rewrite all 0 port to chosen values.
     */
    while ((value = next_option(value, &vec, NULL)) != NULL) {
      struct ns_connection *c = ns_bind(&server->ns_mgr, vec.ptr,
                                        mg_ev_handler, NULL);
      if (c == NULL) {
        error_msg = "Cannot bind to port";
        break;
      } else {
        char buf2[50], cert[100], ca[100];
        union socket_address sa;
        int proto, use_ssl;

        ns_parse_address(vec.ptr, &sa, &proto, &use_ssl, cert, ca);
        ns_sock_to_str(c->sock, buf2, sizeof(buf2),
                       memchr(vec.ptr, ':', vec.len) == NULL ? 2 : 3);

        n += snprintf(buf + n, sizeof(buf) - n, "%s%s%s%s%s%s%s",
                      n > 0 ? "," : "",
                      use_ssl ? "ssl://" : "",
                      buf2, cert[0] ? ":" : "", cert, ca[0] ? ":" : "", ca);
      }
    }
    buf[sizeof(buf) - 1] = '\0';
    NS_FREE(*v);
    *v = mg_strdup(buf);
#ifndef MONGOOSE_NO_FILESYSTEM
  } else if (ind == HEXDUMP_FILE) {
    server->ns_mgr.hexdump_file = *v;
#endif
#if !defined(_WIN32) && !defined(MONGOOSE_NO_USER)
  } else if (ind == RUN_AS_USER) {
    struct passwd *pw;
    if ((pw = getpwnam(value)) == NULL) {
      error_msg = "Unknown user";
    } else if (setgid(pw->pw_gid) != 0) {
      error_msg = "setgid() failed";
    } else if (setuid(pw->pw_uid) != 0) {
      error_msg = "setuid() failed";
    }
#endif
  }

  return error_msg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x3c8, %rsp            # imm = 0x3C8
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0xb5a10
movl %eax, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0xb56aa
leaq 0x11647(%rip), %rax     # 0xc6ce8
movq %rax, -0x10(%rbp)
jmp 0xb5a01
movq -0x18(%rbp), %rax
addq $0x38, %rax
movslq -0x2c(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq $0x0, (%rax)
jne 0xb56d2
cmpq $0x0, -0x28(%rbp)
je 0xb56f8
cmpq $0x0, -0x28(%rbp)
je 0xb5705
movq -0x40(%rbp), %rax
cmpq $0x0, (%rax)
je 0xb5705
movq -0x28(%rbp), %rdi
movq -0x40(%rbp), %rax
movq (%rax), %rsi
callq 0xdab0
cmpl $0x0, %eax
jne 0xb5705
movq $0x0, -0x10(%rbp)
jmp 0xb5a01
movq -0x40(%rbp), %rax
cmpq $0x0, (%rax)
je 0xb5726
movq -0x40(%rbp), %rax
movq (%rax), %rdi
callq 0xd2c0
movq -0x40(%rbp), %rax
movq $0x0, (%rax)
cmpq $0x0, -0x28(%rbp)
je 0xb5739
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xb5746
movq $0x0, -0x10(%rbp)
jmp 0xb5a01
movq -0x28(%rbp), %rdi
callq 0xb5a80
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
cmpl $0xf, -0x2c(%rbp)
jne 0xb596f
leaq -0x240(%rbp), %rdi
xorl %esi, %esi
movl $0x1f4, %edx            # imm = 0x1F4
callq 0xd430
movq $0x0, -0x248(%rbp)
movq -0x28(%rbp), %rdi
leaq -0x258(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xb5ad0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0xb5944
movq -0x18(%rbp), %rdi
movq -0x258(%rbp), %rsi
leaq -0x23a5(%rip), %rdx     # 0xb3410
xorl %eax, %eax
movl %eax, %ecx
callq 0xaf470
movq %rax, -0x260(%rbp)
cmpq $0x0, -0x260(%rbp)
jne 0xb57df
leaq 0x11521(%rip), %rax     # 0xc6cf7
movq %rax, -0x38(%rbp)
jmp 0xb5944
movq -0x258(%rbp), %rdi
leaq -0x310(%rbp), %r8
leaq -0x380(%rbp), %r9
leaq -0x390(%rbp), %rsi
leaq -0x394(%rbp), %rdx
leaq -0x398(%rbp), %rcx
callq 0xaf5a0
movq -0x260(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x3ac(%rbp)
leaq -0x2a0(%rbp), %rax
movq %rax, -0x3a8(%rbp)
movq -0x258(%rbp), %rdi
movq -0x250(%rbp), %rdx
movl $0x3a, %esi
callq 0xd5c0
movl -0x3ac(%rbp), %edi
movq -0x3a8(%rbp), %rsi
movq %rax, %rdx
movl $0x3, %ecx
movl $0x2, %eax
cmpq $0x0, %rdx
cmovel %eax, %ecx
movl $0x32, %edx
callq 0xaf9d0
leaq -0x240(%rbp), %rdi
addq -0x248(%rbp), %rdi
movl $0x1f4, %esi            # imm = 0x1F4
subq -0x248(%rbp), %rsi
movq -0x248(%rbp), %rdx
leaq 0x102b4(%rip), %rcx     # 0xc5b4b
leaq 0xa049(%rip), %rax      # 0xbf8e7
cmpq $0x0, %rdx
cmovaq %rax, %rcx
movl -0x398(%rbp), %edx
leaq 0x10298(%rip), %r8      # 0xc5b4b
leaq 0x11460(%rip), %rax     # 0xc6d1a
cmpl $0x0, %edx
cmovneq %rax, %r8
leaq -0x2a0(%rbp), %r9
movsbl -0x310(%rbp), %edx
leaq 0x10275(%rip), %rbx     # 0xc5b4b
leaq 0xa35a(%rip), %rax      # 0xbfc37
cmpl $0x0, %edx
cmovneq %rax, %rbx
leaq -0x310(%rbp), %r11
movsbl -0x380(%rbp), %edx
leaq 0x10252(%rip), %r10     # 0xc5b4b
leaq 0xa337(%rip), %rax      # 0xbfc37
cmpl $0x0, %edx
cmovneq %rax, %r10
leaq -0x380(%rbp), %rax
leaq 0x113f6(%rip), %rdx     # 0xc6d0b
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movb $0x0, %al
callq 0xd6e0
cltq
addq -0x248(%rbp), %rax
movq %rax, -0x248(%rbp)
jmp 0xb5781
movb $0x0, -0x4d(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rdi
callq 0xd2c0
leaq -0x240(%rbp), %rdi
callq 0xb5a80
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
jmp 0xb59f9
cmpl $0xd, -0x2c(%rbp)
jne 0xb5986
movq -0x40(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0xb59f7
cmpl $0x10, -0x2c(%rbp)
jne 0xb59f5
movq -0x28(%rbp), %rdi
callq 0xd940
movq %rax, -0x3a0(%rbp)
cmpq $0x0, %rax
jne 0xb59af
leaq 0x11378(%rip), %rax     # 0xc6d21
movq %rax, -0x38(%rbp)
jmp 0xb59f3
movq -0x3a0(%rbp), %rax
movl 0x14(%rax), %edi
callq 0xdea0
cmpl $0x0, %eax
je 0xb59d0
leaq 0x11364(%rip), %rax     # 0xc6d2e
movq %rax, -0x38(%rbp)
jmp 0xb59f1
movq -0x3a0(%rbp), %rax
movl 0x10(%rax), %edi
callq 0xde50
cmpl $0x0, %eax
je 0xb59ef
leaq 0x11353(%rip), %rax     # 0xc6d3e
movq %rax, -0x38(%rbp)
jmp 0xb59f1
jmp 0xb59f3
jmp 0xb59f5
jmp 0xb59f7
jmp 0xb59f9
movq -0x38(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x3c8, %rsp            # imm = 0x3C8
popq %rbx
popq %rbp
retq
nop