// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
movq %rdx, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x5c87f
testl %eax, %eax
js 0x5c636
movl %eax, %r15d
movl %eax, %r13d
movq 0x38(%rbx,%r13,8), %r12
movq %r14, %rax
orq %r12, %rax
je 0x5c80b
testq %r14, %r14
sete %al
testq %r12, %r12
sete %cl
orb %al, %cl
je 0x5c642
testq %r12, %r12
jne 0x5c655
jmp 0x5c663
leaq 0xbda4(%rip), %rcx      # 0x683e1
jmp 0x5c80d
movq %r14, %rdi
movq %r12, %rsi
callq 0xc970
testl %eax, %eax
je 0x5c80b
movq %r12, %rdi
callq 0xc250
andq $0x0, 0x38(%rbx,%r13,8)
testq %r14, %r14
je 0x5c80b
cmpb $0x0, (%r14)
je 0x5c80b
movq %r14, %rdi
callq 0x5c8c6
movq %rax, 0x38(%rbx,%r13,8)
cmpl $0xd, %r15d
je 0x5c807
cmpl $0x10, %r15d
je 0x5c7e2
cmpl $0xf, %r15d
jne 0x5c80b
leaq -0x380(%rbp), %rdi
movq $0x0, -0x38(%rbp)
movl $0x1f4, %edx            # imm = 0x1F4
xorl %esi, %esi
callq 0xc370
xorl %r15d, %r15d
movq %r13, -0x40(%rbp)
movq %r14, %rdi
leaq -0x58(%rbp), %rsi
xorl %edx, %edx
callq 0x5c8fa
testq %rax, %rax
je 0x5c831
movq %rax, %r14
movq %rbx, %rdi
movq -0x58(%rbp), %r12
movq %r12, %rsi
leaq -0x2053(%rip), %rdx     # 0x5a69b
xorl %ecx, %ecx
callq 0x57bb5
testq %rax, %rax
je 0x5c822
movq %rax, %r13
movq %r12, %rdi
leaq -0x68(%rbp), %rsi
leaq -0x44(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
leaq -0x140(%rbp), %r8
leaq -0xd0(%rbp), %r9
callq 0x57d03
movl 0x20(%r13), %r13d
movq -0x50(%rbp), %rdx
movq %r12, %rdi
pushq $0x3a
popq %rsi
callq 0xc4d0
cmpq $0x1, %rax
pushq $0x3
popq %rcx
sbbl $0x0, %ecx
movl %r13d, %edi
leaq -0x180(%rbp), %r12
movq %r12, %rsi
pushq $0x32
popq %rdx
callq 0x57f64
movl $0x1f4, %esi            # imm = 0x1F4
subq %r15, %rsi
testq %r15, %r15
leaq 0x51b8(%rip), %rcx      # 0x6191f
leaq 0xaee4(%rip), %rax      # 0x67652
cmoveq %rax, %rcx
cmpl $0x0, -0x2c(%rbp)
leaq 0xbc96(%rip), %r8       # 0x68413
cmoveq %rax, %r8
cmpb $0x0, -0x140(%rbp)
leaq 0x54dd(%rip), %r11      # 0x61c6c
movq %r11, %r10
cmoveq %rax, %r10
cmpb $0x0, -0xd0(%rbp)
leaq -0x380(%rbp,%r15), %rdi
cmoveq %rax, %r11
leaq 0xbc54(%rip), %rdx      # 0x68404
movq %r12, %r9
xorl %eax, %eax
leaq -0xd0(%rbp), %r12
pushq %r12
pushq %r11
leaq -0x140(%rbp), %r11
pushq %r11
pushq %r10
callq 0xc5e0
addq $0x20, %rsp
cltq
addq %rax, %r15
movq -0x40(%rbp), %r13
jmp 0x5c6c3
movq %r14, %rdi
callq 0xc810
testq %rax, %rax
je 0x5c85d
movq %rax, %rbx
movl 0x14(%rax), %edi
callq 0xcd00
testl %eax, %eax
je 0x5c866
leaq 0xbc22(%rip), %rcx      # 0x68427
jmp 0x5c80d
movq %rax, 0x8(%rbx)
xorl %ecx, %ecx
movq %rcx, %rax
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbbc7(%rip), %rax      # 0x683f0
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %r13
leaq -0x380(%rbp), %r14
movb $0x0, 0x1f3(%r14)
movq 0x38(%rbx,%r13,8), %rdi
callq 0xc250
movq %r14, %rdi
callq 0x5c8c6
movq %rax, 0x38(%rbx,%r13,8)
movq -0x38(%rbp), %rcx
jmp 0x5c80d
leaq 0xbbb6(%rip), %rcx      # 0x6841a
jmp 0x5c80d
movl 0x10(%rbx), %edi
callq 0xccc0
xorl %ecx, %ecx
testl %eax, %eax
leaq 0xbbbe(%rip), %rax      # 0x68437
cmovneq %rax, %rcx
jmp 0x5c80d