// File: /workspace/github_c_makefile_star2_O1/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 $0x368, %rsp            # imm = 0x368
movq %rdx, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x6d8a5
testl %eax, %eax
js 0x6d83a
movl %eax, %r15d
movl %eax, %r13d
movq 0x38(%rbx,%r13,8), %r12
movq %r14, %rax
orq %r12, %rax
je 0x6d86c
testq %r14, %r14
sete %al
testq %r12, %r12
sete %cl
orb %al, %cl
jne 0x6d64d
movq %r14, %rdi
movq %r12, %rsi
callq 0xc950
testl %eax, %eax
je 0x6d86c
testq %r12, %r12
je 0x6d663
movq %r12, %rdi
callq 0xc250
movq $0x0, 0x38(%rbx,%r13,8)
testq %r14, %r14
je 0x6d86c
cmpb $0x0, (%r14)
je 0x6d86c
movq %r14, %rdi
callq 0x6d8fa
movq %rax, 0x38(%rbx,%r13,8)
cmpl $0xd, %r15d
je 0x6d868
cmpl $0x10, %r15d
je 0x6d843
cmpl $0xf, %r15d
jne 0x6d86c
leaq -0x390(%rbp), %rdi
movl $0x1f4, %edx            # imm = 0x1F4
xorl %esi, %esi
callq 0xc360
movq $0x0, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq %r13, -0x40(%rbp)
movq %r14, %rdi
leaq -0x60(%rbp), %rsi
xorl %edx, %edx
callq 0x6d92e
testq %rax, %rax
je 0x6d80c
movq %rax, %r14
movq -0x60(%rbp), %r13
movq %rbx, %rdi
movq %r13, %rsi
leaq -0x23a3(%rip), %rdx     # 0x6b350
xorl %ecx, %ecx
callq 0x68471
movq %rax, %r12
testq %rax, %rax
je 0x6d7f4
movq %r13, %rdi
leaq -0x70(%rbp), %rsi
leaq -0x4c(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
leaq -0x150(%rbp), %r8
leaq -0xe0(%rbp), %r9
callq 0x6860c
movq %rbx, %r15
movl 0x20(%r12), %ebx
movq -0x58(%rbp), %rdx
movq %r13, %rdi
movl $0x3a, %esi
callq 0xc4d0
cmpq $0x1, %rax
movl $0x3, %ecx
sbbl $0x0, %ecx
movl $0x32, %edx
movl %ebx, %edi
movq %r15, %rbx
leaq -0x190(%rbp), %r15
movq %r15, %rsi
callq 0x688ca
movl $0x1f4, %esi            # imm = 0x1F4
movq -0x48(%rbp), %r13
subq %r13, %rsi
testq %r13, %r13
leaq 0x61d3(%rip), %rcx      # 0x7394f
leaq 0xbee4(%rip), %rax      # 0x79667
cmoveq %rax, %rcx
cmpl $0x0, -0x2c(%rbp)
leaq 0xcca1(%rip), %r8       # 0x7a433
cmoveq %rax, %r8
cmpb $0x0, -0x150(%rbp)
leaq 0x64d1(%rip), %r11      # 0x73c75
movq %r11, %r10
cmoveq %rax, %r10
cmpb $0x0, -0xe0(%rbp)
leaq -0x390(%rbp,%r13), %rdi
cmoveq %rax, %r11
leaq 0xcc5f(%rip), %rdx      # 0x7a424
movq %r15, %r9
xorl %eax, %eax
leaq -0xe0(%rbp), %r15
pushq %r15
pushq %r11
leaq -0x150(%rbp), %r11
pushq %r11
pushq %r10
callq 0xc5d0
addq $0x20, %rsp
cltq
addq %rax, %r13
movq %r13, -0x48(%rbp)
jmp 0x6d7ff
leaq 0xcc15(%rip), %rax      # 0x7a410
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %r13
testq %r12, %r12
jne 0x6d6c8
movq %rbx, %r14
leaq -0x390(%rbp), %rbx
movb $0x0, 0x1f3(%rbx)
movq 0x38(%r14,%r13,8), %rdi
callq 0xc250
movq %rbx, %rdi
callq 0x6d8fa
movq %rax, 0x38(%r14,%r13,8)
movq -0x38(%rbp), %rcx
jmp 0x6d86e
leaq 0xcbc0(%rip), %rcx      # 0x7a401
jmp 0x6d86e
movq %r14, %rdi
callq 0xc7e0
testq %rax, %rax
je 0x6d883
movq %rax, %rbx
movl 0x14(%rax), %edi
callq 0xccd0
testl %eax, %eax
je 0x6d88c
leaq 0xcbe1(%rip), %rcx      # 0x7a447
jmp 0x6d86e
movq %rax, 0x8(%rbx)
xorl %ecx, %ecx
movq %rcx, %rax
addq $0x368, %rsp            # imm = 0x368
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xcbb0(%rip), %rcx      # 0x7a43a
jmp 0x6d86e
movl 0x10(%rbx), %edi
callq 0xcc90
xorl %ecx, %ecx
testl %eax, %eax
leaq 0xcbb8(%rip), %rax      # 0x7a457
cmovneq %rax, %rcx
jmp 0x6d86e