// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_assemble_uri
int mg_assemble_uri(const struct mg_str *scheme, const struct mg_str *user_info,
                    const struct mg_str *host, unsigned int port,
                    const struct mg_str *path, const struct mg_str *query,
                    const struct mg_str *fragment, int normalize_path,
                    struct mg_str *uri) {
  int result = -1;
  struct mbuf out;
  mbuf_init(&out, 0);

  if (scheme != NULL && scheme->len > 0) {
    mbuf_append(&out, scheme->p, scheme->len);
    mbuf_append(&out, "://", 3);
  }

  if (user_info != NULL && user_info->len > 0) {
    mbuf_append(&out, user_info->p, user_info->len);
    mbuf_append(&out, "@", 1);
  }

  if (host != NULL && host->len > 0) {
    mbuf_append(&out, host->p, host->len);
  }

  if (port != 0) {
    char port_str[20];
    int port_str_len = sprintf(port_str, ":%u", port);
    mbuf_append(&out, port_str, port_str_len);
  }

  if (path != NULL && path->len > 0) {
    if (normalize_path) {
      struct mg_str npath = mg_strdup(*path);
      if (npath.len != path->len) goto out;
      if (!mg_normalize_uri_path(path, &npath)) {
        free((void *) npath.p);
        goto out;
      }
      mbuf_append(&out, npath.p, npath.len);
      free((void *) npath.p);
    } else {
      mbuf_append(&out, path->p, path->len);
    }
  } else if (normalize_path) {
    mbuf_append(&out, "/", 1);
  }

  if (query != NULL && query->len > 0) {
    mbuf_append(&out, "?", 1);
    mbuf_append(&out, query->p, query->len);
  }

  if (fragment != NULL && fragment->len > 0) {
    mbuf_append(&out, "#", 1);
    mbuf_append(&out, fragment->p, fragment->len);
  }

  result = 0;

out:
  if (result == 0) {
    uri->p = out.buf;
    uri->len = out.len;
  } else {
    mbuf_free(&out);
    uri->p = NULL;
    uri->len = 0;
  }
  return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %rbx
movq %r8, %r14
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r13
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x68dd
testq %r13, %r13
je 0xb29f
movq 0x8(%r13), %rdx
testq %rdx, %rdx
je 0xb29f
movq (%r13), %rsi
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x6ae7
leaq 0xb043(%rip), %rsi      # 0x162d5
movl $0x3, %edx
movq %r13, %rdi
callq 0x6ae7
testq %r12, %r12
je 0xb2d3
movq 0x8(%r12), %rdx
testq %rdx, %rdx
je 0xb2d3
movq (%r12), %rsi
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x6ae7
leaq 0xa748(%rip), %rsi      # 0x15a0e
movl $0x1, %edx
movq %r12, %rdi
callq 0x6ae7
testq %r15, %r15
je 0xb2ee
movq 0x8(%r15), %rdx
testq %rdx, %rdx
je 0xb2ee
movq (%r15), %rsi
leaq 0x8(%rsp), %rdi
callq 0x6ae7
testl %ebp, %ebp
je 0xb31a
leaq 0xaca4(%rip), %rsi      # 0x15f9d
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x35a0
movslq %eax, %rdx
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x6ae7
movq 0x80(%rsp), %r12
movl 0x78(%rsp), %eax
testq %r14, %r14
je 0xb38e
movq 0x8(%r14), %rdx
testq %rdx, %rdx
je 0xb38e
testl %eax, %eax
je 0xb3a5
movq (%r14), %rdi
movq %rdx, %rsi
callq 0x6c14
movq %rax, 0x20(%rsp)
movq %rdx, 0x28(%rsp)
cmpq 0x8(%r14), %rdx
jne 0xb44b
leaq 0x20(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0xb0e1
movq (%r15), %r14
testl %eax, %eax
je 0xb443
movq 0x28(%rsp), %rdx
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x6ae7
movq %r14, %rdi
callq 0x3060
jmp 0xb3b2
testl %eax, %eax
je 0xb3b2
leaq 0xad7d(%rip), %rsi      # 0x16116
leaq 0x8(%rsp), %rdi
movl $0x1, %edx
jmp 0xb3ad
movq (%r14), %rsi
leaq 0x8(%rsp), %rdi
callq 0x6ae7
movq 0x70(%rsp), %r15
testq %rbx, %rbx
je 0xb3eb
cmpq $0x0, 0x8(%rbx)
je 0xb3eb
leaq 0xa646(%rip), %rsi      # 0x15a10
leaq 0x8(%rsp), %r14
movl $0x1, %edx
movq %r14, %rdi
callq 0x6ae7
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x6ae7
testq %r15, %r15
je 0xb41f
cmpq $0x0, 0x8(%r15)
je 0xb41f
leaq 0xbdba(%rip), %rsi      # 0x171b8
leaq 0x8(%rsp), %rbx
movl $0x1, %edx
movq %rbx, %rdi
callq 0x6ae7
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %rbx, %rdi
callq 0x6ae7
movq 0x8(%rsp), %rax
movq %rax, (%r12)
movq 0x10(%rsp), %rax
movq %rax, 0x8(%r12)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x3060
leaq 0x8(%rsp), %rdi
callq 0x6934
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xb434