// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
leaq -0x50(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8610
cmpq $0x0, -0x8(%rbp)
je 0xff10
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jbe 0xff10
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
leaq -0x50(%rbp), %rdi
callq 0x89b0
leaq -0x50(%rbp), %rdi
leaq 0x10351(%rip), %rsi     # 0x20257
movl $0x3, %edx
callq 0x89b0
cmpq $0x0, -0x10(%rbp)
je 0xff4f
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jbe 0xff4f
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq -0x50(%rbp), %rdi
callq 0x89b0
leaq -0x50(%rbp), %rdi
leaq 0xfa48(%rip), %rsi      # 0x1f98d
movl $0x1, %edx
callq 0x89b0
cmpq $0x0, -0x18(%rbp)
je 0xff79
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jbe 0xff79
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
leaq -0x50(%rbp), %rdi
callq 0x89b0
cmpl $0x0, -0x1c(%rbp)
je 0xffa8
leaq -0x70(%rbp), %rdi
movl -0x1c(%rbp), %edx
leaq 0xff8f(%rip), %rsi      # 0x1ff1c
movb $0x0, %al
callq 0x35e0
movl %eax, -0x74(%rbp)
leaq -0x70(%rbp), %rsi
movslq -0x74(%rbp), %rdx
leaq -0x50(%rbp), %rdi
callq 0x89b0
cmpq $0x0, -0x28(%rbp)
je 0x10058
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jbe 0x10058
cmpl $0x0, 0x18(%rbp)
je 0x1003e
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rsi
callq 0x8c90
movq %rax, -0x88(%rbp)
movq %rdx, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0xfff6
jmp 0x100fa
movq -0x28(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0xfcd0
cmpl $0x0, %eax
jne 0x1001c
movq -0x88(%rbp), %rdi
callq 0x3050
jmp 0x100fa
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
leaq -0x50(%rbp), %rdi
callq 0x89b0
movq -0x88(%rbp), %rdi
callq 0x3050
jmp 0x10056
movq -0x28(%rbp), %rax
movq (%rax), %rsi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdx
leaq -0x50(%rbp), %rdi
callq 0x89b0
jmp 0x10075
cmpl $0x0, 0x18(%rbp)
je 0x10073
leaq -0x50(%rbp), %rdi
leaq 0x1002f(%rip), %rsi     # 0x20098
movl $0x1, %edx
callq 0x89b0
jmp 0x10075
cmpq $0x0, -0x30(%rbp)
je 0x100b4
movq -0x30(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jbe 0x100b4
leaq -0x50(%rbp), %rdi
leaq 0xf8fd(%rip), %rsi      # 0x1f98f
movl $0x1, %edx
callq 0x89b0
movq -0x30(%rbp), %rax
movq (%rax), %rsi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdx
leaq -0x50(%rbp), %rdi
callq 0x89b0
cmpq $0x0, 0x10(%rbp)
je 0x100f3
movq 0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jbe 0x100f3
leaq -0x50(%rbp), %rdi
leaq 0x110b1(%rip), %rsi     # 0x21182
movl $0x1, %edx
callq 0x89b0
movq 0x10(%rbp), %rax
movq (%rax), %rsi
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq -0x50(%rbp), %rdi
callq 0x89b0
movl $0x0, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x10119
movq -0x50(%rbp), %rcx
movq 0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rcx
movq 0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x10139
leaq -0x50(%rbp), %rdi
callq 0x86e0
movq 0x20(%rbp), %rax
movq $0x0, (%rax)
movq 0x20(%rbp), %rax
movq $0x0, 0x8(%rax)
movl -0x34(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)