// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x6bd18
testl %eax, %eax
js 0x6bab5
movl %eax, %r14d
movl %eax, %r13d
movq 0x38(%rbx,%r13,8), %r12
movq %r15, %rax
orq %r12, %rax
je 0x6bca6
testq %r15, %r15
sete %al
testq %r12, %r12
sete %cl
orb %al, %cl
je 0x6bac1
testq %r12, %r12
jne 0x6bad4
jmp 0x6bae5
leaq 0xc945(%rip), %r14      # 0x78401
jmp 0x6bca9
movq %r15, %rdi
movq %r12, %rsi
callq 0xc950
testl %eax, %eax
je 0x6bca6
movq %r12, %rdi
callq 0xc250
movq $0x0, 0x38(%rbx,%r13,8)
testq %r15, %r15
je 0x6bca6
cmpb $0x0, (%r15)
je 0x6bca6
movq %r15, %rdi
callq 0x6bd6d
movq %rax, 0x38(%rbx,%r13,8)
cmpl $0xd, %r14d
je 0x6bca2
cmpl $0x10, %r14d
je 0x6bc7d
cmpl $0xf, %r14d
jne 0x6bca6
movq %rbx, -0x38(%rbp)
movq %r13, -0x40(%rbp)
leaq -0x380(%rbp), %rdi
xorl %r14d, %r14d
movl $0x1f4, %edx            # imm = 0x1F4
xorl %esi, %esi
callq 0xc360
leaq -0x50(%rbp), %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x6bda1
testq %rax, %rax
je 0x6bcce
xorl %r14d, %r14d
xorl %r15d, %r15d
movq %rax, %rbx
movq -0x50(%rbp), %r12
movq -0x38(%rbp), %rdi
movq %r12, %rsi
leaq -0x240b(%rip), %rdx     # 0x69768
xorl %ecx, %ecx
callq 0x668c9
testq %rax, %rax
je 0x6bcc7
movq %rax, %r13
movq %r12, %rdi
leaq -0x64(%rbp), %rsi
leaq -0x54(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
leaq -0x140(%rbp), %r8
leaq -0xd0(%rbp), %r9
callq 0x66a3e
movl 0x20(%r13), %r13d
movq -0x48(%rbp), %rdx
movq %r12, %rdi
movl $0x3a, %esi
callq 0xc4d0
cmpq $0x1, %rax
movl $0x3, %ecx
sbbl $0x0, %ecx
movl $0x32, %edx
movl %r13d, %edi
leaq -0x180(%rbp), %r12
movq %r12, %rsi
callq 0x66ce6
movl $0x1f4, %esi            # imm = 0x1F4
subq %r15, %rsi
testq %r15, %r15
leaq 0x5d5d(%rip), %rcx      # 0x7194f
leaq 0xba79(%rip), %rax      # 0x77672
cmoveq %rax, %rcx
cmpl $0x0, -0x2c(%rbp)
leaq 0xc82b(%rip), %r8       # 0x78433
cmoveq %rax, %r8
cmpb $0x0, -0x140(%rbp)
leaq 0x6058(%rip), %r11      # 0x71c72
movq %r11, %r10
cmoveq %rax, %r10
cmpb $0x0, -0xd0(%rbp)
leaq -0x380(%rbp,%r15), %rdi
cmoveq %rax, %r11
leaq 0xc7e9(%rip), %rdx      # 0x78424
movq %r12, %r9
xorl %eax, %eax
leaq -0xd0(%rbp), %r12
pushq %r12
pushq %r11
leaq -0x140(%rbp), %r11
pushq %r11
pushq %r10
callq 0xc5d0
addq $0x20, %rsp
cltq
addq %rax, %r15
movq %rbx, %rdi
leaq -0x50(%rbp), %rsi
xorl %edx, %edx
callq 0x6bda1
testq %rax, %rax
jne 0x6bb5e
jmp 0x6bcce
movq %r15, %rdi
callq 0xc7e0
testq %rax, %rax
je 0x6bcbe
movq %rax, %rbx
movl 0x14(%rax), %edi
callq 0xccd0
testl %eax, %eax
je 0x6bcfe
leaq 0xc7a7(%rip), %r14      # 0x78447
jmp 0x6bca9
movq %rax, 0x8(%rbx)
xorl %r14d, %r14d
movq %r14, %rax
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc775(%rip), %r14      # 0x7843a
jmp 0x6bca9
leaq 0xc742(%rip), %r14      # 0x78410
leaq -0x380(%rbp), %r15
movb $0x0, 0x1f3(%r15)
movq -0x40(%rbp), %r12
movq -0x38(%rbp), %rbx
movq 0x38(%rbx,%r12,8), %rdi
callq 0xc250
movq %r15, %rdi
callq 0x6bd6d
movq %rax, 0x38(%rbx,%r12,8)
jmp 0x6bca9
movl 0x10(%rbx), %edi
callq 0xcc90
xorl %r14d, %r14d
testl %eax, %eax
leaq 0xc745(%rip), %rax      # 0x78457
cmovneq %rax, %r14
jmp 0x6bca9