fuzz.c:_ZL9mock_initP11mg_tcpip_if:
    1|  6.10k|static bool mock_init(struct mg_tcpip_if *ifp) {
    2|  6.10k|  (void) ifp;
    3|  6.10k|  return true;
    4|  6.10k|}
fuzz.c:_ZL7mock_txPKvmP11mg_tcpip_if:
    6|  7.36k|static size_t mock_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
    7|  7.36k|  (void) buf, (void) len, (void) ifp;
    8|  7.36k|  return len;
    9|  7.36k|}
fuzz.c:_ZL7mock_rxPvmP11mg_tcpip_if:
   11|  6.10k|static size_t mock_rx(void *buf, size_t len, struct mg_tcpip_if *ifp) {
   12|  6.10k|  (void) buf, (void) len, (void) ifp;
   13|  6.10k|  return 0;
   14|  6.10k|}
fuzz.c:_ZL9mock_pollP11mg_tcpip_ifb:
   16|  6.10k|static bool mock_poll(struct mg_tcpip_if *ifp, bool s1) {
   17|  6.10k|  (void) ifp;
   18|  6.10k|  return s1;
   19|  6.10k|}

LLVMFuzzerTestOneInput:
   72|  6.10k|int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
   73|  6.10k|  mg_log_set(MG_LL_INFO);
  ------------------
  |  | 1757|  6.10k|#define mg_log_set(level_) mg_log_level = (level_)
  ------------------
   74|       |
   75|  6.10k|  struct mg_dns_message dm;
   76|  6.10k|  mg_dns_parse(data, size, &dm);
   77|  6.10k|  mg_dns_parse(NULL, 0, &dm);
   78|       |
   79|  6.10k|  struct mg_http_message hm;
   80|  6.10k|  if (mg_http_parse((const char *) data, size, &hm) > 0) {
  ------------------
  |  Branch (80:7): [True: 2.23k, False: 3.86k]
  ------------------
   81|  2.23k|    mg_crc32(0, hm.method.buf, hm.method.len);
   82|  2.23k|    mg_crc32(0, hm.uri.buf, hm.uri.len);
   83|  2.23k|    mg_crc32(0, hm.uri.buf, hm.uri.len);
   84|  69.3k|    for (size_t i = 0; i < sizeof(hm.headers) / sizeof(hm.headers[0]); i++) {
  ------------------
  |  Branch (84:24): [True: 67.1k, False: 2.23k]
  ------------------
   85|  67.1k|      struct mg_str *k = &hm.headers[i].name, *v = &hm.headers[i].value;
   86|  67.1k|      mg_crc32(0, k->buf, k->len);
   87|  67.1k|      mg_crc32(0, v->buf, v->len);
   88|  67.1k|    }
   89|  2.23k|  }
   90|  6.10k|  mg_http_parse(NULL, 0, &hm);
   91|       |
   92|  6.10k|  struct mg_str body = mg_str_n((const char *) data, size);
   93|  6.10k|  char tmp[256];
   94|  6.10k|  mg_http_get_var(&body, "key", tmp, sizeof(tmp));
   95|  6.10k|  mg_http_get_var(&body, "key", NULL, 0);
   96|  6.10k|  mg_url_decode((char *) data, size, tmp, sizeof(tmp), 1);
   97|  6.10k|  mg_url_decode((char *) data, size, tmp, 1, 1);
   98|  6.10k|  mg_url_decode(NULL, 0, tmp, 1, 1);
   99|       |
  100|  6.10k|  struct mg_mqtt_message mm;
  101|  6.10k|  if (mg_mqtt_parse(data, size, 0, &mm) == MQTT_OK) {
  ------------------
  |  Branch (101:7): [True: 2.38k, False: 3.71k]
  ------------------
  102|  2.38k|    mg_crc32(0, mm.topic.buf, mm.topic.len);
  103|  2.38k|    mg_crc32(0, mm.data.buf, mm.data.len);
  104|  2.38k|    mg_crc32(0, mm.dgram.buf, mm.dgram.len);
  105|  2.38k|  }
  106|  6.10k|  mg_mqtt_parse(NULL, 0, 0, &mm);
  107|  6.10k|  if (mg_mqtt_parse(data, size, 5, &mm) == MQTT_OK) {
  ------------------
  |  Branch (107:7): [True: 2.23k, False: 3.86k]
  ------------------
  108|  2.23k|    mg_crc32(0, mm.topic.buf, mm.topic.len);
  109|  2.23k|    mg_crc32(0, mm.data.buf, mm.data.len);
  110|  2.23k|    mg_crc32(0, mm.dgram.buf, mm.dgram.len);
  111|  2.23k|    {
  112|  2.23k|      struct mg_mqtt_prop prop;
  113|  2.23k|      size_t ofs = 0;
  114|  9.84k|      while ((ofs = mg_mqtt_next_prop(&mm, &prop, ofs)) > 0) {
  ------------------
  |  Branch (114:14): [True: 7.60k, False: 2.23k]
  ------------------
  115|  7.60k|          mg_crc32(0, prop.key.buf, prop.key.len);
  116|  7.60k|          mg_crc32(0, prop.val.buf, prop.val.len);
  117|  7.60k|      }
  118|  2.23k|    }
  119|  2.23k|  }
  120|  6.10k|  mg_mqtt_parse(NULL, 0, 5, &mm);
  121|       |
  122|  6.10k|  mg_sntp_parse(data, size);
  123|  6.10k|  mg_sntp_parse(NULL, 0);
  124|       |
  125|  6.10k|  char buf[size * 4 / 3 + 5];  // At least 4 chars and nul termination
  126|  6.10k|  mg_base64_decode((char *) data, size, buf, sizeof(buf));
  127|  6.10k|  mg_base64_decode(NULL, 0, buf, sizeof(buf));
  128|  6.10k|  mg_base64_encode(data, size, buf, sizeof(buf));
  129|  6.10k|  mg_base64_encode(NULL, 0, buf, sizeof(buf));
  130|       |
  131|  6.10k|  mg_match(mg_str_n((char *) data, size), mg_str_n((char *) data, size), NULL);
  132|       |
  133|  6.10k|  struct mg_str entry, s = mg_str_n((char *) data, size);
  134|  1.19M|  while (mg_span(s, &entry, &s, ',')) entry.len = 0;
  ------------------
  |  Branch (134:10): [True: 1.19M, False: 6.10k]
  ------------------
  135|       |
  136|  6.10k|  int n;
  137|  6.10k|  mg_json_get(mg_str_n((char *) data, size), "$", &n);
  138|  6.10k|  mg_json_get(mg_str_n((char *) data, size), "$.a.b", &n);
  139|  6.10k|  mg_json_get(mg_str_n((char *) data, size), "$[0]", &n);
  140|       |
  141|       |  // Test built-in TCP/IP stack
  142|  6.10k|  if (size > 0) {
  ------------------
  |  Branch (142:7): [True: 6.10k, False: 0]
  ------------------
  143|  6.10k|    static size_t t;
  144|  6.10k|    struct mg_tcpip_if mif = {.ip = 1,
  145|  6.10k|                              .mask = 255,
  146|  6.10k|                              .gw = 1,
  147|  6.10k|                              .gw_ready = true,
  148|  6.10k|                              .state = MG_TCPIP_STATE_READY,
  ------------------
  |  | 4866|  6.10k|#define MG_TCPIP_STATE_READY 5      // Fully operational; gateway MAC resolved
  ------------------
  149|       |#if MG_ENABLE_IPV6
  150|       |                              .ip6[0] = 1,
  151|       |                              .prefix[0] = 1,
  152|       |                              .prefix_len = 64,
  153|       |                              .gw6[0] = 1,
  154|       |                              .gw6_ready = true,
  155|       |                              .state6 = MG_TCPIP_STATE_READY,  // so mg_send() works and RS stops
  156|       |#endif
  157|  6.10k|                              .driver = &mg_tcpip_driver_mock};
  158|  6.10k|    struct mg_mgr mgr;
  159|       |
  160|  6.10k|    if (t >= MG_TCPIP_L2_USER) t = 0; // defined in l2.h
  ------------------
  |  Branch (160:9): [True: 2.03k, False: 4.06k]
  ------------------
  161|  6.10k|    mif.l2type = (enum mg_l2type) t++; // configure to a L2 type
  162|       |
  163|  6.10k|    mg_mgr_init(&mgr);
  164|  6.10k|    mg_tcpip_init(&mgr, &mif);
  165|       |
  166|       |    // Make a copy of the random data, in order to modify it
  167|  6.10k|    void *pkt = malloc(size);
  168|  6.10k|    struct eth *eth = (struct eth *) pkt;
  169|  6.10k|    memcpy(pkt, data, size);
  170|  6.10k|    if ((mif.l2type == MG_TCPIP_L2_ETH || mif.l2type == MG_TCPIP_L2_PPPoE) && size > sizeof(*eth)) {
  ------------------
  |  Branch (170:10): [True: 2.03k, False: 4.06k]
  |  Branch (170:43): [True: 2.03k, False: 2.03k]
  |  Branch (170:79): [True: 2.83k, False: 1.23k]
  ------------------
  171|  2.83k|      static size_t i, v;
  172|  2.83k|      static struct fuzz_l3_state l3;
  173|  2.83k|      uint8_t *ethpay = (uint8_t *) (eth + 1);
  174|  2.83k|      size_t ethhdrsz = sizeof(*eth);
  175|  2.83k|      uint16_t etype;
  176|       |      // eth_types[] exists in l2_eth.c
  177|  2.83k|      memcpy(eth->dst, mif.mac, 6);  // Set valid destination MAC
  178|       |      // send all handled eth types, then 2 random ones
  179|  2.83k|      if (i >= (sizeof(eth_types) / sizeof(eth_types[0]) + 2)) i = 0;
  ------------------
  |  Branch (179:11): [True: 0, False: 2.83k]
  ------------------
  180|  2.83k|      if (i < (sizeof(eth_types) / sizeof(eth_types[0]))) eth->type = mg_htons(eth_types[i++]);
  ------------------
  |  | 2093|      5|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (180:11): [True: 5, False: 2.82k]
  ------------------
  181|  2.83k|      etype = mg_ntohs(eth->type);
  182|  2.83k|      if (v >= 10) v = 0; // 802.1Q tag 3 out of 10 frames
  ------------------
  |  Branch (182:11): [True: 283, False: 2.54k]
  ------------------
  183|  2.83k|      if (v < 3) mif.l2data.eth.vlan_id = 123;
  ------------------
  |  Branch (183:11): [True: 851, False: 1.98k]
  ------------------
  184|  2.83k|      if (size > sizeof(*eth) + sizeof(struct qtag)) {
  ------------------
  |  Branch (184:11): [True: 2.55k, False: 276]
  ------------------
  185|  2.55k|        struct qtag *qtag = (struct qtag *) &eth->type;
  186|  2.55k|        if (v == 0) {
  ------------------
  |  Branch (186:13): [True: 256, False: 2.30k]
  ------------------
  187|       |          // v=0: configured for VLAN 123, untagged frame, discard path
  188|  2.30k|        } else if (v == 1) {
  ------------------
  |  Branch (188:20): [True: 256, False: 2.04k]
  ------------------
  189|       |          // v=1: configured for VLAN 123, tagged VLAN 123, accept path
  190|    256|          qtag->tpid = mg_htons(0x8100);
  ------------------
  |  | 2093|    256|#define mg_htons(x) mg_ntohs(x)
  ------------------
  191|    256|          qtag->tci = mg_htons(123);
  ------------------
  |  | 2093|    256|#define mg_htons(x) mg_ntohs(x)
  ------------------
  192|    256|          MG_STORE_BE16(qtag + 1, etype);
  ------------------
  |  | 2039|    256|  do {                                    \
  |  | 2040|    256|    MG_U8P(p)[0] = (uint8_t) ((n) >> 8U); \
  |  |  ------------------
  |  |  |  | 2012|    256|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  | 2041|    256|    MG_U8P(p)[1] = (uint8_t) (n);         \
  |  |  ------------------
  |  |  |  | 2012|    256|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  | 2042|    256|  } while (0)
  |  |  ------------------
  |  |  |  Branch (2042:12): [Folded, False: 256]
  |  |  ------------------
  ------------------
  193|    256|          ethhdrsz += sizeof(*qtag);
  194|    256|          ethpay += sizeof(*qtag);
  195|  2.04k|        } else if (v == 2) {
  ------------------
  |  Branch (195:20): [True: 255, False: 1.78k]
  ------------------
  196|       |          // v=2: configured for VLAN 123, tagged random VLAN, mismatch path
  197|    255|          qtag->tpid = mg_htons(0x8100);
  ------------------
  |  | 2093|    255|#define mg_htons(x) mg_ntohs(x)
  ------------------
  198|    255|          MG_STORE_BE16(qtag + 1, etype);
  ------------------
  |  | 2039|    255|  do {                                    \
  |  | 2040|    255|    MG_U8P(p)[0] = (uint8_t) ((n) >> 8U); \
  |  |  ------------------
  |  |  |  | 2012|    255|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  | 2041|    255|    MG_U8P(p)[1] = (uint8_t) (n);         \
  |  |  ------------------
  |  |  |  | 2012|    255|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  | 2042|    255|  } while (0)
  |  |  ------------------
  |  |  |  Branch (2042:12): [Folded, False: 255]
  |  |  ------------------
  ------------------
  199|    255|          ethhdrsz += sizeof(*qtag);
  200|    255|          ethpay += sizeof(*qtag);
  201|  1.78k|        } else if (v == 3) {
  ------------------
  |  Branch (201:20): [True: 255, False: 1.53k]
  ------------------
  202|       |          // v=3: unconfigured VLAN, tagged frame, discard path
  203|    255|          qtag->tpid = mg_htons(0x8100);
  ------------------
  |  | 2093|    255|#define mg_htons(x) mg_ntohs(x)
  ------------------
  204|    255|          MG_STORE_BE16(qtag + 1, etype);
  ------------------
  |  | 2039|    255|  do {                                    \
  |  | 2040|    255|    MG_U8P(p)[0] = (uint8_t) ((n) >> 8U); \
  |  |  ------------------
  |  |  |  | 2012|    255|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  | 2041|    255|    MG_U8P(p)[1] = (uint8_t) (n);         \
  |  |  ------------------
  |  |  |  | 2012|    255|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  | 2042|    255|  } while (0)
  |  |  ------------------
  |  |  |  Branch (2042:12): [Folded, False: 255]
  |  |  ------------------
  ------------------
  205|    255|          ethhdrsz += sizeof(*qtag);
  206|    255|          ethpay += sizeof(*qtag);
  207|    255|        } // else unconfigured VLAN, untagged frame, normal path
  208|  2.55k|      }
  209|  2.83k|      ++v;
  210|  2.83k|      if (etype == 0x8863 && size > (ethhdrsz + sizeof(struct pppoe))) { // PPPoE disc
  ------------------
  |  Branch (210:11): [True: 76, False: 2.75k]
  |  Branch (210:30): [True: 68, False: 8]
  ------------------
  211|     68|        static size_t j;
  212|     68|        uint8_t pppoe_codes[] = {MG_PPPoE_PADO, MG_PPPoE_PADS, MG_PPPoE_PADT}; // defined in l2_ppp.c
  ------------------
  |  | 6566|     68|#define MG_PPPoE_PADO 0x07
  ------------------
                      uint8_t pppoe_codes[] = {MG_PPPoE_PADO, MG_PPPoE_PADS, MG_PPPoE_PADT}; // defined in l2_ppp.c
  ------------------
  |  | 6568|     68|#define MG_PPPoE_PADS 0x65
  ------------------
                      uint8_t pppoe_codes[] = {MG_PPPoE_PADO, MG_PPPoE_PADS, MG_PPPoE_PADT}; // defined in l2_ppp.c
  ------------------
  |  | 6569|     68|#define MG_PPPoE_PADT 0xa7
  ------------------
  213|     68|        struct pppoe *pppoe = (struct pppoe *) ethpay;
  214|     68|        pppoe->vertype = 0x11;
  215|       |        // send all handled PPPoE codes, then 2 random ones
  216|     68|        if (j >= (sizeof(pppoe_codes) / sizeof(pppoe_codes[0]) + 2)) j = 0;
  ------------------
  |  Branch (216:13): [True: 0, False: 68]
  ------------------
  217|     68|        if (j < (sizeof(pppoe_codes) / sizeof(pppoe_codes[0]))) pppoe->code = (pppoe_codes[j++]);
  ------------------
  |  Branch (217:13): [True: 3, False: 65]
  ------------------
  218|     68|        if (pppoe->code == MG_PPPoE_PADO) {
  ------------------
  |  | 6566|     68|#define MG_PPPoE_PADO 0x07
  ------------------
  |  Branch (218:13): [True: 8, False: 60]
  ------------------
  219|      8|          static size_t k;
  220|       |          // send id=0, then 2 random ids
  221|      8|          if (k >= 3) k = 0;
  ------------------
  |  Branch (221:15): [True: 2, False: 6]
  ------------------
  222|      8|          if (k == 0) pppoe->id = 0;
  ------------------
  |  Branch (222:15): [True: 3, False: 5]
  ------------------
  223|      8|          ++k;
  224|     60|        } else if (pppoe->code == MG_PPPoE_PADS) {
  ------------------
  |  | 6568|     60|#define MG_PPPoE_PADS 0x65
  ------------------
  |  Branch (224:20): [True: 4, False: 56]
  ------------------
  225|      4|          static size_t k;
  226|       |          // send id=x, then 2 random ids
  227|      4|          if (k >= 3) k = 0;
  ------------------
  |  Branch (227:15): [True: 1, False: 3]
  ------------------
  228|      4|          if (k == 0) pppoe->id = 0x1234;
  ------------------
  |  Branch (228:15): [True: 2, False: 2]
  ------------------
  229|      4|          ++k;
  230|     56|        } else if (pppoe->code == MG_PPPoE_PADT) { // keep separate so they do not correlate too much
  ------------------
  |  | 6569|     56|#define MG_PPPoE_PADT 0xa7
  ------------------
  |  Branch (230:20): [True: 8, False: 48]
  ------------------
  231|      8|          static size_t k;
  232|       |          // send id=x, then 2 random ids
  233|      8|          if (k >= 3) k = 0;
  ------------------
  |  Branch (233:15): [True: 2, False: 6]
  ------------------
  234|      8|          if (k == 0) pppoe->id = 0x1234;
  ------------------
  |  Branch (234:15): [True: 3, False: 5]
  ------------------
  235|      8|          ++k;
  236|      8|        }
  237|  2.76k|      } else if (etype == 0x8864 && size > (ethhdrsz + sizeof(struct pppoe))) { // PPPoE sess
  ------------------
  |  Branch (237:18): [True: 43, False: 2.72k]
  |  Branch (237:37): [True: 42, False: 1]
  ------------------
  238|       |        // PPP rx is covered via HDLC too; PPPoE tx wrapping may remain unexercised.
  239|     42|        struct pppoe *pppoe = (struct pppoe *) ethpay;
  240|     42|        static size_t k, l;
  241|       |        // send code=0, then 2 random codes
  242|     42|        if (k >= 3) k = 0;
  ------------------
  |  Branch (242:13): [True: 13, False: 29]
  ------------------
  243|     42|        if (k == 0)  {
  ------------------
  |  Branch (243:13): [True: 14, False: 28]
  ------------------
  244|     14|          static size_t m;
  245|     14|          pppoe->code = 0;
  246|       |          // send id=x, then 2 random ids
  247|     14|          if (m >= 3) m = 0;
  ------------------
  |  Branch (247:15): [True: 4, False: 10]
  ------------------
  248|     14|          if (m == 0) pppoe->id = 0x1234;
  ------------------
  |  Branch (248:15): [True: 5, False: 9]
  ------------------
  249|     14|          ++m;
  250|     14|        }
  251|     42|        ++k;
  252|       |        // set s_state to valid and invalid
  253|     42|        if (l >= 2) l = 0;
  ------------------
  |  Branch (253:13): [True: 20, False: 22]
  ------------------
  254|     42|        if (l == 0) s_state = MG_PPPoE_ST_SESS; // defined in l2_ppp.c
  ------------------
  |  | 6573|     21|#define MG_PPPoE_ST_SESS 2  // Session established, PPP traffic is exchanged
  ------------------
  |  Branch (254:13): [True: 21, False: 21]
  ------------------
  255|     42|        if (l == 1) s_state = MG_PPPoE_ST_REQ;
  ------------------
  |  | 6572|     21|#define MG_PPPoE_ST_REQ 1   // Chose a server, request a session and wait
  ------------------
  |  Branch (255:13): [True: 21, False: 21]
  ------------------
  256|     42|        ++l;
  257|       |        // PPP exercised in other block
  258|     42|      }
  259|       |      // build proper layer-3 datagrams, to be able to exercise layers above
  260|  2.72k|      else if (etype == 0x800 && size > (ethhdrsz + sizeof(struct ip))) {         // IPv4
  ------------------
  |  Branch (260:16): [True: 120, False: 2.60k]
  |  Branch (260:34): [True: 112, False: 8]
  ------------------
  261|    112|        fuzz_ip4(ethpay, size - ethhdrsz, &l3);
  262|  2.61k|      } else if (etype == 0x806) {      // ARP
  ------------------
  |  Branch (262:18): [True: 59, False: 2.55k]
  ------------------
  263|       |
  264|  2.55k|      } else if (etype == 0x86dd && size > (ethhdrsz + sizeof(struct ip6))) {     // IPv6
  ------------------
  |  Branch (264:18): [True: 27, False: 2.52k]
  |  Branch (264:37): [True: 23, False: 4]
  ------------------
  265|     23|        fuzz_ip6(ethpay, size - ethhdrsz, &l3);
  266|     23|      }
  267|  3.26k|    } else if (mif.l2type == MG_TCPIP_L2_PPP && size > (sizeof(struct hdlc_) + sizeof(struct ppp) + 2)) {
  ------------------
  |  Branch (267:16): [True: 2.03k, False: 1.23k]
  |  Branch (267:49): [True: 1.69k, False: 344]
  ------------------
  268|  1.69k|      static size_t i;
  269|  1.69k|      static struct fuzz_l3_state l3;
  270|  1.69k|      uint16_t ppp_protos[] = {
  271|  1.69k|          MG_PPP_PROTO_LCP, MG_PPP_PROTO_IPCP, MG_PPP_PROTO_IP, MG_PPP_PROTO_IPV6CP, MG_PPP_PROTO_IPV6
  ------------------
  |  | 6537|  1.69k|#define MG_PPP_PROTO_LCP 0xc021
  ------------------
                        MG_PPP_PROTO_LCP, MG_PPP_PROTO_IPCP, MG_PPP_PROTO_IP, MG_PPP_PROTO_IPV6CP, MG_PPP_PROTO_IPV6
  ------------------
  |  | 6538|  1.69k|#define MG_PPP_PROTO_IPCP 0x8021
  ------------------
                        MG_PPP_PROTO_LCP, MG_PPP_PROTO_IPCP, MG_PPP_PROTO_IP, MG_PPP_PROTO_IPV6CP, MG_PPP_PROTO_IPV6
  ------------------
  |  | 6535|  1.69k|#define MG_PPP_PROTO_IP 0x0021
  ------------------
                        MG_PPP_PROTO_LCP, MG_PPP_PROTO_IPCP, MG_PPP_PROTO_IP, MG_PPP_PROTO_IPV6CP, MG_PPP_PROTO_IPV6
  ------------------
  |  | 6539|  1.69k|#define MG_PPP_PROTO_IPV6CP 0x8057
  ------------------
                        MG_PPP_PROTO_LCP, MG_PPP_PROTO_IPCP, MG_PPP_PROTO_IP, MG_PPP_PROTO_IPV6CP, MG_PPP_PROTO_IPV6
  ------------------
  |  | 6536|  1.69k|#define MG_PPP_PROTO_IPV6 0x0057
  ------------------
  272|  1.69k|      };
  273|  1.69k|      struct hdlc_ *hdlc = (struct hdlc_ *) pkt;
  274|  1.69k|      struct ppp *ppp = (struct ppp *) (hdlc + 1);
  275|  1.69k|      size_t len = size - sizeof(*hdlc) - sizeof(*ppp) - 2;
  276|  1.69k|      hdlc->addr = MG_PPP_ADDR;
  ------------------
  |  | 6532|  1.69k|#define MG_PPP_ADDR 0xff
  ------------------
  277|  1.69k|      hdlc->ctrl = MG_PPP_CTRL;
  ------------------
  |  | 6533|  1.69k|#define MG_PPP_CTRL 0x03
  ------------------
  278|  1.69k|      s_lcpup = true;
  279|       |      // send all handled PPP protocols, then 2 random ones
  280|  1.69k|      if (i >= (sizeof(ppp_protos) / sizeof(ppp_protos[0]) + 2)) i = 0;
  ------------------
  |  Branch (280:11): [True: 0, False: 1.69k]
  ------------------
  281|  1.69k|      if (i < (sizeof(ppp_protos) / sizeof(ppp_protos[0]))) ppp->proto = mg_htons(ppp_protos[i++]);
  ------------------
  |  | 2093|      5|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (281:11): [True: 5, False: 1.68k]
  ------------------
  282|  1.69k|      if (ppp->proto == mg_htons(MG_PPP_PROTO_LCP) && len >= sizeof(struct lcp)) {
  ------------------
  |  | 2093|  3.38k|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (282:11): [True: 37, False: 1.65k]
  |  Branch (282:55): [True: 35, False: 2]
  ------------------
  283|     35|        static size_t j, k;
  284|     35|        uint8_t lcp_codes[] = {MG_PPP_LCP_CFG_REQ, MG_PPP_LCP_CFG_ACK, MG_PPP_LCP_CFG_TERM_REQ, MG_PPP_LCP_ECHO_REQ};
  ------------------
  |  | 6543|     35|#define MG_PPP_LCP_CFG_REQ 1
  ------------------
                      uint8_t lcp_codes[] = {MG_PPP_LCP_CFG_REQ, MG_PPP_LCP_CFG_ACK, MG_PPP_LCP_CFG_TERM_REQ, MG_PPP_LCP_ECHO_REQ};
  ------------------
  |  | 6544|     35|#define MG_PPP_LCP_CFG_ACK 2
  ------------------
                      uint8_t lcp_codes[] = {MG_PPP_LCP_CFG_REQ, MG_PPP_LCP_CFG_ACK, MG_PPP_LCP_CFG_TERM_REQ, MG_PPP_LCP_ECHO_REQ};
  ------------------
  |  | 6547|     35|#define MG_PPP_LCP_CFG_TERM_REQ 5
  ------------------
                      uint8_t lcp_codes[] = {MG_PPP_LCP_CFG_REQ, MG_PPP_LCP_CFG_ACK, MG_PPP_LCP_CFG_TERM_REQ, MG_PPP_LCP_ECHO_REQ};
  ------------------
  |  | 6550|     35|#define MG_PPP_LCP_ECHO_REQ 9
  ------------------
  285|     35|        struct lcp *lcp = (struct lcp *) (ppp + 1);
  286|       |        // send all handled LCP codes, then 2 random ones
  287|     35|        if (j >= (sizeof(lcp_codes) / sizeof(lcp_codes[0]) + 2)) j = 0;
  ------------------
  |  Branch (287:13): [True: 0, False: 35]
  ------------------
  288|     35|        if (j < (sizeof(lcp_codes) / sizeof(lcp_codes[0]))) lcp->code = lcp_codes[j++];
  ------------------
  |  Branch (288:13): [True: 4, False: 31]
  ------------------
  289|       |        // send valid length, then 2 random lengths
  290|     35|        if (k >= 3) k = 0;
  ------------------
  |  Branch (290:13): [True: 11, False: 24]
  ------------------
  291|     35|        if (k == 0) lcp->len = mg_htons((uint16_t) sizeof(*lcp));
  ------------------
  |  | 2093|     12|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (291:13): [True: 12, False: 23]
  ------------------
  292|     35|        ++k;
  293|  1.65k|      } else if (ppp->proto == mg_htons(MG_PPP_PROTO_IPCP) && len >= 10) {
  ------------------
  |  | 2093|  3.31k|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (293:18): [True: 41, False: 1.61k]
  |  Branch (293:63): [True: 35, False: 6]
  ------------------
  294|     35|        static size_t j, k, m;
  295|     35|        uint8_t ipcp_codes[] = {MG_PPP_IPCP_CFG_REQ, MG_PPP_IPCP_CFG_ACK, MG_PPP_IPCP_CFG_NACK, MG_PPP_IPCP_CFG_REJECT};
  ------------------
  |  | 6553|     35|#define MG_PPP_IPCP_CFG_REQ 1
  ------------------
                      uint8_t ipcp_codes[] = {MG_PPP_IPCP_CFG_REQ, MG_PPP_IPCP_CFG_ACK, MG_PPP_IPCP_CFG_NACK, MG_PPP_IPCP_CFG_REJECT};
  ------------------
  |  | 6554|     35|#define MG_PPP_IPCP_CFG_ACK 2
  ------------------
                      uint8_t ipcp_codes[] = {MG_PPP_IPCP_CFG_REQ, MG_PPP_IPCP_CFG_ACK, MG_PPP_IPCP_CFG_NACK, MG_PPP_IPCP_CFG_REJECT};
  ------------------
  |  | 6555|     35|#define MG_PPP_IPCP_CFG_NACK 3
  ------------------
                      uint8_t ipcp_codes[] = {MG_PPP_IPCP_CFG_REQ, MG_PPP_IPCP_CFG_ACK, MG_PPP_IPCP_CFG_NACK, MG_PPP_IPCP_CFG_REJECT};
  ------------------
  |  | 6556|     35|#define MG_PPP_IPCP_CFG_REJECT 4
  ------------------
  296|     35|        struct ipcp *ipcp = (struct ipcp *) (ppp + 1);
  297|     35|        uint8_t *opts = (uint8_t *) (ipcp + 1);
  298|       |        // send all handled IPCP codes, then 2 random ones
  299|     35|        if (j >= (sizeof(ipcp_codes) / sizeof(ipcp_codes[0]) + 2)) j = 0;
  ------------------
  |  Branch (299:13): [True: 0, False: 35]
  ------------------
  300|     35|        if (j < (sizeof(ipcp_codes) / sizeof(ipcp_codes[0]))) ipcp->code = ipcp_codes[j++];
  ------------------
  |  Branch (300:13): [True: 4, False: 31]
  ------------------
  301|       |        // send valid length, then 2 random lengths
  302|     35|        if (m >= 3) m = 0;
  ------------------
  |  Branch (302:13): [True: 11, False: 24]
  ------------------
  303|     35|        if (m == 0) ipcp->len = mg_htons(10);
  ------------------
  |  | 2093|     12|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (303:13): [True: 12, False: 23]
  ------------------
  304|     35|        ++m;
  305|       |        // send valid IPADDR option, then 2 random option types
  306|     35|        if (k >= 3) k = 0;
  ------------------
  |  Branch (306:13): [True: 11, False: 24]
  ------------------
  307|     35|        if (k == 0) {
  ------------------
  |  Branch (307:13): [True: 12, False: 23]
  ------------------
  308|     12|          static size_t l;
  309|     12|          opts[0] = MG_PPP_IPCP_OPT_IPADDR;
  ------------------
  |  | 6557|     12|#define MG_PPP_IPCP_OPT_IPADDR 3
  ------------------
  310|       |          // for valid option type, send valid length, then random length
  311|     12|          if (l >= 2) l = 0;
  ------------------
  |  Branch (311:15): [True: 5, False: 7]
  ------------------
  312|     12|          if (l == 0) opts[1] = 6;
  ------------------
  |  Branch (312:15): [True: 6, False: 6]
  ------------------
  313|     12|          ++l;
  314|     12|        }
  315|     35|        ++k;
  316|  1.62k|      } else if (ppp->proto == mg_htons(MG_PPP_PROTO_IP) && len >= sizeof(struct ip)) {
  ------------------
  |  | 2093|  3.24k|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (316:18): [True: 41, False: 1.57k]
  |  Branch (316:61): [True: 36, False: 5]
  ------------------
  317|     36|        fuzz_ip4(ppp + 1, len, &l3);
  318|  1.58k|      } else if (ppp->proto == mg_htons(MG_PPP_PROTO_IPV6CP) && len >= 14) {
  ------------------
  |  | 2093|  3.16k|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (318:18): [True: 13, False: 1.57k]
  |  Branch (318:65): [True: 10, False: 3]
  ------------------
  319|     10|        static size_t j, k, m;
  320|     10|        uint8_t ipv6cp_codes[] = {MG_PPP_IPV6CP_CFG_REQ, MG_PPP_IPV6CP_CFG_ACK, MG_PPP_IPV6CP_CFG_NACK, MG_PPP_IPV6CP_CFG_REJECT};
  ------------------
  |  | 6559|     10|#define MG_PPP_IPV6CP_CFG_REQ 1
  ------------------
                      uint8_t ipv6cp_codes[] = {MG_PPP_IPV6CP_CFG_REQ, MG_PPP_IPV6CP_CFG_ACK, MG_PPP_IPV6CP_CFG_NACK, MG_PPP_IPV6CP_CFG_REJECT};
  ------------------
  |  | 6560|     10|#define MG_PPP_IPV6CP_CFG_ACK 2
  ------------------
                      uint8_t ipv6cp_codes[] = {MG_PPP_IPV6CP_CFG_REQ, MG_PPP_IPV6CP_CFG_ACK, MG_PPP_IPV6CP_CFG_NACK, MG_PPP_IPV6CP_CFG_REJECT};
  ------------------
  |  | 6561|     10|#define MG_PPP_IPV6CP_CFG_NACK 3
  ------------------
                      uint8_t ipv6cp_codes[] = {MG_PPP_IPV6CP_CFG_REQ, MG_PPP_IPV6CP_CFG_ACK, MG_PPP_IPV6CP_CFG_NACK, MG_PPP_IPV6CP_CFG_REJECT};
  ------------------
  |  | 6562|     10|#define MG_PPP_IPV6CP_CFG_REJECT 4
  ------------------
  321|     10|        struct ipv6cp *ipv6cp = (struct ipv6cp *) (ppp + 1);
  322|     10|        uint8_t *opts = (uint8_t *) (ipv6cp + 1);
  323|       |        // send all handled IPV6CP codes, then 2 random ones
  324|     10|        if (j >= (sizeof(ipv6cp_codes) / sizeof(ipv6cp_codes[0]) + 2)) j = 0;
  ------------------
  |  Branch (324:13): [True: 0, False: 10]
  ------------------
  325|     10|        if (j < (sizeof(ipv6cp_codes) / sizeof(ipv6cp_codes[0]))) ipv6cp->code = ipv6cp_codes[j++];
  ------------------
  |  Branch (325:13): [True: 4, False: 6]
  ------------------
  326|       |        // send valid length, then 2 random lengths
  327|     10|        if (m >= 3) m = 0;
  ------------------
  |  Branch (327:13): [True: 3, False: 7]
  ------------------
  328|     10|        if (m == 0) ipv6cp->len = mg_htons(14);
  ------------------
  |  | 2093|      4|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (328:13): [True: 4, False: 6]
  ------------------
  329|     10|        ++m;
  330|       |        // send valid IFCID option, then 2 random option types
  331|     10|        if (k >= 3) k = 0;
  ------------------
  |  Branch (331:13): [True: 3, False: 7]
  ------------------
  332|     10|        if (k == 0) {
  ------------------
  |  Branch (332:13): [True: 4, False: 6]
  ------------------
  333|      4|          static size_t l;
  334|      4|          opts[0] = MG_PPP_IPV6CP_OPT_IFCID;
  ------------------
  |  | 6563|      4|#define MG_PPP_IPV6CP_OPT_IFCID 1
  ------------------
  335|       |          // for valid option type, send valid length, then random length
  336|      4|          if (l >= 2) l = 0;
  ------------------
  |  Branch (336:15): [True: 1, False: 3]
  ------------------
  337|      4|          if (l == 0) {
  ------------------
  |  Branch (337:15): [True: 2, False: 2]
  ------------------
  338|      2|            static size_t o;
  339|      2|            opts[1] = 10;
  340|       |            // for valid option length, send non-zero IFCID, then 2 random IFCIDs
  341|      2|            if (o >= 3) o = 0;
  ------------------
  |  Branch (341:17): [True: 0, False: 2]
  ------------------
  342|      2|            if (o == 0) opts[9] = 1;
  ------------------
  |  Branch (342:17): [True: 1, False: 1]
  ------------------
  343|      2|            ++o;
  344|      2|          }
  345|      4|          ++l;
  346|      4|        }
  347|     10|        ++k;
  348|  1.57k|      } else if (ppp->proto == mg_htons(MG_PPP_PROTO_IPV6) && len >= sizeof(struct ip6)) {
  ------------------
  |  | 2093|  3.14k|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (348:18): [True: 36, False: 1.53k]
  |  Branch (348:63): [True: 30, False: 6]
  ------------------
  349|     30|        fuzz_ip6(ppp + 1, len, &l3);
  350|     30|      }
  351|  1.69k|    }
  352|       |
  353|       |#if defined(MAIN)
  354|       |    printf("Sending to net_builtin:\n");
  355|       |    mg_hexdump(pkt, size);
  356|       |#endif
  357|  6.10k|    mg_tcpip_rx(&mif, pkt, size);
  358|       |
  359|       |    // prior actions may have had consequences on link state
  360|  6.10k|    mif.state = MG_TCPIP_STATE_READY;
  ------------------
  |  | 4866|  6.10k|#define MG_TCPIP_STATE_READY 5      // Fully operational; gateway MAC resolved
  ------------------
  361|       |    // Test HTTP serving (via our built-in TCP/IP stack)
  362|  6.10k|    const char *url = "http://localhost:12345"; // internally resolves
  363|       |    // creates a connection and sends SYN via the router, unless OOM
  364|  6.10k|    struct mg_connection *c = mg_http_connect(&mgr, url, fn, NULL);
  365|  6.10k|    mg_iobuf_add(&c->recv, 0, data, size);
  366|  6.10k|    c->pfn(c, MG_EV_READ, NULL); // manually invoke protocol event handler
  367|       |
  368|  6.10k|    free(pkt);
  369|  6.10k|    mg_mgr_free(&mgr);
  370|  6.10k|  }
  371|       |
  372|  6.10k|  return 0;
  373|  6.10k|}
fuzz.c:_ZL8fuzz_ip4PvmP13fuzz_l3_state:
   32|    148|static void fuzz_ip4(void *buf, size_t len, struct fuzz_l3_state *st) {
   33|    148|  if (len >= sizeof(struct ip)) {
  ------------------
  |  Branch (33:7): [True: 148, False: 0]
  ------------------
   34|    148|    uint8_t ip_protos[] = {1, 6, 17}; // ICMP, TCP, UDP
   35|    148|    struct ip *ip4 = (struct ip *) buf;
   36|    148|    ip4->ver = (uint8_t) ((ip4->ver & ~0xf0) | (4 << 4));
   37|       |    // send all handled IP protos, then 2 random ones
   38|    148|    if (st->ip_proto >= (sizeof(ip_protos) / sizeof(ip_protos[0]) + 2)) st->ip_proto = 0;
  ------------------
  |  Branch (38:9): [True: 0, False: 148]
  ------------------
   39|    148|    if (st->ip_proto < (sizeof(ip_protos) / sizeof(ip_protos[0]))) ip4->proto = ip_protos[st->ip_proto++];
  ------------------
  |  Branch (39:9): [True: 6, False: 142]
  ------------------
   40|    148|    if (ip4->proto == 1) { // ICMP
  ------------------
  |  Branch (40:9): [True: 24, False: 124]
  ------------------
   41|    124|    } else if (ip4->proto == 6) { // TCP
  ------------------
  |  Branch (41:16): [True: 2, False: 122]
  ------------------
   42|    122|    } else if (ip4->proto == 17 && len >= sizeof(struct ip) + sizeof(struct udp)) { // UDP
  ------------------
  |  Branch (42:16): [True: 28, False: 94]
  |  Branch (42:36): [True: 25, False: 3]
  ------------------
   43|     25|      uint16_t udp_ports[] = {67, 68}; // DHCP server and client
   44|     25|      struct udp *udp = (struct udp *) (ip4 + 1);
   45|       |      // send all handled UDP ports, then 2 random ones
   46|     25|      if (st->udp_port >= (sizeof(udp_ports) / sizeof(udp_ports[0]) + 2)) st->udp_port = 0;
  ------------------
  |  Branch (46:11): [True: 0, False: 25]
  ------------------
   47|     25|      if (st->udp_port < (sizeof(udp_ports) / sizeof(udp_ports[0]))) udp->dport = mg_htons(udp_ports[st->udp_port++]);
  ------------------
  |  | 2093|      4|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (47:11): [True: 4, False: 21]
  ------------------
   48|     25|    }
   49|    148|  }
   50|    148|}
fuzz.c:_ZL8fuzz_ip6PvmP13fuzz_l3_state:
   52|     53|static void fuzz_ip6(void *buf, size_t len, struct fuzz_l3_state *st) {
   53|     53|  if (len >= sizeof(struct ip6)) {
  ------------------
  |  Branch (53:7): [True: 53, False: 0]
  ------------------
   54|     53|    uint8_t ip6_protos[] = {6, 17, 58}; // TCP, UDP, ICMPv6
   55|     53|    struct ip6 *ip6 = (struct ip6 *) buf;
   56|     53|    ip6->ver = (uint8_t) ((ip6->ver & ~0xf0) | (6 << 4));
   57|       |    // send all handled IPv6 "next headers", then 2 random ones
   58|     53|    if (st->ip6_next >= (sizeof(ip6_protos) / sizeof(ip6_protos[0]) + 2)) st->ip6_next = 0;
  ------------------
  |  Branch (58:9): [True: 0, False: 53]
  ------------------
   59|     53|    if (st->ip6_next < (sizeof(ip6_protos) / sizeof(ip6_protos[0]))) ip6->next = ip6_protos[st->ip6_next++];
  ------------------
  |  Branch (59:9): [True: 6, False: 47]
  ------------------
   60|     53|    if (ip6->next == 6) { // TCP
  ------------------
  |  Branch (60:9): [True: 2, False: 51]
  ------------------
   61|     51|    } else if (ip6->next == 17) { // UDP
  ------------------
  |  Branch (61:16): [True: 2, False: 49]
  ------------------
   62|     49|    } else if (ip6->next == 58 && len >= sizeof(struct ip6) + sizeof(struct icmp6)) { // ICMPv6
  ------------------
  |  Branch (62:16): [True: 22, False: 27]
  |  Branch (62:35): [True: 20, False: 2]
  ------------------
   63|     20|      uint8_t icmp6_types[] = {128, 134, 135, 136}; // Echo Request, RA, NS, NA
   64|     20|      struct icmp6 *icmp6 = (struct icmp6 *) (ip6 + 1);
   65|       |      // send all handled ICMPv6 types, then 2 random ones
   66|     20|      if (st->icmp6_type >= (sizeof(icmp6_types) / sizeof(icmp6_types[0]) + 2)) st->icmp6_type = 0;
  ------------------
  |  Branch (66:11): [True: 0, False: 20]
  ------------------
   67|     20|      if (st->icmp6_type < (sizeof(icmp6_types) / sizeof(icmp6_types[0]))) icmp6->type = icmp6_types[st->icmp6_type++];
  ------------------
  |  Branch (67:11): [True: 8, False: 12]
  ------------------
   68|     20|    }
   69|     53|  }
   70|     53|}
fuzz.c:_ZL2fnP13mg_connectioniPv:
   19|   603k|static void fn(struct mg_connection *c, int ev, void *ev_data) {
   20|   603k|  struct mg_http_serve_opts opts = {.root_dir = "."};
   21|   603k|  if (ev == MG_EV_HTTP_MSG) {
  ------------------
  |  Branch (21:7): [True: 285k, False: 318k]
  ------------------
   22|   285k|    mg_http_serve_dir(c, (struct mg_http_message *) ev_data, &opts);
   23|   285k|  }
   24|   603k|}

mg_base64_update:
   65|   217M|size_t mg_base64_update(unsigned char ch, char *to, size_t n) {
   66|   217M|  unsigned long rem = (n & 3) % 3;
   67|   217M|  if (rem == 0) {
  ------------------
  |  Branch (67:7): [True: 72.4M, False: 144M]
  ------------------
   68|  72.4M|    to[n] = (char) mg_base64_encode_single(ch >> 2);
   69|  72.4M|    to[++n] = (char) ((ch & 3) << 4);
   70|   144M|  } else if (rem == 1) {
  ------------------
  |  Branch (70:14): [True: 72.4M, False: 72.4M]
  ------------------
   71|  72.4M|    to[n] = (char) mg_base64_encode_single(to[n] | (ch >> 4));
   72|  72.4M|    to[++n] = (char) ((ch & 15) << 2);
   73|  72.4M|  } else {
   74|  72.4M|    to[n] = (char) mg_base64_encode_single(to[n] | (ch >> 6));
   75|  72.4M|    to[++n] = (char) mg_base64_encode_single(ch & 63);
   76|  72.4M|    n++;
   77|  72.4M|  }
   78|   217M|  return n;
   79|   217M|}
mg_base64_final:
   81|  12.2k|size_t mg_base64_final(char *to, size_t n) {
   82|  12.2k|  size_t saved = n;
   83|       |  // printf("---[%.*s]\n", n, to);
   84|  12.2k|  if (n & 3) n = mg_base64_update(0, to, n);
  ------------------
  |  Branch (84:7): [True: 4.06k, False: 8.13k]
  ------------------
   85|  12.2k|  if ((saved & 3) == 2) n--;
  ------------------
  |  Branch (85:7): [True: 1.94k, False: 10.2k]
  ------------------
   86|       |  // printf("    %d[%.*s]\n", n, n, to);
   87|  18.3k|  while (n & 3) to[n++] = '=';
  ------------------
  |  Branch (87:10): [True: 6.17k, False: 12.2k]
  ------------------
   88|  12.2k|  to[n] = '\0';
   89|  12.2k|  return n;
   90|  12.2k|}
mg_base64_encode:
   92|  12.2k|size_t mg_base64_encode(const unsigned char *p, size_t n, char *to, size_t dl) {
   93|  12.2k|  size_t i, len = 0;
   94|  12.2k|  if (dl > 0) to[0] = '\0';
  ------------------
  |  Branch (94:7): [True: 12.2k, False: 0]
  ------------------
   95|  12.2k|  if (dl < ((n / 3) + (n % 3 ? 1 : 0)) * 4 + 1) return 0;
  ------------------
  |  Branch (95:7): [True: 0, False: 12.2k]
  |  Branch (95:24): [True: 4.06k, False: 8.13k]
  ------------------
   96|   217M|  for (i = 0; i < n; i++) len = mg_base64_update(p[i], to, len);
  ------------------
  |  Branch (96:15): [True: 217M, False: 12.2k]
  ------------------
   97|  12.2k|  len = mg_base64_final(to, len);
   98|  12.2k|  return len;
   99|  12.2k|}
mg_base64_decode:
  101|  12.2k|size_t mg_base64_decode(const char *src, size_t n, char *dst, size_t dl) {
  102|  12.2k|  const char *end = src == NULL ? NULL : src + n;  // Cannot add to NULL
  ------------------
  |  Branch (102:21): [True: 6.10k, False: 6.10k]
  ------------------
  103|  12.2k|  size_t len = 0;
  104|  12.2k|  if (dl < n / 4 * 3 + 1) goto fail;
  ------------------
  |  Branch (104:7): [True: 0, False: 12.2k]
  ------------------
  105|   743k|  while (src != NULL && src + 3 < end) {
  ------------------
  |  Branch (105:10): [True: 737k, False: 6.10k]
  |  Branch (105:25): [True: 736k, False: 629]
  ------------------
  106|   736k|    int a = mg_base64_decode_single(src[0]),
  107|   736k|        b = mg_base64_decode_single(src[1]),
  108|   736k|        c = mg_base64_decode_single(src[2]),
  109|   736k|        d = mg_base64_decode_single(src[3]);
  110|   736k|    if (a == 64 || a < 0 || b == 64 || b < 0 || c < 0 || d < 0) {
  ------------------
  |  Branch (110:9): [True: 22, False: 736k]
  |  Branch (110:20): [True: 2.42k, False: 734k]
  |  Branch (110:29): [True: 11, False: 734k]
  |  Branch (110:40): [True: 1.06k, False: 733k]
  |  Branch (110:49): [True: 1.73k, False: 731k]
  |  Branch (110:58): [True: 219, False: 731k]
  ------------------
  111|  5.47k|      goto fail;
  112|  5.47k|    }
  113|   731k|    dst[len++] = (char) ((a << 2) | (b >> 4));
  114|   731k|    if (src[2] != '=') {
  ------------------
  |  Branch (114:9): [True: 731k, False: 210]
  ------------------
  115|   731k|      dst[len++] = (char) ((b << 4) | (c >> 2));
  116|   731k|      if (src[3] != '=') dst[len++] = (char) ((c << 6) | d);
  ------------------
  |  Branch (116:11): [True: 731k, False: 234]
  ------------------
  117|   731k|    }
  118|   731k|    src += 4;
  119|   731k|  }
  120|  6.73k|  dst[len] = '\0';
  121|  6.73k|  return len;
  122|  5.47k|fail:
  123|  5.47k|  if (dl > 0) dst[0] = '\0';
  ------------------
  |  Branch (123:7): [True: 5.47k, False: 0]
  ------------------
  124|  5.47k|  return 0;
  125|  12.2k|}
mg_resolve_cancel:
 2127|  6.10k|void mg_resolve_cancel(struct mg_connection *c) {
 2128|  6.10k|  struct dns_data *tmp, *d;
 2129|  6.10k|  struct mdns_data *mtmp, *md;
 2130|  6.10k|  struct dns_data **head = (struct dns_data **) &c->mgr->active_dns_requests;
 2131|  6.10k|  struct mdns_data **mhead =
 2132|  6.10k|      (struct mdns_data **) &c->mgr->active_mdns_requests;
 2133|  6.10k|  for (d = *head; d != NULL; d = tmp) {
  ------------------
  |  Branch (2133:19): [True: 0, False: 6.10k]
  ------------------
 2134|      0|    tmp = d->next;
 2135|      0|    if (d->c == c) dns_free(head, d);
  ------------------
  |  Branch (2135:9): [True: 0, False: 0]
  ------------------
 2136|      0|  }
 2137|  6.10k|  for (md = *mhead; md != NULL; md = mtmp) {
  ------------------
  |  Branch (2137:21): [True: 0, False: 6.10k]
  ------------------
 2138|      0|    mtmp = md->next;
 2139|      0|    if (md->c == c) mdns_free(mhead, md);
  ------------------
  |  Branch (2139:9): [True: 0, False: 0]
  ------------------
 2140|      0|  }
 2141|  6.10k|}
mg_dns_parse_rr:
 2186|    776|                       bool is_question, struct mg_dns_rr *rr) {
 2187|    776|  const uint8_t *s = buf + ofs, *e = &buf[len];
 2188|       |
 2189|    776|  memset(rr, 0, sizeof(*rr));
 2190|    776|  if (len < sizeof(struct mg_dns_header)) return 0;  // Too small
  ------------------
  |  Branch (2190:7): [True: 0, False: 776]
  ------------------
 2191|    776|  if (len > 512) return 0;  //  Too large, we don't expect that
  ------------------
  |  Branch (2191:7): [True: 56, False: 720]
  ------------------
 2192|    720|  if (s >= e) return 0;     //  Overflow
  ------------------
  |  Branch (2192:7): [True: 106, False: 614]
  ------------------
 2193|       |
 2194|    614|  if ((rr->nlen = (uint16_t) mg_dns_parse_name(buf, len, ofs, NULL, 0)) == 0)
  ------------------
  |  Branch (2194:7): [True: 69, False: 545]
  ------------------
 2195|     69|    return 0;
 2196|    545|  s += rr->nlen + 4;
 2197|    545|  if (s > e) return 0;
  ------------------
  |  Branch (2197:7): [True: 59, False: 486]
  ------------------
 2198|    486|  rr->atype = (uint16_t) (((uint16_t) s[-4] << 8) | s[-3]);
 2199|    486|  rr->aclass = (uint16_t) (((uint16_t) s[-2] << 8) | s[-1]);
 2200|    486|  if (is_question) return (size_t) (rr->nlen + 4);
  ------------------
  |  Branch (2200:7): [True: 115, False: 371]
  ------------------
 2201|       |
 2202|    371|  s += 6;
 2203|    371|  if (s > e) return 0;
  ------------------
  |  Branch (2203:7): [True: 15, False: 356]
  ------------------
 2204|    356|  rr->alen = (uint16_t) (((uint16_t) s[-2] << 8) | s[-1]);
 2205|    356|  if (s + rr->alen > e) return 0;
  ------------------
  |  Branch (2205:7): [True: 55, False: 301]
  ------------------
 2206|    301|  return (size_t) (rr->nlen + rr->alen + 10);
 2207|    356|}
mg_dns_parse:
 2209|  12.2k|bool mg_dns_parse(const uint8_t *buf, size_t len, struct mg_dns_message *dm) {
 2210|  12.2k|  const struct mg_dns_header *h = (struct mg_dns_header *) buf;
 2211|  12.2k|  struct mg_dns_rr rr;
 2212|  12.2k|  size_t i, n, num_answers, ofs = sizeof(*h);
 2213|  12.2k|  bool is_response;
 2214|  12.2k|  memset(dm, 0, sizeof(*dm));
 2215|       |
 2216|  12.2k|  if (len < sizeof(*h)) return 0;                // Too small, headers dont fit
  ------------------
  |  Branch (2216:7): [True: 7.57k, False: 4.63k]
  ------------------
 2217|  4.63k|  if (mg_ntohs(h->num_questions) > 1) return 0;  // Sanity
  ------------------
  |  Branch (2217:7): [True: 4.16k, False: 469]
  ------------------
 2218|    469|  num_answers = mg_ntohs(h->num_answers);
 2219|    469|  if (num_answers > 10) {
  ------------------
  |  Branch (2219:7): [True: 373, False: 96]
  ------------------
 2220|    373|    MG_DEBUG(("Got %u answers, ignoring beyond 10th one", num_answers));
  ------------------
  |  | 1804|    373|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|    373|  do {                      \
  |  |  |  | 1793|    373|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 373]
  |  |  |  |  ------------------
  |  |  |  | 1794|    373|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 373]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2221|    373|    num_answers = 10;  // Sanity cap
 2222|    373|  }
 2223|    469|  dm->txnid = mg_ntohs(h->txnid);
 2224|    469|  is_response = mg_ntohs(h->flags) & 0x8000;
 2225|       |
 2226|    584|  for (i = 0; i < mg_ntohs(h->num_questions); i++) { // advance past queries
  ------------------
  |  Branch (2226:15): [True: 226, False: 358]
  ------------------
 2227|    226|    if ((n = mg_dns_parse_rr(buf, len, ofs, true, &rr)) == 0) return false;
  ------------------
  |  Branch (2227:9): [True: 111, False: 115]
  ------------------
 2228|       |    // MG_INFO(("Q %lu %lu %hu/%hu", ofs, n, rr.atype, rr.aclass));
 2229|    115|    dm->addr.is_ip6 = (rr.atype == MG_DNS_RTYPE_AAAA);
  ------------------
  |  | 3759|    115|#define MG_DNS_RTYPE_AAAA 28 // IPv6 address (16 bytes)
  ------------------
 2230|    115|    mg_dns_parse_name(buf, len, ofs, dm->name, sizeof(dm->name));
 2231|    115|    ofs += n;
 2232|    115|  } // on unresolved responses, we got the name and query type, at least
 2233|       |
 2234|    358|  if (!is_response) {
  ------------------
  |  Branch (2234:7): [True: 83, False: 275]
  ------------------
 2235|       |    // For queries, there is no need to parse the answers. In this way,
 2236|       |    // we also ensure the domain name (dm->name) is parsed from
 2237|       |    // the question field.
 2238|     83|    return true;
 2239|     83|  }
 2240|       |
 2241|    574|  for (i = 0; i < num_answers; i++) {
  ------------------
  |  Branch (2241:15): [True: 550, False: 24]
  ------------------
 2242|    550|    if ((n = mg_dns_parse_rr(buf, len, ofs, false, &rr)) == 0) return false;
  ------------------
  |  Branch (2242:9): [True: 249, False: 301]
  ------------------
 2243|       |    // MG_INFO(("A -- %lu %lu %hu/%hu %s", ofs, n, rr.atype, rr.aclass,
 2244|       |    // dm->name));
 2245|    301|    mg_dns_parse_name(buf, len, ofs, dm->name, sizeof(dm->name));
 2246|    301|    ofs += n;
 2247|       |
 2248|    301|    if (rr.alen == 4 && rr.atype == MG_DNS_RTYPE_A && rr.aclass == 1) {
  ------------------
  |  | 3756|    360|#define MG_DNS_RTYPE_A 1     // IPv4 address (4 bytes)
  ------------------
  |  Branch (2248:9): [True: 59, False: 242]
  |  Branch (2248:25): [True: 28, False: 31]
  |  Branch (2248:55): [True: 1, False: 27]
  ------------------
 2249|      1|      dm->addr.is_ip6 = false;
 2250|      1|      memcpy(&dm->addr.addr.ip, &buf[ofs - 4], 4);
 2251|      1|      dm->resolved = true;
 2252|      1|      break;  // Return success
 2253|    300|    } else if (rr.alen == 16 && rr.atype == MG_DNS_RTYPE_AAAA &&
  ------------------
  |  | 3759|    358|#define MG_DNS_RTYPE_AAAA 28 // IPv6 address (16 bytes)
  ------------------
  |  Branch (2253:16): [True: 58, False: 242]
  |  Branch (2253:33): [True: 35, False: 23]
  ------------------
 2254|     35|               rr.aclass == 1) {
  ------------------
  |  Branch (2254:16): [True: 1, False: 34]
  ------------------
 2255|      1|      dm->addr.is_ip6 = true;
 2256|      1|      memcpy(&dm->addr.addr.ip, &buf[ofs - 16], 16);
 2257|      1|      dm->resolved = true;
 2258|      1|      break;  // Return success
 2259|      1|    }
 2260|    301|  }
 2261|     26|  return true;
 2262|    275|}
mg_resolve:
 2392|  6.10k|void mg_resolve(struct mg_connection *c, const char *url) {
 2393|  6.10k|  struct mg_str host = mg_url_host(url);
 2394|  6.10k|  c->rem.port = mg_htons(mg_url_port(url));
  ------------------
  |  | 2093|  6.10k|#define mg_htons(x) mg_ntohs(x)
  ------------------
 2395|  6.10k|  if (mg_aton(host, &c->rem)) {
  ------------------
  |  Branch (2395:7): [True: 6.10k, False: 0]
  ------------------
 2396|       |    // host is an IP address, do not fire name resolution
 2397|  6.10k|    mg_connect_resolved(c);
 2398|  6.10k|  } else if (host.len > 6 &&
  ------------------
  |  Branch (2398:14): [True: 0, False: 0]
  ------------------
 2399|      0|             strncmp(".local", &host.buf[host.len - 6], 6) == 0) {
  ------------------
  |  Branch (2399:14): [True: 0, False: 0]
  ------------------
 2400|       |    // this is a request for a .local name (mDNS)
 2401|      0|    sendmdnsreq(c, &host, 500, c->mgr->mdns, c->mgr->use_dns6);  // 500ms tmout
 2402|      0|  } else {
 2403|       |    // host is not an IP nor a .local, send DNS resolution request
 2404|      0|    struct mg_dns *dns = c->mgr->use_dns6 ? &c->mgr->dns6 : &c->mgr->dns4;
  ------------------
  |  Branch (2404:26): [True: 0, False: 0]
  ------------------
 2405|      0|    sendnsreq(c, &host, c->mgr->dnstimeout, dns, c->mgr->use_dns6);
 2406|      0|  }
 2407|  6.10k|}
mg_call:
 2928|   603k|void mg_call(struct mg_connection *c, int ev, void *ev_data) {
 2929|       |#if MG_ENABLE_PROFILE
 2930|       |  const char *names[] = {
 2931|       |      "EV_ERROR",    "EV_OPEN",      "EV_POLL",      "EV_RESOLVE",
 2932|       |      "EV_CONNECT",  "EV_ACCEPT",    "EV_TLS_HS",    "EV_READ",
 2933|       |      "EV_WRITE",    "EV_CLOSE",     "EV_HTTP_MSG",  "EV_HTTP_CHUNK",
 2934|       |      "EV_WS_OPEN",  "EV_WS_MSG",    "EV_WS_CTL",    "EV_MQTT_CMD",
 2935|       |      "EV_MQTT_MSG", "EV_MQTT_OPEN", "EV_SNTP_TIME", "EV_USER"};
 2936|       |  if (ev != MG_EV_POLL && ev < (int) (sizeof(names) / sizeof(names[0]))) {
 2937|       |    MG_PROF_ADD(c, names[ev]);
 2938|       |  }
 2939|       |#endif
 2940|       |  // Fire protocol handler first, user handler second. See #2559
 2941|   603k|  if (c->pfn != NULL) c->pfn(c, ev, ev_data);
  ------------------
  |  Branch (2941:7): [True: 603k, False: 0]
  ------------------
 2942|   603k|  if (c->fn != NULL) c->fn(c, ev, ev_data);
  ------------------
  |  Branch (2942:7): [True: 603k, False: 0]
  ------------------
 2943|   603k|}
mg_error:
 2945|    719|void mg_error(struct mg_connection *c, const char *fmt, ...) {
 2946|    719|  char buf[64];
 2947|    719|  va_list ap;
 2948|    719|  va_start(ap, fmt);
 2949|    719|  mg_vsnprintf(buf, sizeof(buf), fmt, &ap);
 2950|    719|  va_end(ap);
 2951|    719|  MG_ERROR(("%lu %ld %s", c->id, c->fd, buf));
  ------------------
  |  | 1802|    719|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|    719|  do {                      \
  |  |  |  | 1793|    719|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 719]
  |  |  |  |  ------------------
  |  |  |  | 1794|    719|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 719]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2952|    719|  c->is_closing = 1;             // Set is_closing before sending MG_EV_CALL
 2953|    719|  mg_call(c, MG_EV_ERROR, buf);  // Let user handler override it
 2954|    719|}
mg_vxprintf:
 3211|  1.85M|                   va_list *ap) {
 3212|  1.85M|  size_t i = 0, n = 0;
 3213|  27.5M|  while (fmt[i] != '\0') {
  ------------------
  |  Branch (3213:10): [True: 25.7M, False: 1.85M]
  ------------------
 3214|  25.7M|    if (fmt[i] == '%') {
  ------------------
  |  Branch (3214:9): [True: 1.39M, False: 24.3M]
  ------------------
 3215|  1.39M|      size_t j, k, x = 0, is_long = 0, w = 0 /* width */, pr = ~0U /* prec */;
 3216|  1.39M|      char pad = ' ', minus = 0, c = fmt[++i];
 3217|  1.39M|      if (c == '#') x++, c = fmt[++i];
  ------------------
  |  Branch (3217:11): [True: 0, False: 1.39M]
  ------------------
 3218|  1.39M|      if (c == '-') minus++, c = fmt[++i];
  ------------------
  |  Branch (3218:11): [True: 284k, False: 1.11M]
  ------------------
 3219|  1.39M|      if (c == '0') pad = '0', c = fmt[++i];
  ------------------
  |  Branch (3219:11): [True: 0, False: 1.39M]
  ------------------
 3220|  1.96M|      while (is_digit(c)) w *= 10, w += (size_t) (c - '0'), c = fmt[++i];
  ------------------
  |  Branch (3220:14): [True: 569k, False: 1.39M]
  ------------------
 3221|  1.39M|      if (c == '.') {
  ------------------
  |  Branch (3221:11): [True: 260k, False: 1.13M]
  ------------------
 3222|   260k|        c = fmt[++i];
 3223|   260k|        if (c == '*') {
  ------------------
  |  Branch (3223:13): [True: 260k, False: 0]
  ------------------
 3224|   260k|          pr = (size_t) va_arg(*ap, int);
 3225|   260k|          c = fmt[++i];
 3226|   260k|        } else {
 3227|      0|          pr = 0;
 3228|      0|          while (is_digit(c)) pr *= 10, pr += (size_t) (c - '0'), c = fmt[++i];
  ------------------
  |  Branch (3228:18): [True: 0, False: 0]
  ------------------
 3229|      0|        }
 3230|   260k|      }
 3231|  1.39M|      while (c == 'h') c = fmt[++i];  // Treat h and hh as int
  ------------------
  |  Branch (3231:14): [True: 0, False: 1.39M]
  ------------------
 3232|  1.39M|      if (c == 'l') {
  ------------------
  |  Branch (3232:11): [True: 284k, False: 1.11M]
  ------------------
 3233|   284k|        is_long++, c = fmt[++i];
 3234|   284k|        if (c == 'l') is_long++, c = fmt[++i];
  ------------------
  |  Branch (3234:13): [True: 0, False: 284k]
  ------------------
 3235|   284k|      }
 3236|  1.39M|      if (c == 'z') is_long = 1, c = fmt[++i];
  ------------------
  |  Branch (3236:11): [True: 0, False: 1.39M]
  ------------------
 3237|  1.39M|      if (c == 'p') x = 1, is_long = 1;
  ------------------
  |  Branch (3237:11): [True: 0, False: 1.39M]
  ------------------
 3238|  1.39M|      if (c == 'd' || c == 'u' || c == 'x' || c == 'X' || c == 'p' ||
  ------------------
  |  Branch (3238:11): [True: 284k, False: 1.11M]
  |  Branch (3238:23): [True: 284k, False: 830k]
  |  Branch (3238:35): [True: 0, False: 830k]
  |  Branch (3238:47): [True: 0, False: 830k]
  |  Branch (3238:59): [True: 0, False: 830k]
  ------------------
 3239|   830k|          c == 'g' || c == 'f') {
  ------------------
  |  Branch (3239:11): [True: 0, False: 830k]
  |  Branch (3239:23): [True: 0, False: 830k]
  ------------------
 3240|   569k|        bool s = (c == 'd'), h = (c == 'x' || c == 'X' || c == 'p');
  ------------------
  |  Branch (3240:35): [True: 0, False: 569k]
  |  Branch (3240:47): [True: 0, False: 569k]
  |  Branch (3240:59): [True: 0, False: 569k]
  ------------------
 3241|   569k|        char tmp[40];
 3242|   569k|        size_t xl = x ? 2 : 0;
  ------------------
  |  Branch (3242:21): [True: 0, False: 569k]
  ------------------
 3243|   569k|        if (c == 'g' || c == 'f') {
  ------------------
  |  Branch (3243:13): [True: 0, False: 569k]
  |  Branch (3243:25): [True: 0, False: 569k]
  ------------------
 3244|      0|          double v = va_arg(*ap, double);
 3245|      0|          if (pr == ~0U) pr = 6;
  ------------------
  |  Branch (3245:15): [True: 0, False: 0]
  ------------------
 3246|      0|          k = mg_dtoa(tmp, sizeof(tmp), v, (int) pr, c == 'g');
 3247|   569k|        } else if (is_long == 2) {
  ------------------
  |  Branch (3247:20): [True: 0, False: 569k]
  ------------------
 3248|      0|          int64_t v = va_arg(*ap, int64_t);
 3249|      0|          k = mg_lld(tmp, v, s, h);
 3250|   569k|        } else if (is_long == 1) {
  ------------------
  |  Branch (3250:20): [True: 284k, False: 284k]
  ------------------
 3251|   284k|          long v = va_arg(*ap, long);
 3252|   284k|          k = mg_lld(tmp, s ? (int64_t) v : (int64_t) (unsigned long) v, s, h);
  ------------------
  |  Branch (3252:27): [True: 0, False: 284k]
  ------------------
 3253|   284k|        } else {
 3254|   284k|          int v = va_arg(*ap, int);
 3255|   284k|          k = mg_lld(tmp, s ? (int64_t) v : (int64_t) (unsigned) v, s, h);
  ------------------
  |  Branch (3255:27): [True: 284k, False: 0]
  ------------------
 3256|   284k|        }
 3257|   569k|        for (j = 0; j < xl && w > 0; j++) w--;
  ------------------
  |  Branch (3257:21): [True: 0, False: 569k]
  |  Branch (3257:31): [True: 0, False: 0]
  ------------------
 3258|   569k|        for (j = 0; pad == ' ' && !minus && k < w && j + k < w; j++)
  ------------------
  |  Branch (3258:21): [True: 569k, False: 0]
  |  Branch (3258:35): [True: 284k, False: 284k]
  |  Branch (3258:45): [True: 0, False: 284k]
  |  Branch (3258:54): [True: 0, False: 0]
  ------------------
 3259|      0|          n += scpy(out, param, &pad, 1);
 3260|   569k|        n += scpy(out, param, (char *) "0x", xl);
 3261|   569k|        for (j = 0; pad == '0' && k < w && j + k < w; j++)
  ------------------
  |  Branch (3261:21): [True: 0, False: 569k]
  |  Branch (3261:35): [True: 0, False: 0]
  |  Branch (3261:44): [True: 0, False: 0]
  ------------------
 3262|      0|          n += scpy(out, param, &pad, 1);
 3263|   569k|        n += scpy(out, param, tmp, k);
 3264|  2.84M|        for (j = 0; pad == ' ' && minus && k < w && j + k < w; j++)
  ------------------
  |  Branch (3264:21): [True: 2.84M, False: 0]
  |  Branch (3264:35): [True: 2.56M, False: 284k]
  |  Branch (3264:44): [True: 2.56M, False: 0]
  |  Branch (3264:53): [True: 2.27M, False: 284k]
  ------------------
 3265|  2.27M|          n += scpy(out, param, &pad, 1);
 3266|   830k|      } else if (c == 'm' || c == 'M') {
  ------------------
  |  Branch (3266:18): [True: 0, False: 830k]
  |  Branch (3266:30): [True: 0, False: 830k]
  ------------------
 3267|      0|        mg_pm_t f = va_arg(*ap, mg_pm_t);
 3268|      0|        if (c == 'm') out('"', param);
  ------------------
  |  Branch (3268:13): [True: 0, False: 0]
  ------------------
 3269|      0|        n += f(out, param, ap);
 3270|      0|        if (c == 'm') n += 2, out('"', param);
  ------------------
  |  Branch (3270:13): [True: 0, False: 0]
  ------------------
 3271|   830k|      } else if (c == 'c') {
  ------------------
  |  Branch (3271:18): [True: 0, False: 830k]
  ------------------
 3272|      0|        int ch = va_arg(*ap, int);
 3273|      0|        out((char) ch, param);
 3274|      0|        n++;
 3275|   830k|      } else if (c == 's') {
  ------------------
  |  Branch (3275:18): [True: 830k, False: 0]
  ------------------
 3276|   830k|        char *p = va_arg(*ap, char *);
 3277|   830k|        if (p != NULL && pr != ~0U) {
  ------------------
  |  Branch (3277:13): [True: 830k, False: 0]
  |  Branch (3277:26): [True: 260k, False: 569k]
  ------------------
 3278|   538k|          for (j = 0; j < pr && p[j] != '\0'; j++) ;  // portable strnlen()
  ------------------
  |  Branch (3278:23): [True: 278k, False: 260k]
  |  Branch (3278:33): [True: 278k, False: 0]
  ------------------
 3279|   260k|          pr = j;
 3280|   569k|        } else {
 3281|   569k|          pr = p == NULL ? 0 : strlen(p);
  ------------------
  |  Branch (3281:16): [True: 0, False: 569k]
  ------------------
 3282|   569k|        }
 3283|   830k|        for (j = 0; !minus && pr < w && j + pr < w; j++)
  ------------------
  |  Branch (3283:21): [True: 830k, False: 0]
  |  Branch (3283:31): [True: 0, False: 830k]
  |  Branch (3283:41): [True: 0, False: 0]
  ------------------
 3284|      0|          n += scpy(out, param, &pad, 1);
 3285|   830k|        n += scpy(out, param, p, pr);
 3286|   830k|        for (j = 0; minus && pr < w && j + pr < w; j++)
  ------------------
  |  Branch (3286:21): [True: 0, False: 830k]
  |  Branch (3286:30): [True: 0, False: 0]
  |  Branch (3286:40): [True: 0, False: 0]
  ------------------
 3287|      0|          n += scpy(out, param, &pad, 1);
 3288|   830k|      } else if (c == '%') {
  ------------------
  |  Branch (3288:18): [True: 0, False: 0]
  ------------------
 3289|      0|        out('%', param);
 3290|      0|        n++;
 3291|      0|      } else {
 3292|      0|        out('%', param);
 3293|      0|        out(c, param);
 3294|      0|        n += 2;
 3295|      0|      }
 3296|  1.39M|      i++;
 3297|  24.3M|    } else {
 3298|  24.3M|      out(fmt[i], param), n++, i++;
 3299|  24.3M|    }
 3300|  25.7M|  }
 3301|  1.85M|  return n;
 3302|  1.85M|}
mg_fs_open:
 3313|  10.2k|struct mg_fd *mg_fs_open(struct mg_fs *fs, const char *path, int flags) {
 3314|  10.2k|  struct mg_fd *fd = (struct mg_fd *) mg_calloc(1, sizeof(*fd));
 3315|  10.2k|  if (fd != NULL) {
  ------------------
  |  Branch (3315:7): [True: 10.2k, False: 0]
  ------------------
 3316|  10.2k|    fd->fd = fs->op(path, flags);
 3317|  10.2k|    fd->fs = fs;
 3318|  10.2k|    if (fd->fd == NULL) {
  ------------------
  |  Branch (3318:9): [True: 10.2k, False: 0]
  ------------------
 3319|  10.2k|      mg_free(fd);
 3320|       |      fd = NULL;
 3321|  10.2k|    }
 3322|  10.2k|  }
 3323|  10.2k|  return fd;
 3324|  10.2k|}
mg_fs_close:
 3326|  10.0k|void mg_fs_close(struct mg_fd *fd) {
 3327|  10.0k|  if (fd != NULL) {
  ------------------
  |  Branch (3327:7): [True: 0, False: 10.0k]
  ------------------
 3328|      0|    fd->fs->cl(fd->fd);
 3329|      0|    mg_free(fd);
 3330|      0|  }
 3331|  10.0k|}
_Z12mg_to_size_t6mg_strPm:
 4256|  3.40k|bool mg_to_size_t(struct mg_str str, size_t *val) {
 4257|  3.40k|  size_t i = 0, max = (size_t) -1, max2 = max / 10, result = 0, ndigits = 0;
 4258|  3.40k|  while (i < str.len && (str.buf[i] == ' ' || str.buf[i] == '\t')) i++;
  ------------------
  |  Branch (4258:10): [True: 3.37k, False: 30]
  |  Branch (4258:26): [True: 0, False: 3.37k]
  |  Branch (4258:47): [True: 0, False: 3.37k]
  ------------------
 4259|  3.40k|  if (i < str.len && str.buf[i] == '-') return false;
  ------------------
  |  Branch (4259:7): [True: 3.37k, False: 30]
  |  Branch (4259:22): [True: 11, False: 3.36k]
  ------------------
 4260|  6.74M|  while (i < str.len && str.buf[i] >= '0' && str.buf[i] <= '9') {
  ------------------
  |  Branch (4260:10): [True: 6.74M, False: 3.23k]
  |  Branch (4260:25): [True: 6.74M, False: 109]
  |  Branch (4260:46): [True: 6.74M, False: 27]
  ------------------
 4261|  6.74M|    size_t digit = (size_t) (str.buf[i] - '0');
 4262|  6.74M|    if (result > max2) return false;  // Overflow
  ------------------
  |  Branch (4262:9): [True: 15, False: 6.74M]
  ------------------
 4263|  6.74M|    result *= 10;
 4264|  6.74M|    if (result > max - digit) return false;  // Overflow
  ------------------
  |  Branch (4264:9): [True: 5, False: 6.74M]
  ------------------
 4265|  6.74M|    result += digit;
 4266|  6.74M|    i++, ndigits++;
 4267|  6.74M|  }
 4268|  1.93M|  while (i < str.len && (str.buf[i] == ' ' || str.buf[i] == '\t')) i++;
  ------------------
  |  Branch (4268:10): [True: 1.93M, False: 3.23k]
  |  Branch (4268:26): [True: 1.93M, False: 350]
  |  Branch (4268:47): [True: 214, False: 136]
  ------------------
 4269|  3.37k|  if (ndigits == 0) return false;  // #2322: Content-Length = 1 * DIGIT
  ------------------
  |  Branch (4269:7): [True: 63, False: 3.31k]
  ------------------
 4270|  3.31k|  if (i != str.len) return false;  // Ditto
  ------------------
  |  Branch (4270:7): [True: 103, False: 3.20k]
  ------------------
 4271|  3.20k|  *val = (size_t) result;
 4272|  3.20k|  return true;
 4273|  3.31k|}
mg_http_var:
 4356|  6.10k|struct mg_str mg_http_var(struct mg_str buf, struct mg_str name) {
 4357|  6.10k|  struct mg_str entry, k, v, result = mg_str_n(NULL, 0);
 4358|  70.7k|  while (mg_span(buf, &entry, &buf, '&')) {
  ------------------
  |  Branch (4358:10): [True: 64.6k, False: 6.06k]
  ------------------
 4359|  64.6k|    if (mg_span(entry, &k, &v, '=') && name.len == k.len &&
  ------------------
  |  Branch (4359:9): [True: 60.5k, False: 4.10k]
  |  Branch (4359:40): [True: 16.5k, False: 43.9k]
  ------------------
 4360|  16.5k|        mg_ncasecmp(name.buf, k.buf, k.len) == 0) {
  ------------------
  |  Branch (4360:9): [True: 40, False: 16.5k]
  ------------------
 4361|     40|      result = v;
 4362|     40|      break;
 4363|     40|    }
 4364|  64.6k|  }
 4365|  6.10k|  return result;
 4366|  6.10k|}
mg_http_get_var:
 4369|  12.2k|                    size_t dst_len) {
 4370|  12.2k|  int len;
 4371|  12.2k|  if (dst != NULL && dst_len > 0) {
  ------------------
  |  Branch (4371:7): [True: 6.10k, False: 6.10k]
  |  Branch (4371:22): [True: 6.10k, False: 0]
  ------------------
 4372|  6.10k|    dst[0] = '\0';  // If destination buffer is valid, always nul-terminate it
 4373|  6.10k|  }
 4374|  12.2k|  if (dst == NULL || dst_len == 0) {
  ------------------
  |  Branch (4374:7): [True: 6.10k, False: 6.10k]
  |  Branch (4374:22): [True: 0, False: 6.10k]
  ------------------
 4375|  6.10k|    len = -2;  // Bad destination
 4376|  6.10k|  } else if (buf->buf == NULL || name == NULL || buf->len == 0) {
  ------------------
  |  Branch (4376:14): [True: 0, False: 6.10k]
  |  Branch (4376:34): [True: 0, False: 6.10k]
  |  Branch (4376:50): [True: 0, False: 6.10k]
  ------------------
 4377|      0|    len = -1;  // Bad source
 4378|  6.10k|  } else {
 4379|  6.10k|    struct mg_str v = mg_http_var(*buf, mg_str(name));
  ------------------
  |  | 1503|  6.10k|#define mg_str(s) mg_str_s(s)
  ------------------
 4380|  6.10k|    if (v.buf == NULL) {
  ------------------
  |  Branch (4380:9): [True: 6.06k, False: 40]
  ------------------
 4381|  6.06k|      len = -4;  // Name does not exist
 4382|  6.06k|    } else {
 4383|     40|      len = mg_url_decode(v.buf, v.len, dst, dst_len, 1);
 4384|     40|      if (len < 0) len = -3;  // Failed to decode
  ------------------
  |  Branch (4384:11): [True: 12, False: 28]
  ------------------
 4385|     40|    }
 4386|  6.10k|  }
 4387|  12.2k|  return len;
 4388|  12.2k|}
mg_url_decode:
 4396|   277k|                  int is_form_url_encoded) {
 4397|   277k|  size_t i, j;
 4398|  7.79M|  for (i = j = 0; i < src_len && j + 1 < dst_len; i++, j++) {
  ------------------
  |  Branch (4398:19): [True: 7.52M, False: 265k]
  |  Branch (4398:34): [True: 7.51M, False: 7.65k]
  ------------------
 4399|  7.51M|    if (src[i] == '%') {
  ------------------
  |  Branch (4399:9): [True: 88.9k, False: 7.42M]
  ------------------
 4400|       |      // Use `i + 2 < src_len`, not `i < src_len - 2`, note small src_len
 4401|  88.9k|      if (i + 2 < src_len && isx(src[i + 1]) && isx(src[i + 2])) {
  ------------------
  |  Branch (4401:11): [True: 88.6k, False: 332]
  |  Branch (4401:30): [True: 86.0k, False: 2.60k]
  |  Branch (4401:49): [True: 83.8k, False: 2.16k]
  ------------------
 4402|  83.8k|        mg_str_to_num(mg_str_n(src + i + 1, 2), 16, &dst[j], sizeof(uint8_t));
 4403|  83.8k|        i += 2;
 4404|  83.8k|      } else {
 4405|  5.09k|        dst[0] = '\0';
 4406|  5.09k|        return -1;
 4407|  5.09k|      }
 4408|  7.42M|    } else if (is_form_url_encoded && src[i] == '+') {
  ------------------
  |  Branch (4408:16): [True: 487k, False: 6.94M]
  |  Branch (4408:39): [True: 2.85k, False: 485k]
  ------------------
 4409|  2.85k|      dst[j] = ' ';
 4410|  7.42M|    } else {
 4411|  7.42M|      dst[j] = src[i];
 4412|  7.42M|    }
 4413|  7.51M|  }
 4414|   272k|  if (j < dst_len) dst[j] = '\0';  // Null-terminate the destination
  ------------------
  |  Branch (4414:7): [True: 272k, False: 0]
  ------------------
 4415|   272k|  return i >= src_len && j < dst_len ? (int) j : -1;
  ------------------
  |  Branch (4415:10): [True: 265k, False: 7.65k]
  |  Branch (4415:26): [True: 265k, False: 0]
  ------------------
 4416|   277k|}
mg_http_get_request_len:
 4422|   305k|int mg_http_get_request_len(const unsigned char *buf, size_t buf_len) {
 4423|   305k|  size_t i;
 4424|   187M|  for (i = 0; i < buf_len; i++) {
  ------------------
  |  Branch (4424:15): [True: 187M, False: 10.5k]
  ------------------
 4425|   187M|    if (!isok(buf[i])) return -1;
  ------------------
  |  Branch (4425:9): [True: 3.54k, False: 187M]
  ------------------
 4426|   187M|    if ((i > 0 && buf[i] == '\n' && buf[i - 1] == '\n') ||
  ------------------
  |  Branch (4426:10): [True: 186M, False: 298k]
  |  Branch (4426:19): [True: 686k, False: 186M]
  |  Branch (4426:37): [True: 287k, False: 399k]
  ------------------
 4427|   186M|        (i > 3 && buf[i] == '\n' && buf[i - 1] == '\r' && buf[i - 2] == '\n'))
  ------------------
  |  Branch (4427:10): [True: 185M, False: 1.18M]
  |  Branch (4427:19): [True: 398k, False: 185M]
  |  Branch (4427:37): [True: 27.4k, False: 371k]
  |  Branch (4427:59): [True: 4.26k, False: 23.2k]
  ------------------
 4428|   291k|      return (int) i + 1;
 4429|   187M|  }
 4430|  10.5k|  return 0;
 4431|   305k|}
mg_http_get_header:
 4432|   862k|struct mg_str *mg_http_get_header(struct mg_http_message *h, const char *name) {
 4433|   862k|  size_t i, n = strlen(name), max = sizeof(h->headers) / sizeof(h->headers[0]);
 4434|  1.00M|  for (i = 0; i < max && h->headers[i].name.len > 0; i++) {
  ------------------
  |  Branch (4434:15): [True: 1.00M, False: 861]
  |  Branch (4434:26): [True: 168k, False: 840k]
  ------------------
 4435|   168k|    struct mg_str *k = &h->headers[i].name, *v = &h->headers[i].value;
 4436|   168k|    if (n == k->len && mg_ncasecmp(k->buf, name, n) == 0) return v;
  ------------------
  |  Branch (4436:9): [True: 35.1k, False: 133k]
  |  Branch (4436:24): [True: 20.9k, False: 14.1k]
  ------------------
 4437|   168k|  }
 4438|   841k|  return NULL;
 4439|   862k|}
mg_http_parse:
 4510|   305k|int mg_http_parse(const char *s, size_t len, struct mg_http_message *hm) {
 4511|   305k|  int is_response, req_len = mg_http_get_request_len((unsigned char *) s, len);
 4512|   305k|  const char *end = s == NULL ? NULL : s + req_len, *qs;  // Cannot add to NULL
  ------------------
  |  Branch (4512:21): [True: 6.10k, False: 299k]
  ------------------
 4513|   305k|  const struct mg_str *cl;
 4514|   305k|  size_t n;
 4515|   305k|  bool version_prefix_valid;
 4516|       |
 4517|   305k|  memset(hm, 0, sizeof(*hm));
 4518|   305k|  if (req_len <= 0) return req_len;
  ------------------
  |  Branch (4518:7): [True: 14.0k, False: 291k]
  ------------------
 4519|       |
 4520|   291k|  hm->message.buf = hm->head.buf = (char *) s;
 4521|   291k|  hm->body.buf = (char *) end;
 4522|   291k|  hm->head.len = (size_t) req_len;
 4523|   291k|  hm->message.len = hm->body.len = (size_t) -1;  // Set body length to infinite
 4524|       |
 4525|       |  // Parse request line
 4526|   291k|  hm->method.buf = (char *) s;
 4527|  10.3M|  while (s < end && (n = clen(s, end)) > 0) s += n, hm->method.len += n;
  ------------------
  |  Branch (4527:10): [True: 10.3M, False: 0]
  |  Branch (4527:21): [True: 10.0M, False: 291k]
  ------------------
 4528|   585k|  while (s < end && s[0] == ' ') s++;  // Skip spaces
  ------------------
  |  Branch (4528:10): [True: 585k, False: 0]
  |  Branch (4528:21): [True: 293k, False: 291k]
  ------------------
 4529|   291k|  hm->uri.buf = (char *) s;
 4530|  17.6M|  while (s < end && (n = clen(s, end)) > 0) s += n, hm->uri.len += n;
  ------------------
  |  Branch (4530:10): [True: 17.6M, False: 0]
  |  Branch (4530:21): [True: 17.3M, False: 291k]
  ------------------
 4531|   556k|  while (s < end && s[0] == ' ') s++;  // Skip spaces
  ------------------
  |  Branch (4531:10): [True: 556k, False: 0]
  |  Branch (4531:21): [True: 264k, False: 291k]
  ------------------
 4532|   291k|  is_response =
 4533|   291k|      hm->method.len > 5 && (mg_ncasecmp(hm->method.buf, "HTTP/", 5) == 0);
  ------------------
  |  Branch (4533:7): [True: 254k, False: 36.7k]
  |  Branch (4533:29): [True: 36.5k, False: 218k]
  ------------------
 4534|   291k|  if ((s = skiptorn(s, end, &hm->proto)) == NULL) return false;
  ------------------
  |  Branch (4534:7): [True: 301, False: 291k]
  ------------------
 4535|       |  // If we're given a version, check that it is HTTP/x.x
 4536|   291k|  version_prefix_valid =
 4537|   291k|      hm->proto.len > 5 && (mg_ncasecmp(hm->proto.buf, "HTTP/", 5) == 0);
  ------------------
  |  Branch (4537:7): [True: 271k, False: 19.3k]
  |  Branch (4537:28): [True: 254k, False: 17.3k]
  ------------------
 4538|   291k|  if (!is_response && !version_prefix_valid)
  ------------------
  |  Branch (4538:7): [True: 254k, False: 36.5k]
  |  Branch (4538:23): [True: 670, False: 254k]
  ------------------
 4539|    670|    return -1;  // no version detected in request
 4540|   290k|  if (!is_response && hm->proto.len > 0 &&
  ------------------
  |  Branch (4540:7): [True: 254k, False: 36.5k]
  |  Branch (4540:23): [True: 254k, False: 0]
  ------------------
 4541|   254k|      (!version_prefix_valid || hm->proto.len != 8 ||
  ------------------
  |  Branch (4541:8): [True: 0, False: 254k]
  |  Branch (4541:33): [True: 56, False: 253k]
  ------------------
 4542|   253k|       (hm->proto.buf[5] < '0' || hm->proto.buf[5] > '9') ||
  ------------------
  |  Branch (4542:9): [True: 19, False: 253k]
  |  Branch (4542:35): [True: 7, False: 253k]
  ------------------
 4543|   253k|       (hm->proto.buf[6] != '.') ||
  ------------------
  |  Branch (4543:8): [True: 23, False: 253k]
  ------------------
 4544|   253k|       (hm->proto.buf[7] < '0' || hm->proto.buf[7] > '9'))) {
  ------------------
  |  Branch (4544:9): [True: 7, False: 253k]
  |  Branch (4544:35): [True: 3, False: 253k]
  ------------------
 4545|    115|    return -1;
 4546|    115|  }
 4547|       |
 4548|       |  // If URI contains '?' character, setup query string
 4549|   290k|  if ((qs = (const char *) memchr(hm->uri.buf, '?', hm->uri.len)) != NULL) {
  ------------------
  |  Branch (4549:7): [True: 1.00k, False: 289k]
  ------------------
 4550|  1.00k|    hm->query.buf = (char *) qs + 1;
 4551|  1.00k|    hm->query.len = (size_t) (&hm->uri.buf[hm->uri.len] - (qs + 1));
 4552|  1.00k|    hm->uri.len = (size_t) (qs - hm->uri.buf);
 4553|  1.00k|  }
 4554|       |
 4555|       |  // Sanity check. Allow protocol/reason to be empty
 4556|       |  // Do this check after hm->method.len and hm->uri.len are finalised
 4557|   290k|  if (hm->method.len == 0 || hm->uri.len == 0) return -1;
  ------------------
  |  Branch (4557:7): [True: 9, False: 290k]
  |  Branch (4557:30): [True: 22, False: 290k]
  ------------------
 4558|       |
 4559|   290k|  if (!mg_http_parse_headers(s, end, hm->headers,
  ------------------
  |  Branch (4559:7): [True: 491, False: 289k]
  ------------------
 4560|   290k|                             sizeof(hm->headers) / sizeof(hm->headers[0])))
 4561|    491|    return -1;  // error when parsing
 4562|   289k|  cl = mg_http_get_header(hm, "Content-Length");
 4563|   289k|  if (cl != NULL && mg_http_get_header(hm, "Transfer-Encoding") != NULL)
  ------------------
  |  Branch (4563:7): [True: 3.40k, False: 286k]
  |  Branch (4563:21): [True: 3, False: 3.40k]
  ------------------
 4564|      3|    return -1; // cannot contain both CL and TE
 4565|   289k|  if (cl != NULL) {
  ------------------
  |  Branch (4565:7): [True: 3.40k, False: 286k]
  ------------------
 4566|  3.40k|    if (mg_to_size_t(*cl, &hm->body.len) == false) return -1;
  ------------------
  |  Branch (4566:9): [True: 197, False: 3.20k]
  ------------------
 4567|  3.20k|    hm->message.len = (size_t) req_len + hm->body.len;
 4568|  3.20k|  }
 4569|       |
 4570|       |  // mg_http_parse() is used to parse both HTTP requests and HTTP
 4571|       |  // responses. If HTTP response does not have Content-Length set, then
 4572|       |  // body is read until socket is closed, i.e. body.len is infinite (~0).
 4573|       |  //
 4574|       |  // For HTTP requests though, if Content-Length is not specified
 4575|       |  // set body length to 0.
 4576|   289k|  if (hm->body.len == (size_t) ~0 && !is_response) {
  ------------------
  |  Branch (4576:7): [True: 286k, False: 3.20k]
  |  Branch (4576:38): [True: 253k, False: 32.6k]
  ------------------
 4577|   253k|    hm->body.len = 0;
 4578|   253k|    hm->message.len = (size_t) req_len;
 4579|   253k|  }
 4580|       |
 4581|       |  // The 204 (No content) responses also have 0 body length
 4582|   289k|  if (hm->body.len == (size_t) ~0 && is_response &&
  ------------------
  |  Branch (4582:7): [True: 32.6k, False: 257k]
  |  Branch (4582:38): [True: 32.6k, False: 0]
  ------------------
 4583|  32.6k|      mg_strcasecmp(hm->uri, mg_str("204")) == 0) {
  ------------------
  |  | 1503|  32.6k|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (4583:7): [True: 15.4k, False: 17.1k]
  ------------------
 4584|  15.4k|    hm->body.len = 0;
 4585|  15.4k|    hm->message.len = (size_t) req_len;
 4586|  15.4k|  }
 4587|   289k|  if (hm->message.len < (size_t) req_len) return -1;  // Overflow protection
  ------------------
  |  Branch (4587:7): [True: 5, False: 289k]
  ------------------
 4588|       |
 4589|   289k|  return req_len;
 4590|   289k|}
mg_http_reply:
 4690|   284k|                   const char *fmt, ...) {
 4691|   284k|  va_list ap;
 4692|   284k|  size_t len;
 4693|   284k|  mg_printf(c, "HTTP/1.1 %d %s\r\n%sContent-Length:            \r\n\r\n", code,
 4694|   284k|            mg_http_status_code_str(code), headers == NULL ? "" : headers);
  ------------------
  |  Branch (4694:44): [True: 0, False: 284k]
  ------------------
 4695|   284k|  len = c->send.len;
 4696|   284k|  va_start(ap, fmt);
 4697|   284k|  mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, &ap);
 4698|   284k|  va_end(ap);
 4699|   284k|  if (c->send.len > 16) {
  ------------------
  |  Branch (4699:7): [True: 284k, False: 0]
  ------------------
 4700|   284k|    size_t n = mg_snprintf((char *) &c->send.buf[len - 15], 11, "%-10lu",
 4701|   284k|                           (unsigned long) (c->send.len - len));
 4702|   284k|    c->send.buf[len - 15 + n] = ' ';  // Change ending 0 to space
 4703|   284k|  }
 4704|       |  c->pfn_data = NULL;  // Response done
 4705|   284k|}
mg_http_serve_file:
 4822|  10.0k|                        const struct mg_http_serve_opts *opts) {
 4823|  10.0k|  char etag[64], tmp[MG_PATH_MAX];
 4824|  10.0k|  struct mg_fs *fs = opts && opts->fs ? opts->fs : &mg_fs_posix;
  ------------------
  |  Branch (4824:22): [True: 10.0k, False: 0]
  |  Branch (4824:30): [True: 0, False: 10.0k]
  ------------------
 4825|  10.0k|  struct mg_fd *fd = NULL;
 4826|  10.0k|  size_t size = 0;
 4827|  10.0k|  time_t mtime = 0;
 4828|  10.0k|  const char *mime_types = opts && opts->mime_types ? opts->mime_types : NULL;
  ------------------
  |  Branch (4828:28): [True: 10.0k, False: 0]
  |  Branch (4828:36): [True: 0, False: 10.0k]
  ------------------
 4829|  10.0k|  const char *hdrs = opts && opts->extra_headers ? opts->extra_headers : "";
  ------------------
  |  Branch (4829:22): [True: 10.0k, False: 0]
  |  Branch (4829:30): [True: 0, False: 10.0k]
  ------------------
 4830|  10.0k|  struct mg_str *inm = NULL;
 4831|  10.0k|  struct mg_str mime = guess_content_type(mg_str(path), mime_types);
  ------------------
  |  | 1503|  10.0k|#define mg_str(s) mg_str_s(s)
  ------------------
 4832|  10.0k|  bool gzip = false;
 4833|       |
 4834|  10.0k|  if (path != NULL) {
  ------------------
  |  Branch (4834:7): [True: 10.0k, False: 0]
  ------------------
 4835|       |    // If a browser sends us "Accept-Encoding: gzip", try to open .gz first
 4836|  10.0k|    struct mg_str *ae = mg_http_get_header(hm, "Accept-Encoding");
 4837|  10.0k|    if (ae != NULL) {
  ------------------
  |  Branch (4837:9): [True: 739, False: 9.31k]
  ------------------
 4838|    739|      if (mg_match(*ae, mg_str("*gzip*"), NULL)) {
  ------------------
  |  | 1503|    739|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (4838:11): [True: 162, False: 577]
  ------------------
 4839|    162|        mg_snprintf(tmp, sizeof(tmp), "%s.gz", path);
 4840|    162|        fd = mg_fs_open(fs, tmp, MG_FS_READ);
 4841|    162|        if (fd != NULL) gzip = true, path = tmp;
  ------------------
  |  Branch (4841:13): [True: 0, False: 162]
  ------------------
 4842|    162|      }
 4843|    739|    }
 4844|       |    // No luck opening .gz? Open what we've told to open
 4845|  10.0k|    if (fd == NULL) fd = mg_fs_open(fs, path, MG_FS_READ);
  ------------------
  |  Branch (4845:9): [True: 10.0k, False: 0]
  ------------------
 4846|  10.0k|  }
 4847|       |
 4848|       |  // Failed to open, and page404 is configured? Open it, then
 4849|  10.0k|  if (fd == NULL && opts && opts->page404) {
  ------------------
  |  Branch (4849:7): [True: 10.0k, False: 0]
  |  Branch (4849:21): [True: 10.0k, False: 0]
  |  Branch (4849:29): [True: 0, False: 10.0k]
  ------------------
 4850|      0|    fd = mg_fs_open(fs, opts->page404, MG_FS_READ);
 4851|      0|    path = opts->page404;
 4852|      0|    mime = guess_content_type(mg_str(path), mime_types);
  ------------------
  |  | 1503|      0|#define mg_str(s) mg_str_s(s)
  ------------------
 4853|      0|  }
 4854|       |
 4855|  10.0k|  if (fd == NULL || fs->st(path, &size, &mtime) == 0) {
  ------------------
  |  Branch (4855:7): [True: 10.0k, False: 0]
  |  Branch (4855:21): [True: 0, False: 0]
  ------------------
 4856|  10.0k|    mg_http_reply(c, 404, hdrs, "Not found\n");
 4857|  10.0k|    mg_fs_close(fd);
 4858|       |    // NOTE: mg_http_etag() call should go first!
 4859|  10.0k|  } else if (mg_http_etag(etag, sizeof(etag), size, mtime) != NULL &&
  ------------------
  |  Branch (4859:14): [True: 0, False: 0]
  ------------------
 4860|      0|             (inm = mg_http_get_header(hm, "If-None-Match")) != NULL &&
  ------------------
  |  Branch (4860:14): [True: 0, False: 0]
  ------------------
 4861|      0|             mg_strcasecmp(*inm, mg_str(etag)) == 0) {
  ------------------
  |  | 1503|      0|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (4861:14): [True: 0, False: 0]
  ------------------
 4862|      0|    mg_fs_close(fd);
 4863|      0|    mg_http_reply(c, 304, hdrs, "");
 4864|      0|  } else {
 4865|      0|    int n, status = 200;
 4866|      0|    char range[100];
 4867|      0|    size_t r1 = 0, r2 = 0, cl = size;
 4868|       |
 4869|       |    // Handle Range header
 4870|      0|    struct mg_str *rh = mg_http_get_header(hm, "Range");
 4871|      0|    range[0] = '\0';
 4872|      0|    if (rh != NULL && (n = getrange(rh, &r1, &r2)) > 0) {
  ------------------
  |  Branch (4872:9): [True: 0, False: 0]
  |  Branch (4872:23): [True: 0, False: 0]
  ------------------
 4873|       |      // If range is specified like "400-", set second limit to content len
 4874|      0|      if (n == 1) r2 = cl - 1;
  ------------------
  |  Branch (4874:11): [True: 0, False: 0]
  ------------------
 4875|      0|      if (r1 > r2 || r2 >= cl) {
  ------------------
  |  Branch (4875:11): [True: 0, False: 0]
  |  Branch (4875:22): [True: 0, False: 0]
  ------------------
 4876|      0|        status = 416;
 4877|      0|        cl = 0;
 4878|      0|        mg_snprintf(range, sizeof(range), "Content-Range: bytes */%lld\r\n",
 4879|      0|                    (int64_t) size);
 4880|      0|      } else {
 4881|      0|        status = 206;
 4882|      0|        cl = r2 - r1 + 1;
 4883|      0|        mg_snprintf(range, sizeof(range),
 4884|      0|                    "Content-Range: bytes %llu-%llu/%llu\r\n", (uint64_t) r1,
 4885|      0|                    (uint64_t) (r1 + cl - 1), (uint64_t) size);
 4886|      0|        fs->sk(fd->fd, r1);
 4887|      0|      }
 4888|      0|    }
 4889|      0|    mg_printf(c,
 4890|      0|              "HTTP/1.1 %d %s\r\n"
 4891|      0|              "Content-Type: %.*s\r\n"
 4892|      0|              "Etag: %s\r\n"
 4893|      0|              "Content-Length: %llu\r\n"
 4894|      0|              "%s%s%s\r\n",
 4895|      0|              status, mg_http_status_code_str(status), (int) mime.len, mime.buf,
 4896|      0|              etag, (uint64_t) cl, gzip ? "Content-Encoding: gzip\r\n" : "",
  ------------------
  |  Branch (4896:36): [True: 0, False: 0]
  ------------------
 4897|      0|              range, hdrs);
 4898|      0|    if (mg_strcasecmp(hm->method, mg_str("HEAD")) == 0 || c->is_closing) {
  ------------------
  |  | 1503|      0|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (4898:9): [True: 0, False: 0]
  |  Branch (4898:59): [True: 0, False: 0]
  ------------------
 4899|      0|      c->pfn_data = NULL;  // Response done
 4900|      0|      mg_fs_close(fd);
 4901|      0|    } else {  // start serving static content only if not closing, see #3354
 4902|       |      // Track to-be-sent content length at the end of c->data, aligned
 4903|      0|      size_t *clp = (size_t *) &c->data[(sizeof(c->data) - sizeof(size_t)) /
 4904|      0|                                        sizeof(size_t) * sizeof(size_t)];
 4905|      0|      c->pfn = static_cb;
 4906|      0|      c->pfn_data = fd;
 4907|      0|      *clp = cl;
 4908|      0|    }
 4909|      0|  }
 4910|  10.0k|}
mg_http_serve_dir:
 5051|   285k|                       const struct mg_http_serve_opts *opts) {
 5052|   285k|  char path[MG_PATH_MAX];
 5053|   285k|  struct mg_fs *fs = opts->fs == NULL ? &mg_fs_posix : opts->fs;
  ------------------
  |  Branch (5053:22): [True: 285k, False: 0]
  ------------------
 5054|   285k|  const char *sp = opts->ssi_pattern;
 5055|   285k|  int flags = uri_to_file_status(c, hm, fs, opts->root_dir, path, sizeof(path));
 5056|   285k|  if (flags < 0) {
  ------------------
  |  Branch (5056:7): [True: 31.3k, False: 254k]
  ------------------
 5057|       |    // Do nothing: the response has already been sent by uri_to_file_status()
 5058|   254k|  } else if (flags & MG_FS_DIR) {
  ------------------
  |  Branch (5058:14): [True: 244k, False: 10.0k]
  ------------------
 5059|   244k|    if (opts->enable_dir_listing) {
  ------------------
  |  Branch (5059:9): [True: 0, False: 244k]
  ------------------
 5060|      0|      listdir(c, hm, opts, path);
 5061|   244k|    } else {
 5062|   244k|      mg_http_reply(c, 403, "", "Forbidden\n");
 5063|   244k|    }
 5064|   244k|  } else if (opts->enable_delete &&
  ------------------
  |  Branch (5064:14): [True: 0, False: 10.0k]
  ------------------
 5065|      0|            mg_strcasecmp(hm->method, mg_str("DELETE")) == 0) {
  ------------------
  |  | 1503|      0|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (5065:13): [True: 0, False: 0]
  ------------------
 5066|      0|    mg_http_reply(c, flags && fs->rm(path) ? 200 : 404, "", "");
  ------------------
  |  Branch (5066:22): [True: 0, False: 0]
  |  Branch (5066:31): [True: 0, False: 0]
  ------------------
 5067|  10.0k|  } else if (opts->enable_upload &&
  ------------------
  |  Branch (5067:14): [True: 0, False: 10.0k]
  ------------------
 5068|      0|            (mg_strcasecmp(hm->method, mg_str("POST")) == 0 ||
  ------------------
  |  | 1503|      0|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (5068:14): [True: 0, False: 0]
  ------------------
 5069|      0|             mg_strcasecmp(hm->method, mg_str("PUT")) == 0)) {
  ------------------
  |  | 1503|      0|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (5069:14): [True: 0, False: 0]
  ------------------
 5070|       |    // Small or already fully buffered body. mg_http_serve_upload() handles
 5071|       |    // the same thing without buffering, for big uploads, from MG_EV_HTTP_HDRS
 5072|      0|    void *fd;
 5073|      0|    bool ok = false;
 5074|      0|    fs->rm(path);  // MG_FS_WRITE appends, not truncates: drop any old file
 5075|      0|    if ((fd = fs->op(path, MG_FS_WRITE)) != NULL) {
  ------------------
  |  Branch (5075:9): [True: 0, False: 0]
  ------------------
 5076|      0|      ok = fs->wr(fd, hm->body.buf, hm->body.len) == hm->body.len;
 5077|      0|      fs->cl(fd);
 5078|      0|    }
 5079|      0|    mg_http_reply(c, ok ? 200 : 500, "", "");
  ------------------
  |  Branch (5079:22): [True: 0, False: 0]
  ------------------
 5080|  10.0k|  } else if (flags && sp != NULL && mg_match(mg_str(path), mg_str(sp), NULL)) {
  ------------------
  |  | 1503|      0|#define mg_str(s) mg_str_s(s)
  ------------------
                } else if (flags && sp != NULL && mg_match(mg_str(path), mg_str(sp), NULL)) {
  ------------------
  |  | 1503|      0|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (5080:14): [True: 0, False: 10.0k]
  |  Branch (5080:23): [True: 0, False: 0]
  |  Branch (5080:37): [True: 0, False: 0]
  ------------------
 5081|      0|    mg_http_serve_ssi(c, opts->root_dir, path);
 5082|  10.0k|  } else {
 5083|  10.0k|    mg_http_serve_file(c, hm, path, opts);
 5084|  10.0k|  }
 5085|   285k|}
mg_http_status:
 5251|  17.1k|int mg_http_status(const struct mg_http_message *hm) {
 5252|  17.1k|  return atoi(hm->uri.buf);
 5253|  17.1k|}
mg_http_connect:
 5494|  6.10k|                                      mg_event_handler_t fn, void *fn_data) {
 5495|       |  return mg_connect_svc(mgr, url, fn, fn_data, http_cb, NULL);
 5496|  6.10k|}
mg_iobuf_resize:
 5517|  32.5k|bool mg_iobuf_resize(struct mg_iobuf *io, size_t new_size) {
 5518|  32.5k|  bool ok = true;
 5519|  32.5k|  new_size = roundup(new_size, io->align);
 5520|  32.5k|  if (new_size == 0) {
  ------------------
  |  Branch (5520:7): [True: 24.4k, False: 8.11k]
  ------------------
 5521|  24.4k|    mg_bzero(io->buf, io->size);
 5522|  24.4k|    mg_free(io->buf);
 5523|  24.4k|    io->buf = NULL;
 5524|  24.4k|    io->len = io->size = 0;
 5525|  24.4k|  } else if (new_size != io->size) {
  ------------------
  |  Branch (5525:14): [True: 8.11k, False: 0]
  ------------------
 5526|       |    // NOTE(lsm): do not use realloc here. Use mg_calloc/mg_free only
 5527|  8.11k|    void *p = mg_calloc(1, new_size);
 5528|  8.11k|    if (p != NULL) {
  ------------------
  |  Branch (5528:9): [True: 8.11k, False: 0]
  ------------------
 5529|  8.11k|      size_t len = new_size < io->len ? new_size : io->len;
  ------------------
  |  Branch (5529:20): [True: 0, False: 8.11k]
  ------------------
 5530|  8.11k|      if (len > 0 && io->buf != NULL) memmove(p, io->buf, len);
  ------------------
  |  Branch (5530:11): [True: 0, False: 8.11k]
  |  Branch (5530:22): [True: 0, False: 0]
  ------------------
 5531|  8.11k|      mg_bzero(io->buf, io->size);
 5532|  8.11k|      mg_free(io->buf);
 5533|  8.11k|      io->buf = (unsigned char *) p;
 5534|  8.11k|      io->size = new_size;
 5535|  8.11k|      io->len = len;
 5536|  8.11k|    } else {
 5537|      0|      ok = false;
 5538|      0|      MG_ERROR(("%lld->%lld", (uint64_t) io->size, (uint64_t) new_size));
  ------------------
  |  | 1802|      0|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5539|      0|    }
 5540|  8.11k|  }
 5541|  32.5k|  return ok;
 5542|  32.5k|}
mg_iobuf_add:
 5552|  6.10k|                    size_t len) {
 5553|  6.10k|  size_t new_size = roundup(io->len + len, io->align);
 5554|  6.10k|  mg_iobuf_resize(io, new_size);      // Attempt to resize
 5555|  6.10k|  if (new_size != io->size) len = 0;  // Resize failure, append nothing
  ------------------
  |  Branch (5555:7): [True: 0, False: 6.10k]
  ------------------
 5556|  6.10k|  if (ofs < io->len) memmove(io->buf + ofs + len, io->buf + ofs, io->len - ofs);
  ------------------
  |  Branch (5556:7): [True: 0, False: 6.10k]
  ------------------
 5557|  6.10k|  if (buf != NULL) memmove(io->buf + ofs, buf, len);
  ------------------
  |  Branch (5557:7): [True: 6.10k, False: 0]
  ------------------
 5558|  6.10k|  if (ofs > io->len) io->len += ofs - io->len;
  ------------------
  |  Branch (5558:7): [True: 0, False: 6.10k]
  ------------------
 5559|  6.10k|  io->len += len;
 5560|  6.10k|  return len;
 5561|  6.10k|}
mg_iobuf_del:
 5563|  1.74k|size_t mg_iobuf_del(struct mg_iobuf *io, size_t ofs, size_t len) {
 5564|  1.74k|  if (ofs > io->len) ofs = io->len;
  ------------------
  |  Branch (5564:7): [True: 0, False: 1.74k]
  ------------------
 5565|  1.74k|  if (ofs + len > io->len) len = io->len - ofs;
  ------------------
  |  Branch (5565:7): [True: 0, False: 1.74k]
  ------------------
 5566|  1.74k|  if (io->buf) memmove(io->buf + ofs, io->buf + ofs + len, io->len - ofs - len);
  ------------------
  |  Branch (5566:7): [True: 1.74k, False: 0]
  ------------------
 5567|  1.74k|  if (io->buf) mg_bzero(io->buf + io->len - len, len);
  ------------------
  |  Branch (5567:7): [True: 1.74k, False: 0]
  ------------------
 5568|  1.74k|  io->len -= len;
 5569|  1.74k|  return len;
 5570|  1.74k|}
mg_iobuf_free:
 5572|  24.4k|void mg_iobuf_free(struct mg_iobuf *io) {
 5573|  24.4k|  mg_iobuf_resize(io, 0);
 5574|  24.4k|}
mg_json_get:
 5718|  18.3k|int mg_json_get(struct mg_str json, const char *path, int *toklen) {
 5719|  18.3k|  const char *s = json.buf;
 5720|  18.3k|  int len = (int) json.len;
 5721|  18.3k|  enum { S_VALUE, S_KEY, S_COLON, S_COMMA_OR_EOO } expecting = S_VALUE;
 5722|  18.3k|  unsigned char nesting[MG_JSON_MAX_DEPTH];
 5723|  18.3k|  int i = 0;             // Current offset in `s`
 5724|  18.3k|  int j = 0;             // Offset in `s` we're looking for (return value)
 5725|  18.3k|  int depth = 0;         // Current depth (nesting level)
 5726|  18.3k|  int ed = 0;            // Expected depth
 5727|  18.3k|  int pos = 1;           // Current position in `path`
 5728|  18.3k|  int ci = -1, ei = -1;  // Current and expected index in array
 5729|       |
 5730|  18.3k|  if (toklen) *toklen = 0;
  ------------------
  |  Branch (5730:7): [True: 18.3k, False: 0]
  ------------------
 5731|  18.3k|  if (path[0] != '$') return MG_JSON_INVALID;
  ------------------
  |  Branch (5731:7): [True: 0, False: 18.3k]
  ------------------
 5732|       |
 5733|  18.3k|#define MG_CHECKRET(x)                                  \
 5734|  18.3k|  do {                                                  \
 5735|  18.3k|    if (depth == ed && path[pos] == '\0' && ci == ei) { \
 5736|  18.3k|      if (toklen) *toklen = i - j + 1;                  \
 5737|  18.3k|      return j;                                         \
 5738|  18.3k|    }                                                   \
 5739|  18.3k|  } while (0)
 5740|       |
 5741|       |// In the ascii table, the distance between `[` and `]` is 2.
 5742|       |// Ditto for `{` and `}`. Hence +2 in the code below.
 5743|  18.3k|#define MG_EOO(x)                                            \
 5744|  18.3k|  do {                                                       \
 5745|  18.3k|    if (depth == ed && ci != ei) return MG_JSON_NOT_FOUND;   \
 5746|  18.3k|    if (c != nesting[depth - 1] + 2) return MG_JSON_INVALID; \
 5747|  18.3k|    depth--;                                                 \
 5748|  18.3k|    MG_CHECKRET(x);                                          \
 5749|  18.3k|  } while (0)
 5750|       |
 5751|   620k|  for (i = 0; i < len; i++) {
  ------------------
  |  Branch (5751:15): [True: 619k, False: 1.20k]
  ------------------
 5752|   619k|    unsigned char c = ((unsigned char *) s)[i];
 5753|   619k|    if (c == ' ' || c == '\t' || c == '\n' || c == '\r') continue;
  ------------------
  |  Branch (5753:9): [True: 2.52k, False: 616k]
  |  Branch (5753:21): [True: 524, False: 616k]
  |  Branch (5753:34): [True: 735, False: 615k]
  |  Branch (5753:47): [True: 501, False: 615k]
  ------------------
 5754|   615k|    switch (expecting) {
  ------------------
  |  Branch (5754:13): [True: 615k, False: 0]
  ------------------
 5755|   307k|      case S_VALUE:
  ------------------
  |  Branch (5755:7): [True: 307k, False: 307k]
  ------------------
 5756|       |        // p("V %s [%.*s] %d %d %d %d\n", path, pos, path, depth, ed, ci, ei);
 5757|   307k|        if (depth == ed) j = i;
  ------------------
  |  Branch (5757:13): [True: 21.5k, False: 286k]
  ------------------
 5758|   307k|        if (c == '{') {
  ------------------
  |  Branch (5758:13): [True: 5.62k, False: 302k]
  ------------------
 5759|  5.62k|          if (depth >= (int) sizeof(nesting)) return MG_JSON_TOO_DEEP;
  ------------------
  |  Branch (5759:15): [True: 5, False: 5.62k]
  ------------------
 5760|  5.62k|          if (depth == ed && path[pos] == '.' && ci == ei) {
  ------------------
  |  Branch (5760:15): [True: 1.64k, False: 3.97k]
  |  Branch (5760:30): [True: 310, False: 1.33k]
  |  Branch (5760:50): [True: 310, False: 0]
  ------------------
 5761|       |            // If we start the object, reset array indices
 5762|    310|            ed++, pos++, ci = ei = -1;
 5763|    310|          }
 5764|  5.62k|          nesting[depth++] = c;
 5765|  5.62k|          expecting = S_KEY;
 5766|  5.62k|          break;
 5767|   302k|        } else if (c == '[') {
  ------------------
  |  Branch (5767:20): [True: 15.0k, False: 287k]
  ------------------
 5768|  15.0k|          if (depth >= (int) sizeof(nesting)) return MG_JSON_TOO_DEEP;
  ------------------
  |  Branch (5768:15): [True: 14, False: 15.0k]
  ------------------
 5769|  15.0k|          if (depth == ed && path[pos] == '[' && ei == ci) {
  ------------------
  |  Branch (5769:15): [True: 3.50k, False: 11.5k]
  |  Branch (5769:30): [True: 378, False: 3.12k]
  |  Branch (5769:50): [True: 378, False: 0]
  ------------------
 5770|    378|            ed++, pos++, ci = 0;
 5771|    756|            for (ei = 0; path[pos] != ']' && path[pos] != '\0'; pos++) {
  ------------------
  |  Branch (5771:26): [True: 378, False: 378]
  |  Branch (5771:46): [True: 378, False: 0]
  ------------------
 5772|    378|              ei *= 10;
 5773|    378|              ei += path[pos] - '0';
 5774|    378|            }
 5775|    378|            if (path[pos] != 0) pos++;
  ------------------
  |  Branch (5775:17): [True: 378, False: 0]
  ------------------
 5776|    378|          }
 5777|  15.0k|          nesting[depth++] = c;
 5778|  15.0k|          break;
 5779|   287k|        } else if (c == ']' && depth > 0) {  // Empty array
  ------------------
  |  Branch (5779:20): [True: 5.89k, False: 281k]
  |  Branch (5779:32): [True: 5.81k, False: 78]
  ------------------
 5780|  5.81k|          MG_EOO(']');
  ------------------
  |  | 5744|  5.81k|  do {                                                       \
  |  | 5745|  5.81k|    if (depth == ed && ci != ei) return MG_JSON_NOT_FOUND;   \
  |  |  ------------------
  |  |  |  Branch (5745:9): [True: 4, False: 5.81k]
  |  |  |  Branch (5745:24): [True: 0, False: 4]
  |  |  ------------------
  |  | 5746|  5.81k|    if (c != nesting[depth - 1] + 2) return MG_JSON_INVALID; \
  |  |  ------------------
  |  |  |  Branch (5746:9): [True: 8, False: 5.80k]
  |  |  ------------------
  |  | 5747|  5.81k|    depth--;                                                 \
  |  | 5748|  5.80k|    MG_CHECKRET(x);                                          \
  |  |  ------------------
  |  |  |  | 5734|  5.80k|  do {                                                  \
  |  |  |  | 5735|  5.80k|    if (depth == ed && path[pos] == '\0' && ci == ei) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (5735:9): [True: 1.33k, False: 4.47k]
  |  |  |  |  |  Branch (5735:24): [True: 25, False: 1.30k]
  |  |  |  |  |  Branch (5735:45): [True: 25, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 5736|     25|      if (toklen) *toklen = i - j + 1;                  \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (5736:11): [True: 25, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 5737|     25|      return j;                                         \
  |  |  |  | 5738|     25|    }                                                   \
  |  |  |  | 5739|  5.80k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (5739:12): [Folded, False: 5.78k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 5749|  5.80k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (5749:12): [Folded, False: 5.78k]
  |  |  ------------------
  ------------------
 5781|   281k|        } else if (c == 't' && i + 3 < len && memcmp(&s[i], "true", 4) == 0) {
  ------------------
  |  Branch (5781:20): [True: 2.96k, False: 278k]
  |  Branch (5781:32): [True: 2.93k, False: 26]
  |  Branch (5781:47): [True: 2.79k, False: 143]
  ------------------
 5782|  2.79k|          i += 3;
 5783|   278k|        } else if (c == 'n' && i + 3 < len && memcmp(&s[i], "null", 4) == 0) {
  ------------------
  |  Branch (5783:20): [True: 14.2k, False: 264k]
  |  Branch (5783:32): [True: 14.2k, False: 11]
  |  Branch (5783:47): [True: 14.1k, False: 116]
  ------------------
 5784|  14.1k|          i += 3;
 5785|   264k|        } else if (c == 'f' && i + 4 < len && memcmp(&s[i], "false", 5) == 0) {
  ------------------
  |  Branch (5785:20): [True: 5.26k, False: 259k]
  |  Branch (5785:32): [True: 5.23k, False: 35]
  |  Branch (5785:47): [True: 5.11k, False: 113]
  ------------------
 5786|  5.11k|          i += 4;
 5787|   259k|        } else if (c == '-' || ((c >= '0' && c <= '9'))) {
  ------------------
  |  Branch (5787:20): [True: 116k, False: 143k]
  |  Branch (5787:34): [True: 138k, False: 4.92k]
  |  Branch (5787:46): [True: 126k, False: 11.2k]
  ------------------
 5788|   243k|          int numlen = 0;
 5789|   243k|          mg_atod(&s[i], len - i, &numlen);
 5790|   243k|          i += numlen - 1;
 5791|   243k|        } else if (c == '"') {
  ------------------
  |  Branch (5791:20): [True: 1.95k, False: 14.1k]
  ------------------
 5792|  1.95k|          int n = mg_pass_string(&s[i + 1], len - i - 1);
 5793|  1.95k|          if (n < 0) return n;
  ------------------
  |  Branch (5793:15): [True: 358, False: 1.59k]
  ------------------
 5794|  1.59k|          i += n + 1;
 5795|  14.1k|        } else {
 5796|  14.1k|          return MG_JSON_INVALID;
 5797|  14.1k|        }
 5798|   272k|        MG_CHECKRET('V');
  ------------------
  |  | 5734|   272k|  do {                                                  \
  |  | 5735|   272k|    if (depth == ed && path[pos] == '\0' && ci == ei) { \
  |  |  ------------------
  |  |  |  Branch (5735:9): [True: 3.34k, False: 269k]
  |  |  |  Branch (5735:24): [True: 696, False: 2.64k]
  |  |  |  Branch (5735:45): [True: 696, False: 0]
  |  |  ------------------
  |  | 5736|    696|      if (toklen) *toklen = i - j + 1;                  \
  |  |  ------------------
  |  |  |  Branch (5736:11): [True: 696, False: 0]
  |  |  ------------------
  |  | 5737|    696|      return j;                                         \
  |  | 5738|    696|    }                                                   \
  |  | 5739|   272k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (5739:12): [Folded, False: 271k]
  |  |  ------------------
  ------------------
 5799|   271k|        if (depth == ed && ei >= 0) ci++;
  ------------------
  |  Branch (5799:13): [True: 2.64k, False: 269k]
  |  Branch (5799:28): [True: 0, False: 2.64k]
  ------------------
 5800|   271k|        expecting = S_COMMA_OR_EOO;
 5801|   271k|        break;
 5802|       |
 5803|  15.0k|      case S_KEY:
  ------------------
  |  Branch (5803:7): [True: 15.0k, False: 600k]
  ------------------
 5804|  15.0k|        if (c == '"') {
  ------------------
  |  Branch (5804:13): [True: 11.8k, False: 3.11k]
  ------------------
 5805|  11.8k|          int n = mg_pass_string(&s[i + 1], len - i - 1);
 5806|  11.8k|          if (n < 0) return n;
  ------------------
  |  Branch (5806:15): [True: 237, False: 11.6k]
  ------------------
 5807|  11.6k|          if (i + 1 + n >= len) return MG_JSON_NOT_FOUND;
  ------------------
  |  Branch (5807:15): [True: 0, False: 11.6k]
  ------------------
 5808|  11.6k|          if (depth < ed) return MG_JSON_NOT_FOUND;
  ------------------
  |  Branch (5808:15): [True: 1, False: 11.6k]
  ------------------
 5809|  11.6k|          if (depth == ed && path[pos - 1] != '.') return MG_JSON_NOT_FOUND;
  ------------------
  |  Branch (5809:15): [True: 3.11k, False: 8.52k]
  |  Branch (5809:30): [True: 1, False: 3.11k]
  ------------------
 5810|       |          // printf("K %s [%.*s] [%.*s] %d %d %d %d %d\n", path, pos, path, n,
 5811|       |          //        &s[i + 1], n, depth, ed, ci, ei);
 5812|       |          //  NOTE(cpq): in the check sequence below is important.
 5813|       |          //  strncmp() must go first: it fails fast if the remaining length
 5814|       |          //  of the path is smaller than `n`.
 5815|  11.6k|          if (depth == ed && path[pos - 1] == '.' &&
  ------------------
  |  Branch (5815:15): [True: 3.11k, False: 8.52k]
  |  Branch (5815:30): [True: 3.11k, False: 0]
  ------------------
 5816|  3.11k|              strncmp(&s[i + 1], &path[pos], (size_t) n) == 0 &&
  ------------------
  |  Branch (5816:15): [True: 1.07k, False: 2.04k]
  ------------------
 5817|  1.07k|              (path[pos + n] == '\0' || path[pos + n] == '.' ||
  ------------------
  |  Branch (5817:16): [True: 2, False: 1.07k]
  |  Branch (5817:41): [True: 7, False: 1.06k]
  ------------------
 5818|  1.06k|               path[pos + n] == '[')) {
  ------------------
  |  Branch (5818:16): [True: 0, False: 1.06k]
  ------------------
 5819|      9|            pos += n;
 5820|      9|          }
 5821|  11.6k|          i += n + 1;
 5822|  11.6k|          expecting = S_COLON;
 5823|  11.6k|        } else if (c == '}') {  // Empty object
  ------------------
  |  Branch (5823:20): [True: 3.01k, False: 107]
  ------------------
 5824|  3.01k|          MG_EOO('}');
  ------------------
  |  | 5744|  3.01k|  do {                                                       \
  |  | 5745|  3.01k|    if (depth == ed && ci != ei) return MG_JSON_NOT_FOUND;   \
  |  |  ------------------
  |  |  |  Branch (5745:9): [True: 13, False: 2.99k]
  |  |  |  Branch (5745:24): [True: 0, False: 13]
  |  |  ------------------
  |  | 5746|  3.01k|    if (c != nesting[depth - 1] + 2) return MG_JSON_INVALID; \
  |  |  ------------------
  |  |  |  Branch (5746:9): [True: 0, False: 3.01k]
  |  |  ------------------
  |  | 5747|  3.01k|    depth--;                                                 \
  |  | 5748|  3.01k|    MG_CHECKRET(x);                                          \
  |  |  ------------------
  |  |  |  | 5734|  3.01k|  do {                                                  \
  |  |  |  | 5735|  3.01k|    if (depth == ed && path[pos] == '\0' && ci == ei) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (5735:9): [True: 691, False: 2.32k]
  |  |  |  |  |  Branch (5735:24): [True: 16, False: 675]
  |  |  |  |  |  Branch (5735:45): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 5736|     16|      if (toklen) *toklen = i - j + 1;                  \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (5736:11): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 5737|     16|      return j;                                         \
  |  |  |  | 5738|     16|    }                                                   \
  |  |  |  | 5739|  3.01k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (5739:12): [Folded, False: 2.99k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 5749|  3.01k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (5749:12): [Folded, False: 2.99k]
  |  |  ------------------
  ------------------
 5825|  2.99k|          expecting = S_COMMA_OR_EOO;
 5826|  2.99k|          if (depth == ed && ei >= 0) ci++;
  ------------------
  |  Branch (5826:15): [True: 675, False: 2.32k]
  |  Branch (5826:30): [True: 0, False: 675]
  ------------------
 5827|  2.99k|        } else {
 5828|    107|          return MG_JSON_INVALID;
 5829|    107|        }
 5830|  14.6k|        break;
 5831|       |
 5832|  14.6k|      case S_COLON:
  ------------------
  |  Branch (5832:7): [True: 11.4k, False: 603k]
  ------------------
 5833|  11.4k|        if (c == ':') {
  ------------------
  |  Branch (5833:13): [True: 11.2k, False: 210]
  ------------------
 5834|  11.2k|          expecting = S_VALUE;
 5835|  11.2k|        } else {
 5836|    210|          return MG_JSON_INVALID;
 5837|    210|        }
 5838|  11.2k|        break;
 5839|       |
 5840|   280k|      case S_COMMA_OR_EOO:
  ------------------
  |  Branch (5840:7): [True: 280k, False: 334k]
  ------------------
 5841|   280k|        if (depth <= 0) {
  ------------------
  |  Branch (5841:13): [True: 918, False: 279k]
  ------------------
 5842|    918|          return MG_JSON_INVALID;
 5843|   279k|        } else if (c == ',') {
  ------------------
  |  Branch (5843:20): [True: 273k, False: 6.70k]
  ------------------
 5844|   273k|          expecting = (nesting[depth - 1] == '{') ? S_KEY : S_VALUE;
  ------------------
  |  Branch (5844:23): [True: 9.43k, False: 263k]
  ------------------
 5845|   273k|        } else if (c == ']' || c == '}') {
  ------------------
  |  Branch (5845:20): [True: 5.36k, False: 1.33k]
  |  Branch (5845:32): [True: 1.10k, False: 234]
  ------------------
 5846|  6.46k|          if (depth == ed && c == '}' && path[pos - 1] == '.')
  ------------------
  |  Branch (5846:15): [True: 18, False: 6.45k]
  |  Branch (5846:30): [True: 15, False: 3]
  |  Branch (5846:42): [True: 14, False: 1]
  ------------------
 5847|     14|            return MG_JSON_NOT_FOUND;
 5848|  6.45k|          if (depth == ed && c == ']' && path[pos - 1] == ',')
  ------------------
  |  Branch (5848:15): [True: 4, False: 6.45k]
  |  Branch (5848:30): [True: 3, False: 1]
  |  Branch (5848:42): [True: 0, False: 3]
  ------------------
 5849|      0|            return MG_JSON_NOT_FOUND;
 5850|  6.45k|          MG_EOO('O');
  ------------------
  |  | 5744|  6.45k|  do {                                                       \
  |  | 5745|  6.45k|    if (depth == ed && ci != ei) return MG_JSON_NOT_FOUND;   \
  |  |  ------------------
  |  |  |  Branch (5745:9): [True: 4, False: 6.45k]
  |  |  |  Branch (5745:24): [True: 0, False: 4]
  |  |  ------------------
  |  | 5746|  6.45k|    if (c != nesting[depth - 1] + 2) return MG_JSON_INVALID; \
  |  |  ------------------
  |  |  |  Branch (5746:9): [True: 16, False: 6.43k]
  |  |  ------------------
  |  | 5747|  6.45k|    depth--;                                                 \
  |  | 5748|  6.43k|    MG_CHECKRET(x);                                          \
  |  |  ------------------
  |  |  |  | 5734|  6.43k|  do {                                                  \
  |  |  |  | 5735|  6.43k|    if (depth == ed && path[pos] == '\0' && ci == ei) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (5735:9): [True: 902, False: 5.53k]
  |  |  |  |  |  Branch (5735:24): [True: 53, False: 849]
  |  |  |  |  |  Branch (5735:45): [True: 53, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 5736|     53|      if (toklen) *toklen = i - j + 1;                  \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (5736:11): [True: 53, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 5737|     53|      return j;                                         \
  |  |  |  | 5738|     53|    }                                                   \
  |  |  |  | 5739|  6.43k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (5739:12): [Folded, False: 6.38k]
  |  |  |  |  ------------------
  |  |  ------------------
  |  | 5749|  6.43k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (5749:12): [Folded, False: 6.38k]
  |  |  ------------------
  ------------------
 5851|  6.38k|          if (depth == ed && ei >= 0) ci++;
  ------------------
  |  Branch (5851:15): [True: 849, False: 5.53k]
  |  Branch (5851:30): [True: 0, False: 849]
  ------------------
 5852|  6.38k|        } else {
 5853|    234|          return MG_JSON_INVALID;
 5854|    234|        }
 5855|   279k|        break;
 5856|   615k|    }
 5857|   615k|  }
 5858|  1.20k|  return MG_JSON_NOT_FOUND;
 5859|  18.3k|}
_Z10mg_l2_initP11mg_tcpip_if:
 6206|  6.10k|void mg_l2_init(struct mg_tcpip_if *ifp) {
 6207|  6.10k|  l2_init[ifp->l2type](ifp);
 6208|  6.10k|}
_Z10mg_l2_pollP11mg_tcpip_ifb:
 6210|  6.10k|bool mg_l2_poll(struct mg_tcpip_if *ifp, bool expired_1000ms) {
 6211|  6.10k|  return l2_poll[ifp->l2type](ifp, expired_1000ms);
 6212|  6.10k|}
_Z12mg_l2_headerP11mg_tcpip_if10mg_l2protoPhS2_S2_:
 6215|  6.10k|                      uint8_t *src, uint8_t *dst, uint8_t *frame) {
 6216|  6.10k|  return l2_header[ifp->l2type](ifp, proto, (struct mg_l2addr *) src,
 6217|  6.10k|                                (struct mg_l2addr *) dst, frame);
 6218|  6.10k|}
_Z13mg_l2_trailerP11mg_tcpip_ifmPh:
 6220|  6.10k|size_t mg_l2_trailer(struct mg_tcpip_if *ifp, size_t len, uint8_t *frame) {
 6221|  6.10k|  return l2_trailer[ifp->l2type](ifp, len, frame);
 6222|  6.10k|}
_Z8mg_l2_rxP11mg_tcpip_ifP10mg_l2protoP6mg_strS4_:
 6225|  6.10k|              struct mg_str *pay, struct mg_str *raw) {
 6226|  6.10k|  return l2_rx[ifp->l2type](ifp, proto, pay, raw);
 6227|  6.10k|}
_Z19mg_l2_driver_outputP11mg_tcpip_ifm:
 6255|  1.26k|size_t mg_l2_driver_output(struct mg_tcpip_if *ifp, size_t len) {
 6256|  1.26k|  size_t n = ifp->driver->tx(ifp->tx.buf, len, ifp);
 6257|  1.26k|  if (n == len) ifp->nsent++;
  ------------------
  |  Branch (6257:7): [True: 1.26k, False: 0]
  ------------------
 6258|  1.26k|  return n;
 6259|  1.26k|}
_Z14mg_l2_eth_initP11mg_tcpip_if:
 6308|  4.06k|void mg_l2_eth_init(struct mg_tcpip_if *ifp) {
 6309|  4.06k|  struct mg_l2addr *l2addr = (struct mg_l2addr *) ifp->mac;
 6310|       |  // If MAC is not set, make a random one
 6311|  4.06k|  if (l2addr->addr.mac[0] == 0 && l2addr->addr.mac[1] == 0 &&
  ------------------
  |  Branch (6311:7): [True: 4.06k, False: 0]
  |  Branch (6311:35): [True: 4.06k, False: 0]
  ------------------
 6312|  4.06k|      l2addr->addr.mac[2] == 0 && l2addr->addr.mac[3] == 0 &&
  ------------------
  |  Branch (6312:7): [True: 4.06k, False: 0]
  |  Branch (6312:35): [True: 4.06k, False: 0]
  ------------------
 6313|  4.06k|      l2addr->addr.mac[4] == 0 && l2addr->addr.mac[5] == 0) {
  ------------------
  |  Branch (6313:7): [True: 4.06k, False: 0]
  |  Branch (6313:35): [True: 4.06k, False: 0]
  ------------------
 6314|  4.06k|    l2addr->addr.mac[0] = 0x02;  // Locally administered, unicast
 6315|  4.06k|    mg_random(&l2addr->addr.mac[1], sizeof(l2addr->addr.mac) - 1);
 6316|  4.06k|    MG_INFO(
  ------------------
  |  | 1803|  4.06k|#define MG_INFO(args) MG_LOG(MG_LL_INFO, args)
  |  |  ------------------
  |  |  |  | 1792|  4.06k|  do {                      \
  |  |  |  | 1793|  4.06k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 4.06k]
  |  |  |  |  ------------------
  |  |  |  | 1794|  4.06k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 4.06k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6317|  4.06k|        ("MAC not set. Generated random: %M", mg_print_mac, l2addr->addr.mac));
 6318|  4.06k|  }
 6319|  4.06k|  ifp->l2mtu = 1500;
 6320|  4.06k|  ifp->framesize = 1540;
 6321|  4.06k|}
_Z14mg_l2_eth_pollP11mg_tcpip_ifb:
 6323|  2.03k|bool mg_l2_eth_poll(struct mg_tcpip_if *ifp, bool expired_1000ms) {
 6324|  2.03k|  (void) ifp;
 6325|  2.03k|  (void) expired_1000ms;
 6326|  2.03k|  return true;
 6327|  2.03k|}
_Z16mg_l2_eth_headerP11mg_tcpip_if10mg_l2protoP9mg_l2addrS3_Ph:
 6331|  4.07k|                          uint8_t *frame) {
 6332|  4.07k|  struct eth_data *d = &ifp->l2data.eth;
 6333|  4.07k|  struct eth *eth = (struct eth *) frame;
 6334|  4.07k|  uint8_t *hlp;
 6335|  4.07k|  hlp = (uint8_t *) (eth + 1);
 6336|  4.07k|  memcpy(eth->src, src->addr.mac, sizeof(eth->dst));
 6337|  4.07k|  memcpy(eth->dst, dst->addr.mac, sizeof(eth->dst));
 6338|  4.07k|  if (d->vlan_id == 0) {  // Traditional plain frame
  ------------------
  |  Branch (6338:7): [True: 3.22k, False: 851]
  ------------------
 6339|  3.22k|    eth->type = mg_htons(eth_types[(unsigned int) proto]);
  ------------------
  |  | 2093|  3.22k|#define mg_htons(x) mg_ntohs(x)
  ------------------
 6340|  3.22k|  } else {  // Add 802.1Q tag
 6341|    851|    struct qtag *qtag = (struct qtag *) &eth->type;
 6342|    851|    qtag->tpid = mg_htons(0x8100);
  ------------------
  |  | 2093|    851|#define mg_htons(x) mg_ntohs(x)
  ------------------
 6343|    851|    qtag->tci = mg_htons(d->vlan_id);  // PCP = default (best-effort)
  ------------------
  |  | 2093|    851|#define mg_htons(x) mg_ntohs(x)
  ------------------
 6344|    851|    hlp += sizeof(*qtag);
 6345|    851|    MG_STORE_BE16(qtag + 1, eth_types[(unsigned int) proto]);
  ------------------
  |  | 2039|    851|  do {                                    \
  |  | 2040|    851|    MG_U8P(p)[0] = (uint8_t) ((n) >> 8U); \
  |  |  ------------------
  |  |  |  | 2012|    851|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  | 2041|    851|    MG_U8P(p)[1] = (uint8_t) (n);         \
  |  |  ------------------
  |  |  |  | 2012|    851|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  | 2042|    851|  } while (0)
  |  |  ------------------
  |  |  |  Branch (2042:12): [Folded, False: 851]
  |  |  ------------------
  ------------------
 6346|    851|  }
 6347|  4.07k|  return hlp;
 6348|  4.07k|}
_Z17mg_l2_eth_trailerP11mg_tcpip_ifmPh:
 6350|  4.07k|size_t mg_l2_eth_trailer(struct mg_tcpip_if *ifp, size_t len, uint8_t *cur) {
 6351|  4.07k|  struct eth_data *d = &ifp->l2data.eth;
 6352|       |  // there is no len field in Ethernet, CRC is hw-calculated; pad to 64 - CRC
 6353|  4.07k|  size_t ethlen =
 6354|  4.07k|      len + sizeof(struct eth) + (d->vlan_id != 0 ? sizeof(struct qtag) : 0);
  ------------------
  |  Branch (6354:35): [True: 851, False: 3.22k]
  ------------------
 6355|  4.07k|  (void) cur;
 6356|  4.07k|  return ethlen >= 60 ? ethlen : 60;
  ------------------
  |  Branch (6356:10): [True: 2.31k, False: 1.75k]
  ------------------
 6357|  4.07k|}
_Z12mg_l2_eth_rxP11mg_tcpip_ifP10mg_l2protoP6mg_strS4_:
 6363|  4.06k|                  struct mg_str *pay, struct mg_str *raw) {
 6364|  4.06k|  struct eth *eth = (struct eth *) raw->buf;
 6365|  4.06k|  struct eth_data *d = &ifp->l2data.eth;
 6366|  4.06k|  uint16_t type, len;
 6367|  4.06k|  unsigned int i;
 6368|  4.06k|  size_t hdrlen =
 6369|  4.06k|      sizeof(struct eth) + (d->vlan_id != 0 ? sizeof(struct qtag) : 0);
  ------------------
  |  Branch (6369:29): [True: 851, False: 3.21k]
  ------------------
 6370|  4.06k|  if (raw->len < hdrlen) return false;  // Truncated - runt?
  ------------------
  |  Branch (6370:7): [True: 1.21k, False: 2.85k]
  ------------------
 6371|  2.85k|  len = (uint16_t) raw->len;
 6372|  2.85k|  if (d->vlan_id == 0) {  // We don't handle VLANs
  ------------------
  |  Branch (6372:7): [True: 2.07k, False: 783]
  ------------------
 6373|  2.07k|    type = mg_ntohs(eth->type);
 6374|  2.07k|  } else {  // We do, check 802.1Q tag
 6375|    783|    struct qtag *qtag = (struct qtag *) &eth->type;
 6376|    783|    if (qtag->tpid != mg_htons(0x8100)) return false;  // Untagged frame
  ------------------
  |  | 2093|    783|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (6376:9): [True: 272, False: 511]
  ------------------
 6377|    511|    if (VLAN_ID(mg_ntohs(qtag->tci)) != VLAN_ID(d->vlan_id))
  ------------------
  |  | 6290|    511|#define VLAN_ID(x) ((uint16_t) ((x) &0x0FFF))
  ------------------
                  if (VLAN_ID(mg_ntohs(qtag->tci)) != VLAN_ID(d->vlan_id))
  ------------------
  |  | 6290|    511|#define VLAN_ID(x) ((uint16_t) ((x) &0x0FFF))
  ------------------
  |  Branch (6377:9): [True: 255, False: 256]
  ------------------
 6378|    255|      return false;  // Not our VLAN
 6379|    256|    type = MG_LOAD_BE16(qtag + 1);
  ------------------
  |  | 2019|    256|  ((uint16_t) (((uint16_t) MG_U8P(p)[0] << 8U) | MG_U8P(p)[1]))
  |  |  ------------------
  |  |  |  | 2012|    256|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  |                 ((uint16_t) (((uint16_t) MG_U8P(p)[0] << 8U) | MG_U8P(p)[1]))
  |  |  ------------------
  |  |  |  | 2012|    256|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  ------------------
 6380|    256|  }
 6381|  2.32k|  if (ifp->enable_mac_check &&
  ------------------
  |  Branch (6381:7): [True: 0, False: 2.32k]
  ------------------
 6382|      0|      memcmp(eth->dst, ifp->mac, sizeof(eth->dst)) != 0 &&
  ------------------
  |  Branch (6382:7): [True: 0, False: 0]
  ------------------
 6383|      0|      memcmp(eth->dst, mg_l2_eth_mapip(MG_TCPIP_L2ADDR_BCAST, NULL),
  ------------------
  |  Branch (6383:7): [True: 0, False: 0]
  ------------------
 6384|      0|             sizeof(eth->dst)) != 0)
 6385|      0|    return false;  // TODO(): add multicast addresses
 6386|  2.32k|  if (ifp->enable_fcs_check && len > hdrlen + 4) {
  ------------------
  |  Branch (6386:7): [True: 0, False: 2.32k]
  |  Branch (6386:32): [True: 0, False: 0]
  ------------------
 6387|      0|    uint32_t crc, crc_rx;
 6388|      0|    len -= 4;
 6389|      0|    crc = mg_crc32(0, (const char *) raw->buf, len);
 6390|      0|    crc_rx = MG_LOAD_LE32(raw->buf + len);
  ------------------
  |  | 2072|      0|  ((uint32_t) (((uint32_t) MG_U8P(p)[3] << 24U) | \
  |  |  ------------------
  |  |  |  | 2012|      0|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  | 2073|      0|               ((uint32_t) MG_U8P(p)[2] << 16U) | \
  |  |  ------------------
  |  |  |  | 2012|      0|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  | 2074|      0|               ((uint32_t) MG_U8P(p)[1] << 8U) | MG_U8P(p)[0]))
  |  |  ------------------
  |  |  |  | 2012|      0|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  |                              ((uint32_t) MG_U8P(p)[1] << 8U) | MG_U8P(p)[0]))
  |  |  ------------------
  |  |  |  | 2012|      0|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  ------------------
 6391|      0|    if (crc_rx != crc)
  ------------------
  |  Branch (6391:9): [True: 0, False: 0]
  ------------------
 6392|      0|      return false;
 6393|      0|  }
 6394|  2.32k|  pay->buf = ((char *) eth) + hdrlen;
 6395|  2.32k|  pay->len = len - hdrlen;
 6396|  2.32k|  if (len > ifp->framesize) return false;  // Oversized
  ------------------
  |  Branch (6396:7): [True: 486, False: 1.84k]
  ------------------
 6397|  10.4k|  for (i = 0; i < sizeof(eth_types) / sizeof(uint16_t); i++) {
  ------------------
  |  Branch (6397:15): [True: 8.80k, False: 1.66k]
  ------------------
 6398|  8.80k|    if (type == eth_types[i]) break;
  ------------------
  |  Branch (6398:9): [True: 173, False: 8.63k]
  ------------------
 6399|  8.80k|  }
 6400|  1.84k|  if (i == sizeof(eth_types) / sizeof(eth_types[0])) {
  ------------------
  |  Branch (6400:7): [True: 1.66k, False: 173]
  ------------------
 6401|  1.66k|    MG_DEBUG(("Unknown eth type %x", type));
  ------------------
  |  | 1804|  1.66k|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|  1.66k|  do {                      \
  |  |  |  | 1793|  1.66k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 1.66k]
  |  |  |  |  ------------------
  |  |  |  | 1794|  1.66k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 1.66k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6402|  1.66k|    if (mg_log_level >= MG_LL_VERBOSE)
  ------------------
  |  Branch (6402:9): [True: 0, False: 1.66k]
  ------------------
 6403|      0|      mg_hexdump(raw->buf, raw->len >= 32 ? 32 : raw->len);
  ------------------
  |  Branch (6403:28): [True: 0, False: 0]
  ------------------
 6404|  1.66k|    return false;
 6405|  1.66k|  }
 6406|    173|  *proto = (enum mg_l2proto) i;
 6407|    173|  return true;
 6408|  1.84k|}
_Z17mg_l2_eth_getaddrP11mg_tcpip_ifPh:
 6410|      1|struct mg_l2addr *mg_l2_eth_getaddr(struct mg_tcpip_if *ifp, uint8_t *frame) {
 6411|      1|  struct eth *eth = (struct eth *) frame; 
 6412|      1|  (void) ifp; // address field is before a possible 802.1Q tag
 6413|      1|  return (struct mg_l2addr *) &eth->src;
 6414|      1|}
_Z14mg_l2_ppp_initP11mg_tcpip_if:
 6582|  2.03k|void mg_l2_ppp_init(struct mg_tcpip_if *ifp) {
 6583|  2.03k|  ifp->l2mtu = 1500;
 6584|  2.03k|  ifp->framesize = ifp->l2mtu + sizeof(struct ppp) + sizeof(struct hdlc_) + 2;
 6585|  2.03k|}
_Z16mg_l2_pppoe_initP11mg_tcpip_if:
 6589|  2.03k|void mg_l2_pppoe_init(struct mg_tcpip_if *ifp) {
 6590|  2.03k|  mg_l2_eth_init(ifp);
 6591|  2.03k|  ifp->l2mtu = ifp->l2mtu - (uint16_t) (sizeof(struct pppoe) +
 6592|  2.03k|                                    sizeof(struct ppp));  // 1500 --> 1492
 6593|  2.03k|}
_Z14mg_l2_ppp_pollP11mg_tcpip_ifb:
 6595|  4.06k|bool mg_l2_ppp_poll(struct mg_tcpip_if *ifp, bool expired_1000ms) {
 6596|  4.06k|  if (expired_1000ms && ifp->state == MG_TCPIP_STATE_DOWN) s_lcpup = false;
  ------------------
  |  | 4861|  4.06k|#define MG_TCPIP_STATE_DOWN 0       // Physical link is down
  ------------------
  |  Branch (6596:7): [True: 4.06k, False: 0]
  |  Branch (6596:25): [True: 0, False: 4.06k]
  ------------------
 6597|  4.06k|  return s_lcpup;
 6598|  4.06k|}
_Z16mg_l2_ppp_headerP11mg_tcpip_if10mg_l2protoP9mg_l2addrS3_Ph:
 6622|  2.03k|                          uint8_t *frame) {
 6623|  2.03k|  (void) ifp;
 6624|  2.03k|  (void) src;
 6625|  2.03k|  (void) dst;
 6626|  2.03k|  return l2_ppp_header(proto, hdlc_header(frame));
 6627|  2.03k|}
_Z18mg_l2_pppoe_headerP11mg_tcpip_if10mg_l2protoP9mg_l2addrS3_Ph:
 6646|  2.03k|                            uint8_t *frame) {
 6647|  2.03k|  (void) dst;
 6648|  2.03k|  return l2_ppp_header(proto, pppoe_header(ifp, MG_TCPIP_L2PROTO_PPPoE_SESS, 0,
 6649|  2.03k|                                           s_id, src, dst, frame));
 6650|  2.03k|}
_Z17mg_l2_ppp_trailerP11mg_tcpip_ifmPh:
 6652|  3.29k|size_t mg_l2_ppp_trailer(struct mg_tcpip_if *ifp, size_t len, uint8_t *cur) {
 6653|  3.29k|  uint16_t crc;
 6654|  3.29k|  uint8_t *frame;
 6655|  3.29k|  len += sizeof(struct ppp) + sizeof(struct hdlc_);
 6656|  3.29k|  frame = cur - len;
 6657|  3.29k|  crc = mg_crc16(0, (const char *) frame, len);
 6658|  3.29k|  *cur++ = (uint8_t) crc;  // add CRC, note the byte order
 6659|  3.29k|  *cur++ = (uint8_t) (crc >> 8);
 6660|       |  // there is no len field in PPP
 6661|  3.29k|  (void) ifp;
 6662|  3.29k|  return len + 2;
 6663|  3.29k|}
_Z19mg_l2_pppoe_trailerP11mg_tcpip_ifmPh:
 6673|  2.03k|size_t mg_l2_pppoe_trailer(struct mg_tcpip_if *ifp, size_t len, uint8_t *cur) {
 6674|  2.03k|  return pppoe_trailer(ifp, len + sizeof(struct ppp), cur);
 6675|  2.03k|}
_Z12mg_l2_ppp_rxP11mg_tcpip_ifP10mg_l2protoP6mg_strS4_:
 6939|  2.03k|                  struct mg_str *pay, struct mg_str *raw) {
 6940|  2.03k|  struct hdlc_ *hdlc = (struct hdlc_ *) raw->buf;
 6941|  2.03k|  if (raw->len < sizeof(*hdlc) + 2) return false;  // Truncated
  ------------------
  |  Branch (6941:7): [True: 158, False: 1.87k]
  ------------------
 6942|  1.87k|  if (hdlc->addr == MG_PPP_ADDR && hdlc->ctrl == MG_PPP_CTRL) {
  ------------------
  |  | 6532|  3.75k|#define MG_PPP_ADDR 0xff
  ------------------
                if (hdlc->addr == MG_PPP_ADDR && hdlc->ctrl == MG_PPP_CTRL) {
  ------------------
  |  | 6533|  1.69k|#define MG_PPP_CTRL 0x03
  ------------------
  |  Branch (6942:7): [True: 1.69k, False: 182]
  |  Branch (6942:36): [True: 1.69k, False: 3]
  ------------------
 6943|  1.69k|    pay->buf = (char *) (hdlc + 1);
 6944|  1.69k|    pay->len = raw->len - sizeof(*hdlc) - 2;
 6945|  1.69k|  } else {  // Address-and-Control-Field-Compressed PPP header
 6946|    185|    pay->buf = (char *) raw->buf;
 6947|    185|    pay->len = raw->len - 2;
 6948|    185|  }
 6949|  1.87k|  if (pay->len > ifp->l2mtu + sizeof(struct ppp)) return false;  // Oversized
  ------------------
  |  Branch (6949:7): [True: 376, False: 1.50k]
  ------------------
 6950|  1.50k|  return ppp_rx(ifp, proto, pay, raw);
 6951|  1.87k|}
_Z16mg_l2_pppoe_pollP11mg_tcpip_ifb:
 7005|  2.03k|bool mg_l2_pppoe_poll(struct mg_tcpip_if *ifp, bool expired_1000ms) {
 7006|  2.03k|  if (expired_1000ms && s_state == MG_PPPoE_ST_DISC &&
  ------------------
  |  | 6571|  4.06k|#define MG_PPPoE_ST_DISC 0  // Discovery phase, see what servers are out there
  ------------------
  |  Branch (7006:7): [True: 2.03k, False: 0]
  |  Branch (7006:25): [True: 1.40k, False: 630]
  ------------------
 7007|  1.40k|      ifp->state == MG_TCPIP_STATE_LINK_UP) {
  ------------------
  |  | 4862|  1.40k|#define MG_TCPIP_STATE_LINK_UP 1    // Driver reports physical link is up
  ------------------
  |  Branch (7007:7): [True: 0, False: 1.40k]
  ------------------
 7008|      0|    uint16_t tags[2];
 7009|      0|    tags[0] = mg_htons(0x0101);  // Service Request
  ------------------
  |  | 2093|      0|#define mg_htons(x) mg_ntohs(x)
  ------------------
 7010|      0|    tags[1] = mg_htons(0x0000);  // Any
  ------------------
  |  | 2093|      0|#define mg_htons(x) mg_ntohs(x)
  ------------------
 7011|      0|    pppoe_tx_frame(ifp, MG_PPPoE_PADI, 0, (uint8_t *) tags, sizeof(tags),
  ------------------
  |  | 6565|      0|#define MG_PPPoE_PADI 0x09
  ------------------
 7012|      0|                   mg_l2_eth_mapip(MG_TCPIP_L2ADDR_BCAST, NULL));
 7013|      0|    MG_DEBUG(("Sent PADI"));
  ------------------
  |  | 1804|      0|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7014|  2.03k|  } else if (expired_1000ms && (s_state != MG_PPPoE_ST_SESS ||
  ------------------
  |  | 6573|  4.06k|#define MG_PPPoE_ST_SESS 2  // Session established, PPP traffic is exchanged
  ------------------
  |  Branch (7014:14): [True: 2.03k, False: 0]
  |  Branch (7014:33): [True: 1.42k, False: 609]
  ------------------
 7015|  1.42k|                                ifp->state == MG_TCPIP_STATE_DOWN)) {
  ------------------
  |  | 4861|    609|#define MG_TCPIP_STATE_DOWN 0       // Physical link is down
  ------------------
  |  Branch (7015:33): [True: 0, False: 609]
  ------------------
 7016|  1.42k|    s_state = MG_PPPoE_ST_DISC;
  ------------------
  |  | 6571|  1.42k|#define MG_PPPoE_ST_DISC 0  // Discovery phase, see what servers are out there
  ------------------
 7017|  1.42k|  }
 7018|  2.03k|  return mg_l2_ppp_poll(ifp, expired_1000ms);
 7019|  2.03k|}
_Z14mg_l2_pppoe_rxP11mg_tcpip_ifP10mg_l2protoP6mg_strS4_:
 7026|  2.03k|                    struct mg_str *pay, struct mg_str *raw) {
 7027|  2.03k|  enum mg_l2proto eth_proto;  // raw is handled by eth
 7028|  2.03k|  struct pppoe *pppoe;
 7029|  2.03k|  if (!mg_l2_eth_rx(ifp, &eth_proto, pay, raw)) return false;
  ------------------
  |  Branch (7029:7): [True: 1.95k, False: 80]
  ------------------
 7030|     80|  pppoe = (struct pppoe *) pay->buf;            // here we handle pay, not raw
 7031|     80|  if (pay->len < sizeof(*pppoe)) return false;  // Truncated
  ------------------
  |  Branch (7031:7): [True: 4, False: 76]
  ------------------
 7032|     76|  if (pay->len - sizeof(*pppoe) > ifp->l2mtu + sizeof(struct ppp))
  ------------------
  |  Branch (7032:7): [True: 7, False: 69]
  ------------------
 7033|      7|    return false;  // Oversized
 7034|     69|  if (eth_proto == MG_TCPIP_L2PROTO_PPPoE_DISC) {
  ------------------
  |  Branch (7034:7): [True: 15, False: 54]
  ------------------
 7035|     15|    MG_VERBOSE(("PPPoE_DISC"));
  ------------------
  |  | 1805|     15|#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)
  |  |  ------------------
  |  |  |  | 1792|     15|  do {                      \
  |  |  |  | 1793|     15|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  |  | 1794|     15|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7036|     15|    if (s_state == MG_PPPoE_ST_DISC && pppoe->code == MG_PPPoE_PADO &&
  ------------------
  |  | 6571|     30|#define MG_PPPoE_ST_DISC 0  // Discovery phase, see what servers are out there
  ------------------
                  if (s_state == MG_PPPoE_ST_DISC && pppoe->code == MG_PPPoE_PADO &&
  ------------------
  |  | 6566|     20|#define MG_PPPoE_PADO 0x07
  ------------------
  |  Branch (7036:9): [True: 5, False: 10]
  |  Branch (7036:40): [True: 1, False: 4]
  ------------------
 7037|      1|        pppoe->id == 0) {
  ------------------
  |  Branch (7037:9): [True: 1, False: 0]
  ------------------
 7038|      1|      uint16_t tags[2];
 7039|      1|      bool has_cookie = false;
 7040|      1|      size_t len = pay->len - sizeof(*pppoe);
 7041|      1|      uint8_t *p = (uint8_t *) (pppoe + 1);
 7042|      1|      uint16_t taglen;
 7043|     28|      while (len >= 4) {  // parse tags for a possible AC-Cookie
  ------------------
  |  Branch (7043:14): [True: 27, False: 1]
  ------------------
 7044|     27|        uint16_t curtag = MG_LOAD_BE16(p);
  ------------------
  |  | 2019|     27|  ((uint16_t) (((uint16_t) MG_U8P(p)[0] << 8U) | MG_U8P(p)[1]))
  |  |  ------------------
  |  |  |  | 2012|     27|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  |                 ((uint16_t) (((uint16_t) MG_U8P(p)[0] << 8U) | MG_U8P(p)[1]))
  |  |  ------------------
  |  |  |  | 2012|     27|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  ------------------
 7045|     27|        taglen = MG_LOAD_BE16(p + 2);
  ------------------
  |  | 2019|     27|  ((uint16_t) (((uint16_t) MG_U8P(p)[0] << 8U) | MG_U8P(p)[1]))
  |  |  ------------------
  |  |  |  | 2012|     27|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  |                 ((uint16_t) (((uint16_t) MG_U8P(p)[0] << 8U) | MG_U8P(p)[1]))
  |  |  ------------------
  |  |  |  | 2012|     27|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  ------------------
 7046|     27|        if (taglen > len - 4) return false;  // truncated / malformed
  ------------------
  |  Branch (7046:13): [True: 0, False: 27]
  ------------------
 7047|     27|        if (curtag == 0x0104) {
  ------------------
  |  Branch (7047:13): [True: 0, False: 27]
  ------------------
 7048|      0|          has_cookie = true;
 7049|      0|          break;
 7050|      0|        }
 7051|     27|        len -= 4 + taglen;
 7052|     27|        p += 4 + taglen;
 7053|     27|      }
 7054|      1|      tags[0] = mg_htons(0x0101);  // Service Request
  ------------------
  |  | 2093|      1|#define mg_htons(x) mg_ntohs(x)
  ------------------
 7055|      1|      tags[1] = mg_htons(0x0000);  // Any
  ------------------
  |  | 2093|      1|#define mg_htons(x) mg_ntohs(x)
  ------------------
 7056|      1|      if (has_cookie) {  // copy tags to before AC-Cookie tag in rx buffer
  ------------------
  |  Branch (7056:11): [True: 0, False: 1]
  ------------------
 7057|      0|        memcpy(p -= sizeof(tags), tags, sizeof(tags));  // point to all tags
 7058|      0|        taglen += 4 + sizeof(tags);                     // account for tags
 7059|      1|      } else {
 7060|      1|        p = (uint8_t *) tags;
 7061|      1|        taglen = sizeof(tags);
 7062|      1|      }
 7063|      1|      pppoe_tx_frame(ifp, MG_PPPoE_PADR, 0, p, taglen,
  ------------------
  |  | 6567|      1|#define MG_PPPoE_PADR 0x19
  ------------------
 7064|      1|                     mg_l2_eth_getaddr(ifp, (uint8_t *) raw->buf));
 7065|      1|      MG_DEBUG(("Sent PADR"));
  ------------------
  |  | 1804|      1|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|      1|  do {                      \
  |  |  |  | 1793|      1|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  |  | 1794|      1|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7066|      1|      s_state = MG_PPPoE_ST_REQ;
  ------------------
  |  | 6572|      1|#define MG_PPPoE_ST_REQ 1   // Chose a server, request a session and wait
  ------------------
 7067|     14|    } else if (s_state == MG_PPPoE_ST_REQ && pppoe->code == MG_PPPoE_PADS) {
  ------------------
  |  | 6572|     28|#define MG_PPPoE_ST_REQ 1   // Chose a server, request a session and wait
  ------------------
                  } else if (s_state == MG_PPPoE_ST_REQ && pppoe->code == MG_PPPoE_PADS) {
  ------------------
  |  | 6568|      0|#define MG_PPPoE_PADS 0x65
  ------------------
  |  Branch (7067:16): [True: 0, False: 14]
  |  Branch (7067:46): [True: 0, False: 0]
  ------------------
 7068|      0|      s_id = pppoe->id;
 7069|      0|      memcpy(&ifp->gwmac,
 7070|      0|             mg_l2_eth_getaddr(ifp, (uint8_t *) raw->buf)->addr.mac, 6);
 7071|      0|      MG_DEBUG(("PPPoE session 0x%04x started", mg_ntohs(s_id)));
  ------------------
  |  | 1804|      0|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7072|      0|      s_state = MG_PPPoE_ST_SESS;
  ------------------
  |  | 6573|      0|#define MG_PPPoE_ST_SESS 2  // Session established, PPP traffic is exchanged
  ------------------
 7073|     14|    } else if (s_state == MG_PPPoE_ST_SESS && pppoe->code == MG_PPPoE_PADT &&
  ------------------
  |  | 6573|     28|#define MG_PPPoE_ST_SESS 2  // Session established, PPP traffic is exchanged
  ------------------
                  } else if (s_state == MG_PPPoE_ST_SESS && pppoe->code == MG_PPPoE_PADT &&
  ------------------
  |  | 6569|     24|#define MG_PPPoE_PADT 0xa7
  ------------------
  |  Branch (7073:16): [True: 10, False: 4]
  |  Branch (7073:47): [True: 1, False: 9]
  ------------------
 7074|      1|               pppoe->id == s_id) {
  ------------------
  |  Branch (7074:16): [True: 0, False: 1]
  ------------------
 7075|      0|      MG_ERROR(("Got PADT"));
  ------------------
  |  | 1802|      0|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7076|      0|      s_id = 0;
 7077|      0|      s_lcpup = false;
 7078|      0|      s_state = MG_PPPoE_ST_DISC;
  ------------------
  |  | 6571|      0|#define MG_PPPoE_ST_DISC 0  // Discovery phase, see what servers are out there
  ------------------
 7079|      0|    }
 7080|     54|  } else if (eth_proto == MG_TCPIP_L2PROTO_PPPoE_SESS &&
  ------------------
  |  Branch (7080:14): [True: 8, False: 46]
  ------------------
 7081|      8|             s_state == MG_PPPoE_ST_SESS) {
  ------------------
  |  | 6573|      8|#define MG_PPPoE_ST_SESS 2  // Session established, PPP traffic is exchanged
  ------------------
  |  Branch (7081:14): [True: 3, False: 5]
  ------------------
 7082|      3|    pay->buf = (char *) (pppoe + 1);
 7083|      3|    pay->len = pay->len - sizeof(*pppoe);
 7084|      3|    return ppp_rx(ifp, proto, pay, raw);
 7085|      3|  }
 7086|     66|  return false;
 7087|     69|}
mg_hexdump:
 7439|  2.65k|void mg_hexdump(const void *buf, size_t len) {
 7440|  2.65k|  const unsigned char *p = (const unsigned char *) buf;
 7441|  2.65k|  unsigned char ascii[16], alen = 0;
 7442|  2.65k|  size_t i;
 7443|  38.2k|  for (i = 0; i < len; i++) {
  ------------------
  |  Branch (7443:15): [True: 35.6k, False: 2.65k]
  ------------------
 7444|  35.6k|    if ((i % 16) == 0) {
  ------------------
  |  Branch (7444:9): [True: 2.65k, False: 32.9k]
  ------------------
 7445|       |      // Print buffered ascii chars
 7446|  2.65k|      if (i > 0)
  ------------------
  |  Branch (7446:11): [True: 0, False: 2.65k]
  ------------------
 7447|      0|        logs("  ", 2), logs((char *) ascii, 16), logs("\r\n", 2), alen = 0;
 7448|       |      // Print hex address, then \t
 7449|  2.65k|      logc(nibble((i >> 12) & 15)), logc(nibble((i >> 8) & 15)),
 7450|  2.65k|          logc(nibble((i >> 4) & 15)), logc('0'), logs("   ", 3);
 7451|  2.65k|    }
 7452|  35.6k|    logc(nibble(p[i] >> 4)), logc(nibble(p[i] & 15));  // Two nibbles, e.g. c5
 7453|  35.6k|    logc(' ');                                         // Space after hex number
 7454|  35.6k|    ascii[alen++] = ISPRINT(p[i]) ? p[i] : '.';        // Add to the ascii buf
  ------------------
  |  | 7438|  35.6k|#define ISPRINT(x) ((x) >= ' ' && (x) <= '~')
  |  |  ------------------
  |  |  |  Branch (7438:21): [True: 24.2k, False: 11.3k]
  |  |  |  Branch (7438:35): [True: 17.3k, False: 6.91k]
  |  |  ------------------
  ------------------
 7455|  35.6k|  }
 7456|  9.53k|  while (alen < 16) logs("   ", 3), ascii[alen++] = ' ';
  ------------------
  |  Branch (7456:10): [True: 6.88k, False: 2.65k]
  ------------------
 7457|  2.65k|  logs("  ", 2), logs((char *) ascii, 16), logs("\r\n", 2);
 7458|  2.65k|}
mg_mdash_poll:
 7890|  6.10k|void mg_mdash_poll(struct mg_mgr *mgr) {
 7891|  6.10k|  (void) mgr;
 7892|  6.10k|}
mg_mqtt_next_prop:
 8333|  9.84k|                         size_t ofs) {
 8334|  9.84k|  uint8_t *props = (uint8_t *) msg->dgram.buf + msg->props_start;
 8335|  9.84k|  uint8_t *props_end = props + msg->props_size;
 8336|  9.84k|  uint8_t *i = props + ofs;
 8337|  9.84k|  size_t new_pos = ofs, len;
 8338|       |  
 8339|  9.84k|  if (msg->props_start > msg->dgram.len ||
  ------------------
  |  Branch (8339:7): [True: 0, False: 9.84k]
  ------------------
 8340|  9.84k|    msg->props_size > msg->dgram.len - msg->props_start ||
  ------------------
  |  Branch (8340:5): [True: 0, False: 9.84k]
  ------------------
 8341|  9.84k|    ofs >= msg->props_size)
  ------------------
  |  Branch (8341:5): [True: 2.00k, False: 7.84k]
  ------------------
 8342|  2.00k|  return 0;
 8343|       |
 8344|  7.84k|  memset(prop, 0, sizeof(struct mg_mqtt_prop));
 8345|  7.84k|  prop->id = i[0];
 8346|  7.84k|  i++, new_pos++;
 8347|       |
 8348|  7.84k|  switch (mqtt_prop_type_by_id(prop->id)) {
 8349|     39|    case MQTT_PROP_TYPE_STRING_PAIR:
  ------------------
  |  Branch (8349:5): [True: 39, False: 7.80k]
  ------------------
 8350|     39|      if (i + 2 > props_end) return 0;
  ------------------
  |  Branch (8350:11): [True: 3, False: 36]
  ------------------
 8351|     36|      prop->key.len = (uint16_t) ((((uint16_t) i[0]) << 8) | i[1]);
 8352|     36|      if (i + 2 + prop->key.len > props_end) return 0;
  ------------------
  |  Branch (8352:11): [True: 23, False: 13]
  ------------------
 8353|     13|      prop->key.buf = (char *) i + 2;
 8354|     13|      i += 2 + prop->key.len;
 8355|     13|      if (i + 2 > props_end) return 0;
  ------------------
  |  Branch (8355:11): [True: 2, False: 11]
  ------------------
 8356|     11|      prop->val.len = (uint16_t) ((((uint16_t) i[0]) << 8) | i[1]);
 8357|     11|      prop->val.buf = (char *) i + 2;
 8358|     11|      if (i + 2 + prop->val.len > props_end) return 0;
  ------------------
  |  Branch (8358:11): [True: 1, False: 10]
  ------------------
 8359|     10|      new_pos += 2 * sizeof(uint16_t) + prop->val.len + prop->key.len;
 8360|     10|      break;
 8361|  1.29k|    case MQTT_PROP_TYPE_BYTE:
  ------------------
  |  Branch (8361:5): [True: 1.29k, False: 6.55k]
  ------------------
 8362|  1.29k|      if (i + 1 > props_end) return 0;
  ------------------
  |  Branch (8362:11): [True: 6, False: 1.28k]
  ------------------
 8363|  1.28k|      prop->iv = (uint8_t) i[0];
 8364|  1.28k|      new_pos++;
 8365|  1.28k|      break;
 8366|    472|    case MQTT_PROP_TYPE_SHORT:
  ------------------
  |  Branch (8366:5): [True: 472, False: 7.36k]
  ------------------
 8367|    472|      if (i + 2 > props_end) return 0;
  ------------------
  |  Branch (8367:11): [True: 6, False: 466]
  ------------------
 8368|    466|      prop->iv = (uint16_t) ((((uint16_t) i[0]) << 8) | i[1]);
 8369|    466|      new_pos += sizeof(uint16_t);
 8370|    466|      break;
 8371|  5.28k|    case MQTT_PROP_TYPE_INT:
  ------------------
  |  Branch (8371:5): [True: 5.28k, False: 2.55k]
  ------------------
 8372|  5.28k|      if (i + 4 > props_end) return 0;
  ------------------
  |  Branch (8372:11): [True: 9, False: 5.27k]
  ------------------
 8373|  5.27k|      prop->iv = ((uint32_t) i[0] << 24) | ((uint32_t) i[1] << 16) |
 8374|  5.27k|                 ((uint32_t) i[2] << 8) | i[3];
 8375|  5.27k|      new_pos += sizeof(uint32_t);
 8376|  5.27k|      break;
 8377|     51|    case MQTT_PROP_TYPE_STRING:
  ------------------
  |  Branch (8377:5): [True: 51, False: 7.78k]
  ------------------
 8378|     51|      if (i + 2 > props_end) return 0;
  ------------------
  |  Branch (8378:11): [True: 5, False: 46]
  ------------------
 8379|     46|      prop->val.len = (uint16_t) ((((uint16_t) i[0]) << 8) | i[1]);
 8380|     46|      prop->val.buf = (char *) i + 2;
 8381|     46|      if (i + 2 + prop->val.len > props_end) return 0;
  ------------------
  |  Branch (8381:11): [True: 25, False: 21]
  ------------------
 8382|     21|      new_pos += 2 + prop->val.len;
 8383|     21|      break;
 8384|     58|    case MQTT_PROP_TYPE_BINARY_DATA:
  ------------------
  |  Branch (8384:5): [True: 58, False: 7.78k]
  ------------------
 8385|     58|      if (i + 2 > props_end) return 0;
  ------------------
  |  Branch (8385:11): [True: 5, False: 53]
  ------------------
 8386|     53|      prop->val.len = (uint16_t) ((((uint16_t) i[0]) << 8) | i[1]);
 8387|     53|      prop->val.buf = (char *) i + 2;
 8388|     53|      if (i + 2 + prop->val.len > props_end) return 0;
  ------------------
  |  Branch (8388:11): [True: 26, False: 27]
  ------------------
 8389|     27|      new_pos += 2 + prop->val.len;
 8390|     27|      break;
 8391|    535|    case MQTT_PROP_TYPE_VARIABLE_INT:
  ------------------
  |  Branch (8391:5): [True: 535, False: 7.30k]
  ------------------
 8392|    535|      len = decode_varint(i, (size_t) (props_end - i), &prop->iv);
 8393|    535|      if (i + len > props_end) return 0;
  ------------------
  |  Branch (8393:11): [True: 0, False: 535]
  ------------------
 8394|    535|      new_pos = (len == 0) ? 0 : new_pos + len;
  ------------------
  |  Branch (8394:17): [True: 12, False: 523]
  ------------------
 8395|    535|      break;
 8396|    114|    default:
  ------------------
  |  Branch (8396:5): [True: 114, False: 7.72k]
  ------------------
 8397|    114|      new_pos = 0;
 8398|    114|      break;
 8399|  7.84k|  }
 8400|       |
 8401|  7.72k|  return new_pos;
 8402|  7.84k|}
mg_mqtt_parse:
 8547|  24.4k|                  struct mg_mqtt_message *m) {
 8548|  24.4k|  uint8_t lc = 0, *p, *end;
 8549|  24.4k|  uint32_t n = 0, len_len = 0, tmp;
 8550|       |
 8551|  24.4k|  memset(m, 0, sizeof(*m));
 8552|  24.4k|  m->dgram.buf = (char *) buf;
 8553|  24.4k|  if (len < 2) return MQTT_INCOMPLETE;
  ------------------
  |  Branch (8553:7): [True: 12.4k, False: 11.9k]
  ------------------
 8554|  11.9k|  m->cmd = (uint8_t) (buf[0] >> 4);
 8555|  11.9k|  m->qos = (buf[0] >> 1) & 3;
 8556|       |
 8557|  11.9k|  n = len_len = 0;
 8558|  11.9k|  p = (uint8_t *) buf + 1;
 8559|  14.4k|  while ((size_t) (p - buf) < len) {
  ------------------
  |  Branch (8559:10): [True: 14.3k, False: 118]
  ------------------
 8560|  14.3k|    lc = *((uint8_t *) p++);
 8561|  14.3k|    n += (uint32_t) ((lc & 0x7f) << 7 * len_len);
 8562|  14.3k|    len_len++;
 8563|  14.3k|    if (!(lc & 0x80)) break;
  ------------------
  |  Branch (8563:9): [True: 11.5k, False: 2.74k]
  ------------------
 8564|  2.74k|    if (len_len >= 4) return MQTT_MALFORMED;
  ------------------
  |  Branch (8564:9): [True: 274, False: 2.47k]
  ------------------
 8565|  2.74k|  }
 8566|  11.7k|  end = p + n;
 8567|  11.7k|  if ((lc & 0x80) || (end > buf + len)) return MQTT_INCOMPLETE;
  ------------------
  |  Branch (8567:7): [True: 118, False: 11.5k]
  |  Branch (8567:22): [True: 6.11k, False: 5.48k]
  ------------------
 8568|  5.48k|  m->dgram.len = (size_t) (end - buf);
 8569|       |
 8570|  5.48k|  switch (m->cmd) {
 8571|    648|    case MQTT_CMD_CONNACK:
  ------------------
  |  | 3550|    648|#define MQTT_CMD_CONNACK 2
  ------------------
  |  Branch (8571:5): [True: 648, False: 4.83k]
  ------------------
 8572|    648|      if (end - p < 2) return MQTT_MALFORMED;
  ------------------
  |  Branch (8572:11): [True: 70, False: 578]
  ------------------
 8573|    578|      m->ack = p[1];
 8574|    578|      p += 2;
 8575|    578|      if (version == 5) {
  ------------------
  |  Branch (8575:11): [True: 289, False: 289]
  ------------------
 8576|    289|        if (p >= end) return MQTT_MALFORMED;
  ------------------
  |  Branch (8576:13): [True: 2, False: 287]
  ------------------
 8577|    287|        len_len = (uint32_t) decode_varint(p, (size_t) (end - p), &tmp);
 8578|    287|        if (!len_len) return MQTT_MALFORMED;
  ------------------
  |  Branch (8578:13): [True: 20, False: 267]
  ------------------
 8579|    267|        m->props_size = (size_t) tmp;
 8580|    267|        m->props_start = (size_t) (p + len_len - buf);
 8581|    267|        p += len_len + m->props_size;
 8582|    267|        if (p > end) return MQTT_MALFORMED;
  ------------------
  |  Branch (8582:13): [True: 112, False: 155]
  ------------------
 8583|    267|      }
 8584|    444|      break;
 8585|  1.90k|    case MQTT_CMD_PUBACK:
  ------------------
  |  | 3552|  1.90k|#define MQTT_CMD_PUBACK 4
  ------------------
  |  Branch (8585:5): [True: 1.90k, False: 3.57k]
  ------------------
 8586|  2.53k|    case MQTT_CMD_PUBREC:
  ------------------
  |  | 3553|  2.53k|#define MQTT_CMD_PUBREC 5
  ------------------
  |  Branch (8586:5): [True: 630, False: 4.85k]
  ------------------
 8587|  2.66k|    case MQTT_CMD_PUBREL:
  ------------------
  |  | 3554|  2.66k|#define MQTT_CMD_PUBREL 6
  ------------------
  |  Branch (8587:5): [True: 122, False: 5.36k]
  ------------------
 8588|  3.07k|    case MQTT_CMD_PUBCOMP:
  ------------------
  |  | 3555|  3.07k|#define MQTT_CMD_PUBCOMP 7
  ------------------
  |  Branch (8588:5): [True: 416, False: 5.06k]
  ------------------
 8589|  3.14k|    case MQTT_CMD_SUBSCRIBE:
  ------------------
  |  | 3556|  3.14k|#define MQTT_CMD_SUBSCRIBE 8
  ------------------
  |  Branch (8589:5): [True: 66, False: 5.41k]
  ------------------
 8590|  3.25k|    case MQTT_CMD_SUBACK:
  ------------------
  |  | 3557|  3.25k|#define MQTT_CMD_SUBACK 9
  ------------------
  |  Branch (8590:5): [True: 110, False: 5.37k]
  ------------------
 8591|  3.26k|    case MQTT_CMD_UNSUBSCRIBE:
  ------------------
  |  | 3558|  3.26k|#define MQTT_CMD_UNSUBSCRIBE 10
  ------------------
  |  Branch (8591:5): [True: 16, False: 5.46k]
  ------------------
 8592|  3.27k|    case MQTT_CMD_UNSUBACK:
  ------------------
  |  | 3559|  3.27k|#define MQTT_CMD_UNSUBACK 11
  ------------------
  |  Branch (8592:5): [True: 6, False: 5.47k]
  ------------------
 8593|  3.27k|      if (p + 2 > end) return MQTT_MALFORMED;
  ------------------
  |  Branch (8593:11): [True: 250, False: 3.02k]
  ------------------
 8594|  3.02k|      m->id = (uint16_t) ((((uint16_t) p[0]) << 8) | p[1]);
 8595|  3.02k|      p += 2;
 8596|  3.02k|      break;
 8597|    732|    case MQTT_CMD_PUBLISH: {
  ------------------
  |  | 3551|    732|#define MQTT_CMD_PUBLISH 3
  ------------------
  |  Branch (8597:5): [True: 732, False: 4.75k]
  ------------------
 8598|    732|      if (p + 2 > end) return MQTT_MALFORMED;
  ------------------
  |  Branch (8598:11): [True: 8, False: 724]
  ------------------
 8599|    724|      m->topic.len = (uint16_t) ((((uint16_t) p[0]) << 8) | p[1]);
 8600|    724|      m->topic.buf = (char *) p + 2;
 8601|    724|      p += 2 + m->topic.len;
 8602|    724|      if (p > end) return MQTT_MALFORMED;
  ------------------
  |  Branch (8602:11): [True: 382, False: 342]
  ------------------
 8603|    342|      if (m->qos > 0) {
  ------------------
  |  Branch (8603:11): [True: 84, False: 258]
  ------------------
 8604|     84|        if (p + 2 > end) return MQTT_MALFORMED;
  ------------------
  |  Branch (8604:13): [True: 8, False: 76]
  ------------------
 8605|     76|        m->id = (uint16_t) ((((uint16_t) p[0]) << 8) | p[1]);
 8606|     76|        p += 2;
 8607|     76|      }
 8608|    334|      if (p > end) return MQTT_MALFORMED;
  ------------------
  |  Branch (8608:11): [True: 0, False: 334]
  ------------------
 8609|    334|      if (version == 5 && p + 2 < end) {
  ------------------
  |  Branch (8609:11): [True: 167, False: 167]
  |  Branch (8609:27): [True: 162, False: 5]
  ------------------
 8610|    162|        len_len = (uint32_t) decode_varint(p, (size_t) (end - p), &tmp);
 8611|    162|        if (!len_len) return MQTT_MALFORMED;
  ------------------
  |  Branch (8611:13): [True: 7, False: 155]
  ------------------
 8612|    155|        m->props_size = (size_t) tmp;
 8613|    155|        m->props_start = (size_t) (p + len_len - buf);
 8614|    155|        p += len_len + m->props_size;
 8615|    155|      }
 8616|    327|      if (p > end) return MQTT_MALFORMED;
  ------------------
  |  Branch (8616:11): [True: 5, False: 322]
  ------------------
 8617|    322|      m->data.buf = (char *) p;
 8618|    322|      m->data.len = (size_t) (end - p);
 8619|    322|      break;
 8620|    327|    }
 8621|    830|    default: break;
  ------------------
  |  Branch (8621:5): [True: 830, False: 4.65k]
  ------------------
 8622|  5.48k|  }
 8623|  4.62k|  return MQTT_OK;
 8624|  5.48k|}
mg_vprintf:
 8763|   285k|size_t mg_vprintf(struct mg_connection *c, const char *fmt, va_list *ap) {
 8764|   285k|  size_t old = c->send.len;
 8765|   285k|  size_t expected = mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, ap);
 8766|   285k|  size_t actual = c->send.len - old;
 8767|   285k|  if (actual != expected) {
  ------------------
  |  Branch (8767:7): [True: 0, False: 285k]
  ------------------
 8768|      0|    mg_error(c, "OOM");
 8769|      0|    c->send.len = old;
 8770|      0|    actual = 0;
 8771|      0|  }
 8772|   285k|  return actual;
 8773|   285k|}
mg_printf:
 8775|   285k|size_t mg_printf(struct mg_connection *c, const char *fmt, ...) {
 8776|   285k|  size_t len = 0;
 8777|   285k|  va_list ap;
 8778|   285k|  va_start(ap, fmt);
 8779|   285k|  len = mg_vprintf(c, fmt, &ap);
 8780|       |  va_end(ap);
 8781|   285k|  return len;
 8782|   285k|}
mg_aton:
 8923|  6.10k|bool mg_aton(struct mg_str str, struct mg_addr *addr) {
 8924|  6.10k|  return mg_atone(str, addr) || mg_atonl(str, addr) || mg_aton_(str, addr);
  ------------------
  |  Branch (8924:10): [True: 0, False: 6.10k]
  |  Branch (8924:33): [True: 6.10k, False: 0]
  |  Branch (8924:56): [True: 0, False: 0]
  ------------------
 8925|  6.10k|}
mg_alloc_conn:
 8927|  6.10k|struct mg_connection *mg_alloc_conn(struct mg_mgr *mgr) {
 8928|  6.10k|  struct mg_connection *c =
 8929|  6.10k|      (struct mg_connection *) mg_calloc(1, sizeof(*c) + mgr->extraconnsize);
 8930|  6.10k|  if (c != NULL) {
  ------------------
  |  Branch (8930:7): [True: 6.10k, False: 0]
  ------------------
 8931|  6.10k|    c->mgr = mgr;
 8932|  6.10k|    c->send.align = c->recv.align = c->rtls.align = MG_IO_SIZE;
  ------------------
  |  |    7|  6.10k|#define MG_IO_SIZE (32 * 1024 * 1024)  // Big IO size for fast resizes
  ------------------
 8933|  6.10k|    c->id = ++mgr->nextid;
 8934|  6.10k|    MG_PROF_INIT(c);
 8935|  6.10k|  }
 8936|  6.10k|  return c;
 8937|  6.10k|}
mg_close_conn:
 8939|  6.10k|void mg_close_conn(struct mg_connection *c) {
 8940|  6.10k|  mg_resolve_cancel(c);  // Close any pending DNS query
 8941|  6.10k|  LIST_DELETE(struct mg_connection, &c->mgr->conns, c);
  ------------------
  |  | 2161|  6.10k|  do {                                     \
  |  | 2162|  6.10k|    type_ **h = head_;                     \
  |  | 2163|  6.10k|    while (*h != (elem_)) h = &(*h)->next; \
  |  |  ------------------
  |  |  |  Branch (2163:12): [True: 0, False: 6.10k]
  |  |  ------------------
  |  | 2164|  6.10k|    *h = (elem_)->next;                    \
  |  | 2165|  6.10k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (2165:12): [Folded, False: 6.10k]
  |  |  ------------------
  ------------------
 8942|  6.10k|  if (c == c->mgr->dns4.c) c->mgr->dns4.c = NULL;
  ------------------
  |  Branch (8942:7): [True: 0, False: 6.10k]
  ------------------
 8943|  6.10k|  if (c == c->mgr->dns6.c) c->mgr->dns6.c = NULL;
  ------------------
  |  Branch (8943:7): [True: 0, False: 6.10k]
  ------------------
 8944|       |  // Order of operations is important. `MG_EV_CLOSE` event must be fired
 8945|       |  // before we deallocate received data, see #1331
 8946|  6.10k|  mg_call(c, MG_EV_CLOSE, NULL);
 8947|  6.10k|  MG_DEBUG(("%lu %ld closed", c->id, c->fd));
  ------------------
  |  | 1804|  6.10k|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|  6.10k|  do {                      \
  |  |  |  | 1793|  6.10k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 6.10k]
  |  |  |  |  ------------------
  |  |  |  | 1794|  6.10k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 6.10k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8948|  6.10k|  MG_PROF_DUMP(c);
 8949|  6.10k|  MG_PROF_FREE(c);
 8950|       |
 8951|  6.10k|  mg_tls_free(c);
 8952|  6.10k|  mg_iobuf_free(&c->recv);
 8953|  6.10k|  mg_iobuf_free(&c->send);
 8954|  6.10k|  mg_iobuf_free(&c->rtls);
 8955|  6.10k|  mg_bzero((unsigned char *) c, sizeof(*c));
 8956|  6.10k|  mg_free(c);
 8957|  6.10k|}
mg_connect_svc:
 8961|  6.10k|                                     mg_event_handler_t pfn, void *pfn_data) {
 8962|  6.10k|  struct mg_connection *c = NULL;
 8963|  6.10k|  if (url == NULL || url[0] == '\0') {
  ------------------
  |  Branch (8963:7): [True: 0, False: 6.10k]
  |  Branch (8963:22): [True: 0, False: 6.10k]
  ------------------
 8964|      0|    MG_ERROR(("null url"));
  ------------------
  |  | 1802|      0|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8965|      0|#if MG_ENABLE_TCPIP
 8966|  6.10k|  } else if (mgr->ifp != NULL && mgr->ifp->state != MG_TCPIP_STATE_READY) {
  ------------------
  |  | 4866|  6.10k|#define MG_TCPIP_STATE_READY 5      // Fully operational; gateway MAC resolved
  ------------------
  |  Branch (8966:14): [True: 6.10k, False: 0]
  |  Branch (8966:34): [True: 0, False: 6.10k]
  ------------------
 8967|      0|    MG_ERROR(("Network is down"));
  ------------------
  |  | 1802|      0|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8968|      0|#endif
 8969|  6.10k|  } else if ((c = mg_alloc_conn(mgr)) == NULL) {
  ------------------
  |  Branch (8969:14): [True: 0, False: 6.10k]
  ------------------
 8970|      0|    MG_ERROR(("OOM"));
  ------------------
  |  | 1802|      0|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8971|  6.10k|  } else {
 8972|  6.10k|    LIST_ADD_HEAD(struct mg_connection, &mgr->conns, c);
  ------------------
  |  | 2148|  6.10k|  do {                                     \
  |  | 2149|  6.10k|    (elem_)->next = (*head_);              \
  |  | 2150|  6.10k|    *(head_) = (elem_);                    \
  |  | 2151|  6.10k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (2151:12): [Folded, False: 6.10k]
  |  |  ------------------
  ------------------
 8973|  6.10k|    c->is_udp = (strncmp(url, "udp:", 4) == 0);
 8974|  6.10k|    c->fd = (void *) (size_t) MG_INVALID_SOCKET;
  ------------------
  |  | 1283|  6.10k|#define MG_INVALID_SOCKET (-1)
  ------------------
 8975|  6.10k|    c->fn = fn;
 8976|  6.10k|    c->is_client = true;
 8977|  6.10k|    c->fn_data = fn_data;
 8978|  6.10k|    c->is_tls = (mg_url_is_ssl(url) != 0);
 8979|  6.10k|    c->pfn = pfn;
 8980|  6.10k|    c->pfn_data = pfn_data;
 8981|  6.10k|    mg_call(c, MG_EV_OPEN, (void *) url);
 8982|  6.10k|    MG_DEBUG(("%lu %ld %s", c->id, c->fd, url));
  ------------------
  |  | 1804|  6.10k|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|  6.10k|  do {                      \
  |  |  |  | 1793|  6.10k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 6.10k]
  |  |  |  |  ------------------
  |  |  |  | 1794|  6.10k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 6.10k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 8983|  6.10k|    mg_resolve(c, url);
 8984|  6.10k|  }
 8985|  6.10k|  return c;
 8986|  6.10k|}
mg_mgr_free:
 9048|  6.10k|void mg_mgr_free(struct mg_mgr *mgr) {
 9049|  6.10k|  struct mg_connection *c;
 9050|  6.10k|  struct mg_timer *tmp, *t = mgr->timers;
 9051|  6.10k|  while (t != NULL) tmp = t->next, mg_free(t), t = tmp;
  ------------------
  |  Branch (9051:10): [True: 0, False: 6.10k]
  ------------------
 9052|  6.10k|  mgr->timers = NULL;  // Important. Next call to poll won't touch timers
 9053|  12.2k|  for (c = mgr->conns; c != NULL; c = c->next) c->is_closing = 1;
  ------------------
  |  Branch (9053:24): [True: 6.10k, False: 6.10k]
  ------------------
 9054|       |#if MG_ENABLE_MDASH
 9055|       |  mg_mdash_free(mgr);  // Before the final poll, so mdash does not reconnect
 9056|       |#endif
 9057|  6.10k|  mg_mgr_poll(mgr, 0);
 9058|       |#if MG_ENABLE_FREERTOS_TCP
 9059|       |  FreeRTOS_DeleteSocketSet(mgr->ss);
 9060|       |#endif
 9061|  6.10k|  MG_DEBUG(("All connections closed"));
  ------------------
  |  | 1804|  6.10k|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|  6.10k|  do {                      \
  |  |  |  | 1793|  6.10k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 6.10k]
  |  |  |  |  ------------------
  |  |  |  | 1794|  6.10k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 6.10k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 9062|  6.10k|#if MG_ENABLE_EPOLL
 9063|  6.10k|  if (mgr->epoll_fd >= 0) close(mgr->epoll_fd), mgr->epoll_fd = -1;
  ------------------
  |  Branch (9063:7): [True: 6.10k, False: 0]
  ------------------
 9064|  6.10k|#endif
 9065|  6.10k|  mg_tls_ctx_free(mgr);
 9066|  6.10k|#if MG_ENABLE_TCPIP
 9067|  6.10k|  if (mgr->ifp) mg_tcpip_free(mgr->ifp);
  ------------------
  |  Branch (9067:7): [True: 6.10k, False: 0]
  ------------------
 9068|  6.10k|#endif
 9069|  6.10k|}
mg_mgr_init:
 9071|  6.10k|void mg_mgr_init(struct mg_mgr *mgr) {
 9072|  6.10k|  memset(mgr, 0, sizeof(*mgr));
 9073|  6.10k|#if MG_ENABLE_EPOLL
 9074|  6.10k|  if ((mgr->epoll_fd = epoll_create1(EPOLL_CLOEXEC)) < 0)
  ------------------
  |  Branch (9074:7): [True: 0, False: 6.10k]
  ------------------
 9075|  6.10k|    MG_ERROR(("epoll_create1 errno %d", errno));
  ------------------
  |  | 1802|      0|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 9076|       |#else
 9077|       |  mgr->epoll_fd = -1;
 9078|       |#endif
 9079|       |#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
 9080|       |  // clang-format off
 9081|       |  { WSADATA data; WSAStartup(MAKEWORD(2, 2), &data); }
 9082|       |  // clang-format on
 9083|       |#elif MG_ENABLE_FREERTOS_TCP
 9084|       |  mgr->ss = FreeRTOS_CreateSocketSet();
 9085|       |#elif MG_ARCH == MG_ARCH_UNIX
 9086|       |  // Ignore SIGPIPE signal, so if client cancels the request, it
 9087|       |  // won't kill the whole process.
 9088|  6.10k|  signal(SIGPIPE, SIG_IGN);
 9089|       |#elif MG_ENABLE_TCPIP_DRIVER_INIT && defined(MG_TCPIP_DRIVER_INIT)
 9090|       |  MG_TCPIP_DRIVER_INIT(mgr);
 9091|       |#endif
 9092|       |#if MG_ENABLE_BSD_SOCKETS
 9093|       |  mgr->pipe.q = NULL;
 9094|       |#else
 9095|  6.10k|  mgr->pipe.fd = MG_INVALID_SOCKET;
  ------------------
  |  | 1283|  6.10k|#define MG_INVALID_SOCKET (-1)
  ------------------
 9096|  6.10k|#endif
 9097|  6.10k|  mgr->dnstimeout = 3000;
 9098|  6.10k|  mgr->dns4.url = "udp://8.8.8.8:53";
 9099|  6.10k|  mgr->dns6.url = "udp://[2001:4860:4860::8888]:53";
 9100|  6.10k|  mg_tls_ctx_init(mgr);
 9101|  6.10k|  MG_DEBUG(("MG_IO_SIZE: %lu, TLS: %s, conn size: %zu, mgr size: %zu",
  ------------------
  |  | 1804|  6.10k|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|  6.10k|  do {                      \
  |  |  |  | 1793|  6.10k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 6.10k]
  |  |  |  |  |  Branch (1793:19): [Folded, False: 0]
  |  |  |  |  |  Branch (1793:19): [Folded, False: 0]
  |  |  |  |  |  Branch (1793:19): [Folded, False: 0]
  |  |  |  |  |  Branch (1793:19): [Folded, False: 0]
  |  |  |  |  |  Branch (1793:19): [True: 0, Folded]
  |  |  |  |  ------------------
  |  |  |  | 1794|  6.10k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 6.10k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 9102|  6.10k|            MG_IO_SIZE,
 9103|  6.10k|            MG_TLS == MG_TLS_NONE      ? "none"
 9104|  6.10k|            : MG_TLS == MG_TLS_MBED    ? "MbedTLS"
 9105|  6.10k|            : MG_TLS == MG_TLS_OPENSSL ? "OpenSSL"
 9106|  6.10k|            : MG_TLS == MG_TLS_BUILTIN ? "builtin"
 9107|  6.10k|            : MG_TLS == MG_TLS_WOLFSSL ? "WolfSSL"
 9108|  6.10k|                                       : "custom",
 9109|  6.10k|            sizeof(struct mg_connection), sizeof(struct mg_mgr)));
 9110|       |#if MG_ENABLE_MDASH
 9111|       |  mg_mdash_init(mgr);
 9112|       |#endif
 9113|  6.10k|}
mg_tcpip_call:
 9373|  6.81k|void mg_tcpip_call(struct mg_tcpip_if *ifp, int ev, void *ev_data) {
 9374|       |#if 0 && MG_ENABLE_PROFILE
 9375|       |  const char *names[] = {"TCPIP_EV_STATE_CHANGE",  "TCPIP_EV_DHCP_DNS",
 9376|       |                         "TCPIP_EV_DHCP_SNTP",     "TCPIP_EV_ARP",
 9377|       |                         "TCPIP_EV_TIMER_1S",      "TCPIP_EV_WIFI_SCAN_RESULT",
 9378|       |                         "TCPIP_EV_WIFI_SCAN_END", "TCPIP_EV_WIFI_CONNECT_ERR",
 9379|       |                         "TCPIP_EV_DRIVER",        "TCPIP_EV_STATE6_CHANGE",
 9380|       |                         "TCPIP_EV_PHY_RX",        "TCPIP_EV_PHY_TX",
 9381|       |                         "TCPIP_EV_USER"};
 9382|       |  if (ev != MG_TCPIP_EV_TIMER_1S && ev < (int) (sizeof(names) / sizeof(names[0]))) {
 9383|       |    MG_PROF_ADD(ifp, names[ev]); // TODO(): call MG_PROF_DUMP() MG_PROF_FREE()
 9384|       |  }
 9385|       |#endif
 9386|       |  // Fire protocol handler first, user handler second. See #2559
 9387|  6.81k|  if (ifp->pfn != NULL) ifp->pfn(ifp, ev, ev_data);
  ------------------
  |  Branch (9387:7): [True: 0, False: 6.81k]
  ------------------
 9388|  6.81k|  if (ifp->fn != NULL) ifp->fn(ifp, ev, ev_data);
  ------------------
  |  Branch (9388:7): [True: 0, False: 6.81k]
  ------------------
 9389|  6.81k|}
mg_tcpip_init:
11421|  6.10k|void mg_tcpip_init(struct mg_mgr *mgr, struct mg_tcpip_if *ifp) {
11422|       |  // If L2 address is not set, make a random one; fill MTU
11423|  6.10k|  mg_l2_init(ifp);
11424|  6.10k|  ifp->mtu = ifp->l2mtu;
11425|  6.10k|  if (MG_ENABLE_TCPIP_TCPRTX) ifp->enable_tcp_retransmit = true;
  ------------------
  |  | 1320|  6.10k|#define MG_ENABLE_TCPIP_TCPRTX 0  // TCP retransmission queue
  |  |  ------------------
  |  |  |  Branch (1320:32): [Folded, False: 6.10k]
  |  |  ------------------
  ------------------
11426|       |
11427|  6.10k|  if (ifp->dhcp_name[0] == '\0')  // If DHCP name is not set, use "mip"
  ------------------
  |  Branch (11427:7): [True: 6.10k, False: 0]
  ------------------
11428|  6.10k|    memcpy(ifp->dhcp_name, "mip", 4);
11429|  6.10k|  ifp->dhcp_name[sizeof(ifp->dhcp_name) - 1] = '\0';  // Just in case
11430|       |
11431|  6.10k|  if (ifp->driver->init && !ifp->driver->init(ifp)) {
  ------------------
  |  Branch (11431:7): [True: 6.10k, False: 0]
  |  Branch (11431:28): [True: 0, False: 6.10k]
  ------------------
11432|      0|    MG_ERROR(("driver init failed"));
  ------------------
  |  | 1802|      0|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
11433|  6.10k|  } else {
11434|  6.10k|    ifp->tx.buf = (char *) mg_calloc(1, ifp->framesize),
11435|  6.10k|    ifp->tx.len = ifp->framesize;
11436|  6.10k|    if (ifp->recv_queue.size == 0)
  ------------------
  |  Branch (11436:9): [True: 6.10k, False: 0]
  ------------------
11437|  6.10k|      ifp->recv_queue.size = ifp->driver->rx ? ifp->framesize : 8192;
  ------------------
  |  Branch (11437:30): [True: 6.10k, False: 0]
  ------------------
11438|  6.10k|    ifp->recv_queue.buf = (char *) mg_calloc(1, ifp->recv_queue.size);
11439|  6.10k|    ifp->timer_1000ms = mg_millis();
11440|  6.10k|    mgr->ifp = ifp;
11441|  6.10k|    ifp->mgr = mgr;
11442|  6.10k|    mgr->extraconnsize = sizeof(struct connstate);
11443|  6.10k|    if (ifp->ip == 0 && ifp->l2type != MG_TCPIP_L2_PPP &&
  ------------------
  |  Branch (11443:9): [True: 0, False: 6.10k]
  |  Branch (11443:25): [True: 0, False: 0]
  ------------------
11444|      0|        ifp->l2type != MG_TCPIP_L2_PPPoE)
  ------------------
  |  Branch (11444:9): [True: 0, False: 0]
  ------------------
11445|      0|      ifp->enable_dhcp_client = true;
11446|  6.10k|    mg_random(&ifp->eport, sizeof(ifp->eport));  // Random from 0 to 65535
11447|  6.10k|    ifp->eport |= MG_EPHEMERAL_PORT_BASE;        // Random from
  ------------------
  |  | 9138|  6.10k|#define MG_EPHEMERAL_PORT_BASE 32768
  ------------------
11448|       |                                           // MG_EPHEMERAL_PORT_BASE to 65535
11449|  6.10k|    if (ifp->tx.buf == NULL || ifp->recv_queue.buf == NULL) MG_ERROR(("OOM"));
  ------------------
  |  | 1802|      0|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (11449:9): [True: 0, False: 6.10k]
  |  Branch (11449:32): [True: 0, False: 6.10k]
  ------------------
11450|  6.10k|    MG_DEBUG(("Builtin TCP/IP init done. Queue size: %zu, extra conn size: %zu",
  ------------------
  |  | 1804|  6.10k|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|  6.10k|  do {                      \
  |  |  |  | 1793|  6.10k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 6.10k]
  |  |  |  |  ------------------
  |  |  |  | 1794|  6.10k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 6.10k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
11451|  6.10k|              ifp->recv_queue.size, mgr->extraconnsize));
11452|  6.10k|  }
11453|  6.10k|  mg_bsd_init(mgr);
11454|  6.10k|}
mg_tcpip_free:
11462|  6.10k|void mg_tcpip_free(struct mg_tcpip_if *ifp) {
11463|  6.10k|  while (ifp->mgr->conns != NULL) close_conn(ifp->mgr->conns); // TCP FIN wait
  ------------------
  |  Branch (11463:10): [True: 0, False: 6.10k]
  ------------------
11464|  6.10k|  mg_free(ifp->recv_queue.buf);
11465|  6.10k|  mg_free(ifp->tx.buf);
11466|  6.10k|  mg_free(ifp->dns4_url);
11467|  6.10k|}
mg_connect_resolved:
11486|  6.10k|void mg_connect_resolved(struct mg_connection *c) {
11487|  6.10k|  struct mg_tcpip_if *ifp = c->mgr->ifp;
11488|  6.10k|  uint8_t *l2addr;
11489|  6.10k|  struct connstate *s = (struct connstate *) (c + 1);
11490|  6.10k|  s->retransmit = ifp->enable_tcp_retransmit;
11491|  6.10k|  s->txq.align = MG_TCPIP_TXQ_ALIGN;
  ------------------
  |  | 9169|  6.10k|#define MG_TCPIP_TXQ_ALIGN 1024  // Retransmit queue allocation quantum
  ------------------
11492|  6.10k|  c->is_resolving = 0;
11493|  6.10k|  if (c->loc.port == 0) {
  ------------------
  |  Branch (11493:7): [True: 6.10k, False: 0]
  ------------------
11494|  6.10k|    if (ifp->eport < MG_EPHEMERAL_PORT_BASE)
  ------------------
  |  | 9138|  6.10k|#define MG_EPHEMERAL_PORT_BASE 32768
  ------------------
  |  Branch (11494:9): [True: 0, False: 6.10k]
  ------------------
11495|      0|      ifp->eport = MG_EPHEMERAL_PORT_BASE;
  ------------------
  |  | 9138|      0|#define MG_EPHEMERAL_PORT_BASE 32768
  ------------------
11496|  6.10k|    c->loc.port = mg_htons(ifp->eport++);
  ------------------
  |  | 2093|  6.10k|#define mg_htons(x) mg_ntohs(x)
  ------------------
11497|  6.10k|  }  // otherwise retain an existing bound port
11498|       |#if MG_ENABLE_IPV6
11499|       |  if (c->rem.is_ip6) {
11500|       |    if (c->loc.addr.ip6[0] == 0 && c->loc.addr.ip6[1] == 0 &&
11501|       |        c->rem.addr.ip6[0] == ifp->ip6ll[0]) {  // same local LAN, use ll
11502|       |      c->loc.addr.ip6[0] = ifp->ip6ll[0], c->loc.addr.ip6[1] = ifp->ip6ll[1];
11503|       |    } else if (c->loc.addr.ip6[0] == 0 && c->loc.addr.ip6[1] == 0) {
11504|       |      // Use global address
11505|       |      c->loc.addr.ip6[0] = ifp->ip6[0], c->loc.addr.ip6[1] = ifp->ip6[1];
11506|       |    } // otherwise retain an existing bound address
11507|       |    c->loc.is_ip6 = true;
11508|       |  } else
11509|       |#endif
11510|  6.10k|  {
11511|  6.10k|    if (c->loc.addr.ip4 == 0) c->loc.addr.ip4 = ifp->ip;
  ------------------
  |  Branch (11511:9): [True: 6.10k, False: 0]
  ------------------
11512|  6.10k|  }
11513|  6.10k|  MG_DEBUG(("%lu %M -> %M", c->id, mg_print_ip_port, &c->loc, mg_print_ip_port,
  ------------------
  |  | 1804|  6.10k|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|  6.10k|  do {                      \
  |  |  |  | 1793|  6.10k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 6.10k]
  |  |  |  |  ------------------
  |  |  |  | 1794|  6.10k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 6.10k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
11514|  6.10k|            &c->rem));
11515|  6.10k|  mg_call(c, MG_EV_RESOLVE, NULL);
11516|  6.10k|  c->is_connecting = 1;
11517|  6.10k|  if (c->is_udp && (l2addr = tcpip_mapip(ifp, &c->rem)) != NULL) {
  ------------------
  |  Branch (11517:7): [True: 0, False: 6.10k]
  |  Branch (11517:20): [True: 0, False: 0]
  ------------------
11518|      0|    memcpy(s->mac, l2addr, sizeof(s->mac));
11519|      0|    l2addr_resolved(c);  // broadcast or multicast
11520|       |#if MG_ENABLE_IPV6
11521|       |  } else if (c->rem.is_ip6) {
11522|       |    if (match_prefix((uint8_t *) c->rem.addr.ip6, ifp->prefix,
11523|       |                     ifp->prefix_len)                       // same global LAN
11524|       |        || (c->rem.addr.ip6[0] == ifp->ip6ll[0]             // same local LAN
11525|       |            && !MG_IP6MATCH(c->rem.addr.ip6, ifp->gw6))) {  // and not gw
11526|       |      // If we're in the same LAN, fire a Neighbor Solicitation
11527|       |      MG_DEBUG(("%lu NS lookup...", c->id));
11528|       |      tx_ndp_ns(ifp, c->rem.addr.ip6, NULL);  // RFC-4861 4.3, requesting
11529|       |      settmout(c, MIP_TTYPE_ARP);
11530|       |      c->is_arplooking = 1;
11531|       |    } else if (ifp->gw6_ready) {
11532|       |      memcpy(s->mac, ifp->gw6mac, sizeof(s->mac));
11533|       |      l2addr_resolved(c);
11534|       |    } else {
11535|       |      mg_error(c, "No IPv6 gateway, can't connect");
11536|       |    }
11537|       |#endif
11538|  6.10k|  } else {
11539|  6.10k|    uint32_t rem_ip = c->rem.addr.ip4;
11540|  6.10k|    if (ifp->ip && MG_IPISLOCAL(ifp, rem_ip) &&
  ------------------
  |  | 9455|  12.2k|#define MG_IPISLOCAL(i, a) ((a & i->mask) == (i->ip & i->mask))
  |  |  ------------------
  |  |  |  Branch (9455:28): [True: 0, False: 6.10k]
  |  |  ------------------
  ------------------
  |  Branch (11540:9): [True: 6.10k, False: 0]
  ------------------
11541|      0|        rem_ip != ifp->gw) {  // skip if gw (onstatechange -> ARP)
  ------------------
  |  Branch (11541:9): [True: 0, False: 0]
  ------------------
11542|       |      // We're in the same LAN, fire an ARP lookup.
11543|      0|      MG_DEBUG(("%lu ARP lookup...", c->id));
  ------------------
  |  | 1804|      0|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
11544|      0|      mg_tcpip_arp_request(ifp, rem_ip, NULL);
11545|      0|      settmout(c, MIP_TTYPE_ARP);
  ------------------
  |  | 9187|      0|#define MIP_TTYPE_ARP 2        // ARP resolve sent, waiting for response
  ------------------
11546|      0|      c->is_arplooking = 1;
11547|  6.10k|    } else if (ifp->gw_ready) {
  ------------------
  |  Branch (11547:16): [True: 6.10k, False: 0]
  ------------------
11548|  6.10k|      memcpy(s->mac, ifp->gwmac, sizeof(s->mac));
11549|  6.10k|      l2addr_resolved(c);
11550|  6.10k|    } else {
11551|      0|      mg_error(c, "No gateway, can't connect");
11552|      0|    }
11553|  6.10k|  }
11554|  6.10k|}
mg_mgr_poll:
11582|  6.10k|void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
11583|  6.10k|  struct mg_connection *c, *tmp;
11584|  6.10k|  uint64_t now = mg_millis();
11585|  6.10k|  mg_timer_poll(&mgr->timers, now);
11586|  6.10k|  mg_ota_poll(mgr);
11587|  6.10k|  mg_mdash_poll(mgr);
11588|  6.10k|  if (mgr->ifp == NULL || mgr->ifp->driver == NULL) return;
  ------------------
  |  Branch (11588:7): [True: 0, False: 6.10k]
  |  Branch (11588:27): [True: 0, False: 6.10k]
  ------------------
11589|  6.10k|  mg_tcpip_poll(mgr->ifp, now);
11590|  12.2k|  for (c = mgr->conns; c != NULL; c = tmp) {
  ------------------
  |  Branch (11590:24): [True: 6.10k, False: 6.10k]
  ------------------
11591|  6.10k|    struct connstate *s = (struct connstate *) (c + 1);
11592|  6.10k|    long flush = 0;
11593|  6.10k|    bool is_tls = c->is_tls && !c->is_resolving && !c->is_arplooking &&
  ------------------
  |  Branch (11593:19): [True: 0, False: 6.10k]
  |  Branch (11593:32): [True: 0, False: 0]
  |  Branch (11593:52): [True: 0, False: 0]
  ------------------
11594|      0|                  !c->is_listening && !c->is_connecting;
  ------------------
  |  Branch (11594:19): [True: 0, False: 0]
  |  Branch (11594:39): [True: 0, False: 0]
  ------------------
11595|  6.10k|    tmp = c->next;
11596|  6.10k|    mg_call(c, MG_EV_POLL, &now);
11597|  6.10k|    MG_VERBOSE(("%lu .. %c%c%c%c%c%c %lu %lu", c->id, c->is_tls ? 'T' : 't',
  ------------------
  |  | 1805|  6.10k|#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)
  |  |  ------------------
  |  |  |  | 1792|  6.10k|  do {                      \
  |  |  |  | 1793|  6.10k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 6.10k]
  |  |  |  |  |  Branch (1793:19): [True: 0, False: 0]
  |  |  |  |  |  Branch (1793:19): [True: 0, False: 0]
  |  |  |  |  |  Branch (1793:19): [True: 0, False: 0]
  |  |  |  |  |  Branch (1793:19): [True: 0, False: 0]
  |  |  |  |  |  Branch (1793:19): [True: 0, False: 0]
  |  |  |  |  |  Branch (1793:19): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|  6.10k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 6.10k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
11598|  6.10k|                c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h',
11599|  6.10k|                c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c',
11600|  6.10k|                s->is_closing ? 'F' : 'f', mg_tls_pending(c), c->rtls.len));
11601|  6.10k|    if (!c->is_closing) {
  ------------------
  |  Branch (11601:9): [True: 0, False: 6.10k]
  ------------------
11602|       |      // order is important, TLS conn close with > 1 record in buffer (below)
11603|      0|      if (is_tls && (c->rtls.len > 0 || mg_tls_pending(c) > 0))
  ------------------
  |  Branch (11603:11): [True: 0, False: 0]
  |  Branch (11603:22): [True: 0, False: 0]
  |  Branch (11603:41): [True: 0, False: 0]
  ------------------
11604|      0|      c->is_tls_hs ? mg_tls_handshake(c) : handle_tls_recv(c);
  ------------------
  |  Branch (11604:7): [True: 0, False: 0]
  ------------------
11605|      0|      if (can_write(c)) write_conn(c);
  ------------------
  |  Branch (11605:11): [True: 0, False: 0]
  ------------------
11606|      0|      if (is_tls && c->send.len == 0) flush = mg_tls_flush(c);
  ------------------
  |  Branch (11606:11): [True: 0, False: 0]
  |  Branch (11606:21): [True: 0, False: 0]
  ------------------
11607|      0|    }
11608|  6.10k|    if (flush == MG_IO_ERR) proto_error(c, false, "tx err"); // should RST but
  ------------------
  |  Branch (11608:9): [True: 0, False: 6.10k]
  ------------------
11609|  6.10k|    if (c->is_draining && c->send.len == 0 &&
  ------------------
  |  Branch (11609:9): [True: 2.65k, False: 3.44k]
  |  Branch (11609:27): [True: 2.39k, False: 258]
  ------------------
11610|  2.39k|        (c->is_udp ||
  ------------------
  |  Branch (11610:10): [True: 0, False: 2.39k]
  ------------------
11611|  2.39k|         (flush == 0 && s->txq.len == 0 && s->ttype != MIP_TTYPE_FIN)))
  ------------------
  |  | 9189|  2.39k|#define MIP_TTYPE_FIN 4  // FIN sent, waiting until terminating the connection
  ------------------
  |  Branch (11611:11): [True: 2.39k, False: 0]
  |  Branch (11611:25): [True: 2.39k, False: 0]
  |  Branch (11611:44): [True: 2.39k, False: 0]
  ------------------
11612|  2.39k|      c->is_closing = 1;
11613|       |    // For non-TLS, close immediately upon completing the 3-way closure
11614|       |    // For TLS, handle any pending data (above) until MIP_TTYPE_FIN expires
11615|  6.10k|    if (s->twclosure &&
  ------------------
  |  Branch (11615:9): [True: 0, False: 6.10k]
  ------------------
11616|      0|        (!c->is_tls || (c->rtls.len == 0 && mg_tls_pending(c) == 0))) {
  ------------------
  |  Branch (11616:10): [True: 0, False: 0]
  |  Branch (11616:25): [True: 0, False: 0]
  |  Branch (11616:45): [True: 0, False: 0]
  ------------------
11617|      0|      s->is_closing = 1;
11618|  6.10k|    } else if (c->is_closing && !s->is_closing) {
  ------------------
  |  Branch (11618:16): [True: 6.10k, False: 0]
  |  Branch (11618:33): [True: 692, False: 5.40k]
  ------------------
11619|    692|      if (c->is_udp || c->is_listening || c->is_resolving || c->is_arplooking ||
  ------------------
  |  Branch (11619:11): [True: 0, False: 692]
  |  Branch (11619:24): [True: 0, False: 692]
  |  Branch (11619:43): [True: 0, False: 692]
  |  Branch (11619:62): [True: 0, False: 692]
  ------------------
11620|    692|          c->is_connecting) {
  ------------------
  |  Branch (11620:11): [True: 692, False: 0]
  ------------------
11621|    692|        close_conn(c);
11622|    692|        continue;
11623|    692|      } else if (s->ttype != MIP_TTYPE_FIN) {  // active TCP: initiate closure
  ------------------
  |  | 9189|      0|#define MIP_TTYPE_FIN 4  // FIN sent, waiting until terminating the connection
  ------------------
  |  Branch (11623:18): [True: 0, False: 0]
  ------------------
11624|      0|        size_t tx = tx_tcp(c->mgr->ifp, s->mac, &c->loc, &c->rem, c->dscp,
11625|      0|                           TH_FIN | TH_ACK, mg_htonl(s->seq), mg_htonl(s->ack),
  ------------------
  |  | 9276|      0|#define TH_FIN 0x01
  ------------------
                                         TH_FIN | TH_ACK, mg_htonl(s->seq), mg_htonl(s->ack),
  ------------------
  |  | 9280|      0|#define TH_ACK 0x10
  ------------------
                                         TH_FIN | TH_ACK, mg_htonl(s->seq), mg_htonl(s->ack),
  ------------------
  |  | 2094|      0|#define mg_htonl(x) mg_ntohl(x)
  ------------------
                                         TH_FIN | TH_ACK, mg_htonl(s->seq), mg_htonl(s->ack),
  ------------------
  |  | 2094|      0|#define mg_htonl(x) mg_ntohl(x)
  ------------------
11626|      0|                           s->is_full ? 0 : MG_TCPIP_WIN, NULL, 0);
  ------------------
  |  | 9161|      0|#define MG_TCPIP_WIN 6000  // TCP window size
  ------------------
  |  Branch (11626:28): [True: 0, False: 0]
  ------------------
11627|      0|        if (tx == (size_t) -1) {
  ------------------
  |  Branch (11627:13): [True: 0, False: 0]
  ------------------
11628|      0|          s->is_closing = 1;
11629|      0|        } else if (tx > 0) {
  ------------------
  |  Branch (11629:20): [True: 0, False: 0]
  ------------------
11630|      0|          s->seq++;
11631|      0|          settmout(c, MIP_TTYPE_FIN);
  ------------------
  |  | 9189|      0|#define MIP_TTYPE_FIN 4  // FIN sent, waiting until terminating the connection
  ------------------
11632|      0|        }  // else tx = 0, should recover later or we have worse problems
11633|      0|      }
11634|    692|    }
11635|  5.40k|    if (s->send_rst)  // proto_error requested TCP RST, send it and close
  ------------------
  |  Branch (11635:9): [True: 0, False: 5.40k]
  ------------------
11636|      0|      tx_tcp(c->mgr->ifp, s->mac, &c->loc, &c->rem, c->dscp, TH_RST,
  ------------------
  |  | 9278|      0|#define TH_RST 0x04
  ------------------
11637|      0|             mg_htonl(s->seq), 0, 0, NULL, 0);
  ------------------
  |  | 2094|      0|#define mg_htonl(x) mg_ntohl(x)
  ------------------
11638|  5.40k|    if (s->is_closing) close_conn(c);  // then removes the conn
  ------------------
  |  Branch (11638:9): [True: 5.40k, False: 0]
  ------------------
11639|  5.40k|  }
11640|  6.10k|  mg_bsd_poll(mgr);
11641|  6.10k|  (void) ms;
11642|  6.10k|}
mg_ota_poll:
11979|  6.10k|void mg_ota_poll(struct mg_mgr *mgr) {
11980|  6.10k|  static uint64_t t = 5000;  // Fire first time 5 sec after boot
11981|       |
11982|  6.10k|  static uint64_t feed_timer;  // Advances 500ms per tick; tracks elapsed time
11983|  6.10k|  if (MG_OTA_STATE_GET() == MG_OTA_FAILED &&
  ------------------
  |  | 4334|  6.10k|#define MG_OTA_STATE_GET() 0
  ------------------
  |  Branch (11983:7): [Folded, False: 6.10k]
  ------------------
11984|      0|      mg_timer_expired(&feed_timer, 500, mg_millis())) {
  ------------------
  |  Branch (11984:7): [True: 0, False: 0]
  ------------------
11985|      0|    if (feed_timer < (uint64_t) MG_OTA_ROLLBACK_TIMEOUT_SECONDS * 1000) {
  ------------------
  |  | 4345|      0|#define MG_OTA_ROLLBACK_TIMEOUT_SECONDS 120
  ------------------
  |  Branch (11985:9): [True: 0, False: 0]
  ------------------
11986|      0|      MG_OTA_ROLLBACK_TIMER_FEED();  // Feed watchdog every 500ms
11987|      0|    } else if (s_autocommit_ok) {
  ------------------
  |  Branch (11987:16): [True: 0, False: 0]
  ------------------
11988|      0|      MG_INFO(("Auto-committing firmware"));
  ------------------
  |  | 1803|      0|#define MG_INFO(args) MG_LOG(MG_LL_INFO, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
11989|      0|      MG_OTA_STATE_SET(MG_OTA_CONFIRMED);  // Stop feeding → IWDG resets cleanly
  ------------------
  |  | 4337|      0|#define MG_OTA_STATE_SET(val) (void) (val)
  ------------------
11990|      0|    } else {
11991|      0|      MG_INFO(("No commit confirmation, rolling back"));
  ------------------
  |  | 1803|      0|#define MG_INFO(args) MG_LOG(MG_LL_INFO, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
11992|       |      // Stop feeding → IWDG fires → resets into MG_OTA_FAILED → rollback
11993|      0|    }
11994|      0|  }
11995|       |
11996|  6.10k|  if (MG_OTA_URL != NULL &&
  ------------------
  |  | 4388|  6.10k|#define MG_OTA_URL NULL
  ------------------
  |  Branch (11996:7): [Folded, False: 6.10k]
  ------------------
11997|      0|      mg_timer_expired(&t, MG_OTA_PULL_INTERVAL_SECONDS * 1000, mg_millis())) {
  ------------------
  |  | 4414|      0|#define MG_OTA_PULL_INTERVAL_SECONDS 60
  ------------------
  |  Branch (11997:7): [True: 0, False: 0]
  ------------------
11998|      0|    mg_ota_url_check(mgr, MG_OTA_URL, MG_OTA_STATUS_FN);
  ------------------
  |  | 4388|      0|#define MG_OTA_URL NULL
  ------------------
                  mg_ota_url_check(mgr, MG_OTA_URL, MG_OTA_STATUS_FN);
  ------------------
  |  | 4399|      0|#define MG_OTA_STATUS_FN NULL
  ------------------
11999|      0|  }
12000|  6.10k|}
mg_pfn_iobuf_noresize:
14567|  12.2M|void mg_pfn_iobuf_noresize(char ch, void *param) {
14568|  12.2M|  mg_pfn_iobuf_private(ch, param, false);
14569|  12.2M|}
mg_pfn_iobuf:
14571|  18.6M|void mg_pfn_iobuf(char ch, void *param) {
14572|  18.6M|  mg_pfn_iobuf_private(ch, param, true);
14573|  18.6M|}
mg_vsnprintf:
14575|  1.28M|size_t mg_vsnprintf(char *buf, size_t len, const char *fmt, va_list *ap) {
14576|  1.28M|  struct mg_iobuf io = {0, 0, 0, 0};
14577|  1.28M|  size_t n;
14578|  1.28M|  io.buf = (uint8_t *) buf, io.size = len;
14579|  1.28M|  n = mg_vxprintf(mg_pfn_iobuf_noresize, &io, fmt, ap);
14580|  1.28M|  if (n < len) buf[n] = '\0';
  ------------------
  |  Branch (14580:7): [True: 1.28M, False: 1.84k]
  ------------------
14581|  1.28M|  return n;
14582|  1.28M|}
mg_snprintf:
14584|  1.27M|size_t mg_snprintf(char *buf, size_t len, const char *fmt, ...) {
14585|  1.27M|  va_list ap;
14586|  1.27M|  size_t n;
14587|  1.27M|  va_start(ap, fmt);
14588|  1.27M|  n = mg_vsnprintf(buf, len, fmt, &ap);
14589|       |  va_end(ap);
14590|  1.27M|  return n;
14591|  1.27M|}
mg_pfn_stdout:
14608|   199k|void mg_pfn_stdout(char c, void *param) {
14609|   199k|#if MG_ENABLE_POSIX_FS
14610|   199k|  putchar(c);
14611|   199k|#endif
14612|   199k|  (void) param, (void) c;
14613|   199k|}
mg_sntp_parse:
15590|  12.2k|int64_t mg_sntp_parse(const unsigned char *buf, size_t len) {
15591|  12.2k|  int64_t epoch_milliseconds = -1;
15592|  12.2k|  int mode = len > 0 ? buf[0] & 7 : 0;
  ------------------
  |  Branch (15592:14): [True: 6.10k, False: 6.10k]
  ------------------
15593|  12.2k|  int version = len > 0 ? (buf[0] >> 3) & 7 : 0;
  ------------------
  |  Branch (15593:17): [True: 6.10k, False: 6.10k]
  ------------------
15594|  12.2k|  if (len < 48) {
  ------------------
  |  Branch (15594:7): [True: 9.59k, False: 2.60k]
  ------------------
15595|  9.59k|    MG_ERROR(("%s", "corrupt packet"));
  ------------------
  |  | 1802|  9.59k|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|  9.59k|  do {                      \
  |  |  |  | 1793|  9.59k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 9.59k]
  |  |  |  |  ------------------
  |  |  |  | 1794|  9.59k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 9.59k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
15596|  9.59k|  } else if (mode != 4 && mode != 5) {
  ------------------
  |  Branch (15596:14): [True: 2.47k, False: 128]
  |  Branch (15596:27): [True: 2.28k, False: 191]
  ------------------
15597|  2.28k|    MG_ERROR(("%s", "not a server reply"));
  ------------------
  |  | 1802|  2.28k|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|  2.28k|  do {                      \
  |  |  |  | 1793|  2.28k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 2.28k]
  |  |  |  |  ------------------
  |  |  |  | 1794|  2.28k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 2.28k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
15598|  2.28k|  } else if (buf[1] == 0) {
  ------------------
  |  Branch (15598:14): [True: 5, False: 314]
  ------------------
15599|      5|    MG_ERROR(("%s", "server sent a kiss of death"));
  ------------------
  |  | 1802|      5|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|      5|  do {                      \
  |  |  |  | 1793|      5|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  |  | 1794|      5|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
15600|    314|  } else if (version == 4 || version == 3) {
  ------------------
  |  Branch (15600:14): [True: 77, False: 237]
  |  Branch (15600:30): [True: 121, False: 116]
  ------------------
15601|       |    // int64_t ref = gettimestamp((uint32_t *) &buf[16]);
15602|    198|    int64_t origin_time = gettimestamp((uint32_t *) &buf[24]);
15603|    198|    int64_t receive_time = gettimestamp((uint32_t *) &buf[32]);
15604|    198|    int64_t transmit_time = gettimestamp((uint32_t *) &buf[40]);
15605|    198|    int64_t now = (int64_t) mg_millis();
15606|    198|    int64_t latency = (now - origin_time) - (transmit_time - receive_time);
15607|    198|    epoch_milliseconds = transmit_time + latency / 2;
15608|    198|    mg_boot_timestamp_ms = (uint64_t) (epoch_milliseconds - now);
15609|    198|  } else {
15610|    116|    MG_ERROR(("unexpected version: %d", version));
  ------------------
  |  | 1802|    116|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|    116|  do {                      \
  |  |  |  | 1793|    116|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 116]
  |  |  |  |  ------------------
  |  |  |  | 1794|    116|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 116]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
15611|    116|  }
15612|  12.2k|  return epoch_milliseconds;
15613|  12.2k|}
mg_str_s:
16590|  1.71M|struct mg_str mg_str_s(const char *s) {
16591|  1.71M|  struct mg_str str;
16592|  1.71M|  str.buf = (char *) s, str.len = (s == NULL) ? 0 : strlen(s);
  ------------------
  |  Branch (16592:35): [True: 10.0k, False: 1.70M]
  ------------------
16593|  1.71M|  return str;
16594|  1.71M|}
mg_str_n:
16596|  4.49M|struct mg_str mg_str_n(const char *s, size_t n) {
16597|  4.49M|  struct mg_str str;
16598|  4.49M|  str.buf = (char *) s, str.len = n;
16599|  4.49M|  return str;
16600|  4.49M|}
mg_strcmp:
16629|   849k|int mg_strcmp(const struct mg_str str1, const struct mg_str str2) {
16630|   849k|  size_t i = 0;
16631|  1.36M|  while (i < str1.len && i < str2.len) {
  ------------------
  |  Branch (16631:10): [True: 854k, False: 511k]
  |  Branch (16631:26): [True: 841k, False: 13.5k]
  ------------------
16632|   841k|    int c1 = str1.buf[i];
16633|   841k|    int c2 = str2.buf[i];
16634|   841k|    if (c1 < c2) return -1;
  ------------------
  |  Branch (16634:9): [True: 315k, False: 525k]
  ------------------
16635|   525k|    if (c1 > c2) return 1;
  ------------------
  |  Branch (16635:9): [True: 9.11k, False: 516k]
  ------------------
16636|   516k|    i++;
16637|   516k|  }
16638|   524k|  if (i < str1.len) return 1;
  ------------------
  |  Branch (16638:7): [True: 13.5k, False: 511k]
  ------------------
16639|   511k|  if (i < str2.len) return -1;
  ------------------
  |  Branch (16639:7): [True: 10.0k, False: 501k]
  ------------------
16640|   501k|  return 0;
16641|   511k|}
mg_strcasecmp:
16643|   853k|int mg_strcasecmp(const struct mg_str str1, const struct mg_str str2) {
16644|   853k|  size_t i = 0;
16645|  1.52M|  while (i < str1.len && i < str2.len) {
  ------------------
  |  Branch (16645:10): [True: 1.45M, False: 66.4k]
  |  Branch (16645:26): [True: 1.45M, False: 1.34k]
  ------------------
16646|  1.45M|    int c1 = mg_tolc(str1.buf[i]);
16647|  1.45M|    int c2 = mg_tolc(str2.buf[i]);
16648|  1.45M|    if (c1 < c2) return -1;
  ------------------
  |  Branch (16648:9): [True: 179k, False: 1.27M]
  ------------------
16649|  1.27M|    if (c1 > c2) return 1;
  ------------------
  |  Branch (16649:9): [True: 605k, False: 669k]
  ------------------
16650|   669k|    i++;
16651|   669k|  }
16652|  67.7k|  if (i < str1.len) return 1;
  ------------------
  |  Branch (16652:7): [True: 1.34k, False: 66.4k]
  ------------------
16653|  66.4k|  if (i < str2.len) return -1;
  ------------------
  |  Branch (16653:7): [True: 12.5k, False: 53.8k]
  ------------------
16654|  53.8k|  return 0;
16655|  66.4k|}
mg_match:
16657|  6.84k|bool mg_match(struct mg_str s, struct mg_str p, struct mg_str *caps) {
16658|  6.84k|  size_t i = 0, j = 0, ni = 0, nj = 0;
16659|  6.84k|  if (caps) caps->buf = NULL, caps->len = 0;
  ------------------
  |  Branch (16659:7): [True: 0, False: 6.84k]
  ------------------
16660|   219M|  while (i < p.len || j < s.len) {
  ------------------
  |  Branch (16660:10): [True: 219M, False: 8.86k]
  |  Branch (16660:23): [True: 2.59k, False: 6.26k]
  ------------------
16661|   219M|    if (i < p.len && j < s.len &&
  ------------------
  |  Branch (16661:9): [True: 219M, False: 2.59k]
  |  Branch (16661:22): [True: 219M, False: 861]
  ------------------
16662|   219M|        (p.buf[i] == '?' ||
  ------------------
  |  Branch (16662:10): [True: 173k, False: 219M]
  ------------------
16663|   219M|         (p.buf[i] != '*' && p.buf[i] != '#' && s.buf[j] == p.buf[i]))) {
  ------------------
  |  Branch (16663:11): [True: 217M, False: 2.09M]
  |  Branch (16663:30): [True: 217M, False: 177k]
  |  Branch (16663:49): [True: 215M, False: 1.13M]
  ------------------
16664|   216M|      if (caps == NULL) {
  ------------------
  |  Branch (16664:11): [True: 216M, False: 0]
  ------------------
16665|   216M|      } else if (p.buf[i] == '?') {
  ------------------
  |  Branch (16665:18): [True: 0, False: 0]
  ------------------
16666|      0|        caps->buf = &s.buf[j], caps->len = 1;     // Finalize `?` cap
16667|      0|        caps++, caps->buf = NULL, caps->len = 0;  // Init next cap
16668|      0|      } else if (caps->buf != NULL && caps->len == 0) {
  ------------------
  |  Branch (16668:18): [True: 0, False: 0]
  |  Branch (16668:39): [True: 0, False: 0]
  ------------------
16669|      0|        caps->len = (size_t) (&s.buf[j] - caps->buf);  // Finalize current cap
16670|      0|        caps++, caps->len = 0, caps->buf = NULL;       // Init next cap
16671|      0|      }
16672|   216M|      i++, j++;
16673|   216M|    } else if (i < p.len && (p.buf[i] == '*' || p.buf[i] == '#')) {
  ------------------
  |  Branch (16673:16): [True: 3.40M, False: 2.59k]
  |  Branch (16673:30): [True: 2.09M, False: 1.31M]
  |  Branch (16673:49): [True: 177k, False: 1.13M]
  ------------------
16674|  2.27M|      if (caps && !caps->buf) caps->len = 0, caps->buf = &s.buf[j];  // Init cap
  ------------------
  |  Branch (16674:11): [True: 0, False: 2.27M]
  |  Branch (16674:19): [True: 0, False: 0]
  ------------------
16675|  2.27M|      ni = i++, nj = j + 1;
16676|  2.27M|    } else if (nj > 0 && nj <= s.len &&
  ------------------
  |  Branch (16676:16): [True: 1.13M, False: 0]
  |  Branch (16676:26): [True: 1.13M, False: 293]
  ------------------
16677|  1.13M|               ((ni < p.len && p.buf[ni] == '#') || s.buf[nj - 1] != '/')) {
  ------------------
  |  Branch (16677:18): [True: 1.13M, False: 0]
  |  Branch (16677:32): [True: 88.7k, False: 1.04M]
  |  Branch (16677:53): [True: 1.04M, False: 284]
  ------------------
16678|  1.13M|      i = ni, j = nj;
16679|  1.13M|      if (caps && caps->buf == NULL && caps->len == 0) {
  ------------------
  |  Branch (16679:11): [True: 0, False: 1.13M]
  |  Branch (16679:19): [True: 0, False: 0]
  |  Branch (16679:40): [True: 0, False: 0]
  ------------------
16680|      0|        caps--, caps->len = 0;  // Restart previous cap
16681|      0|      }
16682|  1.13M|    } else {
16683|    577|      return false;
16684|    577|    }
16685|   219M|  }
16686|  6.26k|  if (caps && caps->buf && caps->len == 0) {
  ------------------
  |  Branch (16686:7): [True: 0, False: 6.26k]
  |  Branch (16686:15): [True: 0, False: 0]
  |  Branch (16686:28): [True: 0, False: 0]
  ------------------
16687|      0|    caps->len = (size_t) (&s.buf[j] - caps->buf);
16688|      0|  }
16689|  6.26k|  return true;
16690|  6.84k|}
mg_span:
16692|  2.19M|bool mg_span(struct mg_str s, struct mg_str *a, struct mg_str *b, char sep) {
16693|  2.19M|  if (s.len == 0 || s.buf == NULL) {
  ------------------
  |  Branch (16693:7): [True: 311k, False: 1.88M]
  |  Branch (16693:21): [True: 0, False: 1.88M]
  ------------------
16694|   311k|    return false;  // Empty string, nothing to span - fail
16695|  1.88M|  } else {
16696|  1.88M|    size_t len = 0;
16697|   602M|    while (len < s.len && s.buf[len] != sep) len++;  // Find separator
  ------------------
  |  Branch (16697:12): [True: 602M, False: 632k]
  |  Branch (16697:27): [True: 600M, False: 1.25M]
  ------------------
16698|  1.88M|    if (a) *a = mg_str_n(s.buf, len);                // Init a
  ------------------
  |  Branch (16698:9): [True: 1.88M, False: 0]
  ------------------
16699|  1.88M|    if (b) *b = mg_str_n(s.buf + len, s.len - len);  // Init b
  ------------------
  |  Branch (16699:9): [True: 1.88M, False: 0]
  ------------------
16700|  1.88M|    if (b && len < s.len) b->buf++, b->len--;        // Skip separator
  ------------------
  |  Branch (16700:9): [True: 1.88M, False: 0]
  |  Branch (16700:14): [True: 1.25M, False: 632k]
  ------------------
16701|  1.88M|    return true;
16702|  1.88M|  }
16703|  2.19M|}
mg_str_to_num:
16705|   112k|bool mg_str_to_num(struct mg_str str, int base, void *val, size_t val_len) {
16706|   112k|  size_t i = 0, ndigits = 0;
16707|   112k|  uint64_t max = val_len == sizeof(uint8_t)    ? 0xFF
  ------------------
  |  Branch (16707:18): [True: 83.8k, False: 29.0k]
  ------------------
16708|   112k|                 : val_len == sizeof(uint16_t) ? 0xFFFF
  ------------------
  |  Branch (16708:20): [True: 0, False: 29.0k]
  ------------------
16709|  29.0k|                 : val_len == sizeof(uint32_t) ? 0xFFFFFFFF
  ------------------
  |  Branch (16709:20): [True: 29.0k, False: 0]
  ------------------
16710|  29.0k|                                               : (uint64_t) ~0;
16711|   112k|  uint64_t result = 0;
16712|   112k|  if (max == (uint64_t) ~0 && val_len != sizeof(uint64_t)) return false;
  ------------------
  |  Branch (16712:7): [True: 0, False: 112k]
  |  Branch (16712:31): [True: 0, False: 0]
  ------------------
16713|   112k|  if (base == 0 && str.len >= 2) {
  ------------------
  |  Branch (16713:7): [True: 0, False: 112k]
  |  Branch (16713:20): [True: 0, False: 0]
  ------------------
16714|      0|    if (str.buf[i] == '0') {
  ------------------
  |  Branch (16714:9): [True: 0, False: 0]
  ------------------
16715|      0|      i++;
16716|      0|      base = str.buf[i] == 'b' ? 2 : str.buf[i] == 'x' ? 16 : 10;
  ------------------
  |  Branch (16716:14): [True: 0, False: 0]
  |  Branch (16716:38): [True: 0, False: 0]
  ------------------
16717|      0|      if (base != 10) ++i;
  ------------------
  |  Branch (16717:11): [True: 0, False: 0]
  ------------------
16718|      0|    } else {
16719|      0|      base = 10;
16720|      0|    }
16721|      0|  }
16722|   112k|  switch (base) {
16723|      0|    case 2:
  ------------------
  |  Branch (16723:5): [True: 0, False: 112k]
  ------------------
16724|      0|      while (i < str.len && (str.buf[i] == '0' || str.buf[i] == '1')) {
  ------------------
  |  Branch (16724:14): [True: 0, False: 0]
  |  Branch (16724:30): [True: 0, False: 0]
  |  Branch (16724:51): [True: 0, False: 0]
  ------------------
16725|      0|        uint64_t digit = (uint64_t) (str.buf[i] - '0');
16726|      0|        if (result > max / 2) return false;  // Overflow
  ------------------
  |  Branch (16726:13): [True: 0, False: 0]
  ------------------
16727|      0|        result *= 2;
16728|      0|        if (result > max - digit) return false;  // Overflow
  ------------------
  |  Branch (16728:13): [True: 0, False: 0]
  ------------------
16729|      0|        result += digit;
16730|      0|        i++, ndigits++;
16731|      0|      }
16732|      0|      break;
16733|      0|    case 10:
  ------------------
  |  Branch (16733:5): [True: 0, False: 112k]
  ------------------
16734|      0|      while (i < str.len && str.buf[i] >= '0' && str.buf[i] <= '9') {
  ------------------
  |  Branch (16734:14): [True: 0, False: 0]
  |  Branch (16734:29): [True: 0, False: 0]
  |  Branch (16734:50): [True: 0, False: 0]
  ------------------
16735|      0|        uint64_t digit = (uint64_t) (str.buf[i] - '0');
16736|      0|        if (result > max / 10) return false;  // Overflow
  ------------------
  |  Branch (16736:13): [True: 0, False: 0]
  ------------------
16737|      0|        result *= 10;
16738|      0|        if (result > max - digit) return false;  // Overflow
  ------------------
  |  Branch (16738:13): [True: 0, False: 0]
  ------------------
16739|      0|        result += digit;
16740|      0|        i++, ndigits++;
16741|      0|      }
16742|      0|      break;
16743|   112k|    case 16:
  ------------------
  |  Branch (16743:5): [True: 112k, False: 0]
  ------------------
16744|  8.77M|      while (i < str.len) {
  ------------------
  |  Branch (16744:14): [True: 8.66M, False: 112k]
  ------------------
16745|  8.66M|        char c = str.buf[i];
16746|  8.66M|        uint64_t digit = (c >= '0' && c <= '9')   ? (uint64_t) (c - '0')
  ------------------
  |  Branch (16746:27): [True: 8.66M, False: 0]
  |  Branch (16746:39): [True: 8.49M, False: 166k]
  ------------------
16747|  8.66M|                         : (c >= 'A' && c <= 'F') ? (uint64_t) (c - '7')
  ------------------
  |  Branch (16747:29): [True: 166k, False: 0]
  |  Branch (16747:41): [True: 14.0k, False: 152k]
  ------------------
16748|   166k|                         : (c >= 'a' && c <= 'f') ? (uint64_t) (c - 'W')
  ------------------
  |  Branch (16748:29): [True: 152k, False: 0]
  |  Branch (16748:41): [True: 152k, False: 0]
  ------------------
16749|   152k|                                                  : (uint64_t) ~0;
16750|  8.66M|        if (digit == (uint64_t) ~0) break;
  ------------------
  |  Branch (16750:13): [True: 0, False: 8.66M]
  ------------------
16751|  8.66M|        if (result > max / 16) return false;  // Overflow
  ------------------
  |  Branch (16751:13): [True: 26, False: 8.66M]
  ------------------
16752|  8.66M|        result *= 16;
16753|  8.66M|        if (result > max - digit) return false;  // Overflow
  ------------------
  |  Branch (16753:13): [True: 0, False: 8.66M]
  ------------------
16754|  8.66M|        result += digit;
16755|  8.66M|        i++, ndigits++;
16756|  8.66M|      }
16757|   112k|      break;
16758|   112k|    default: return false;
  ------------------
  |  Branch (16758:5): [True: 0, False: 112k]
  ------------------
16759|   112k|  }
16760|   112k|  if (ndigits == 0) return false;
  ------------------
  |  Branch (16760:7): [True: 0, False: 112k]
  ------------------
16761|   112k|  if (i != str.len) return false;
  ------------------
  |  Branch (16761:7): [True: 0, False: 112k]
  ------------------
16762|   112k|  if (val_len == 1) {
  ------------------
  |  Branch (16762:7): [True: 83.8k, False: 29.0k]
  ------------------
16763|  83.8k|    *((uint8_t *) val) = (uint8_t) result;
16764|  83.8k|  } else if (val_len == 2) {
  ------------------
  |  Branch (16764:14): [True: 0, False: 29.0k]
  ------------------
16765|      0|    *((uint16_t *) val) = (uint16_t) result;
16766|  29.0k|  } else if (val_len == 4) {
  ------------------
  |  Branch (16766:14): [True: 29.0k, False: 0]
  ------------------
16767|  29.0k|    *((uint32_t *) val) = (uint32_t) result;
16768|  29.0k|  } else {
16769|      0|    *((uint64_t *) val) = (uint64_t) result;
16770|      0|  }
16771|   112k|  return true;
16772|   112k|}
mg_timer_expired:
16794|  6.10k|bool mg_timer_expired(uint64_t *t, uint64_t prd, uint64_t now) {
16795|  6.10k|  if (now + prd < *t) *t = 0;                    // Time wrapped? Reset timer
  ------------------
  |  Branch (16795:7): [True: 0, False: 6.10k]
  ------------------
16796|  6.10k|  if (*t == 0) *t = now + prd;                   // Firt poll? Set expiration
  ------------------
  |  Branch (16796:7): [True: 0, False: 6.10k]
  ------------------
16797|  6.10k|  if (*t > now) return false;                    // Not expired yet, return
  ------------------
  |  Branch (16797:7): [True: 0, False: 6.10k]
  ------------------
16798|  6.10k|  *t = (now - *t) > prd ? now + prd : *t + prd;  // Next expiration time
  ------------------
  |  Branch (16798:8): [True: 0, False: 6.10k]
  ------------------
16799|  6.10k|  return true;                                   // Expired, return true
16800|  6.10k|}
mg_timer_poll:
16802|  6.10k|void mg_timer_poll(struct mg_timer **head, uint64_t now_ms) {
16803|  6.10k|  struct mg_timer *t, *tmp;
16804|  6.10k|  for (t = *head; t != NULL; t = tmp) {
  ------------------
  |  Branch (16804:19): [True: 0, False: 6.10k]
  ------------------
16805|      0|    bool once = t->expire == 0 && (t->flags & MG_TIMER_RUN_NOW) &&
  ------------------
  |  | 1816|      0|#define MG_TIMER_RUN_NOW 2     // Call immediately when timer is set
  ------------------
  |  Branch (16805:17): [True: 0, False: 0]
  |  Branch (16805:35): [True: 0, False: 0]
  ------------------
16806|      0|                !(t->flags & MG_TIMER_CALLED);  // Handle MG_TIMER_NOW only once
  ------------------
  |  | 1817|      0|#define MG_TIMER_CALLED 4      // Timer function was called at least once
  ------------------
  |  Branch (16806:17): [True: 0, False: 0]
  ------------------
16807|      0|    bool expired = mg_timer_expired(&t->expire, t->period_ms, now_ms);
16808|      0|    tmp = t->next;
16809|      0|    if (!once && !expired) continue;
  ------------------
  |  Branch (16809:9): [True: 0, False: 0]
  |  Branch (16809:18): [True: 0, False: 0]
  ------------------
16810|      0|    if ((t->flags & MG_TIMER_REPEAT) || !(t->flags & MG_TIMER_CALLED)) {
  ------------------
  |  | 1815|      0|#define MG_TIMER_REPEAT 1      // Call function periodically
  ------------------
                  if ((t->flags & MG_TIMER_REPEAT) || !(t->flags & MG_TIMER_CALLED)) {
  ------------------
  |  | 1817|      0|#define MG_TIMER_CALLED 4      // Timer function was called at least once
  ------------------
  |  Branch (16810:9): [True: 0, False: 0]
  |  Branch (16810:41): [True: 0, False: 0]
  ------------------
16811|      0|      t->fn(t->arg);
16812|      0|    }
16813|      0|    t->flags |= MG_TIMER_CALLED;
  ------------------
  |  | 1817|      0|#define MG_TIMER_CALLED 4      // Timer function was called at least once
  ------------------
16814|       |
16815|       |    // If this timer is not repeating and marked AUTODELETE, remove it
16816|      0|    if (!(t->flags & MG_TIMER_REPEAT) && (t->flags & MG_TIMER_AUTODELETE)) {
  ------------------
  |  | 1815|      0|#define MG_TIMER_REPEAT 1      // Call function periodically
  ------------------
                  if (!(t->flags & MG_TIMER_REPEAT) && (t->flags & MG_TIMER_AUTODELETE)) {
  ------------------
  |  | 1818|      0|#define MG_TIMER_AUTODELETE 8  // mg_free() timer when done
  ------------------
  |  Branch (16816:9): [True: 0, False: 0]
  |  Branch (16816:42): [True: 0, False: 0]
  ------------------
16817|      0|      mg_timer_free(head, t);
16818|      0|      mg_free(t);
16819|      0|    }
16820|      0|  }
16821|  6.10k|}
mg_tls_free:
22326|  6.10k|void mg_tls_free(struct mg_connection *c) {
22327|  6.10k|  (void) c;
22328|  6.10k|}
mg_tls_ctx_init:
22343|  6.10k|void mg_tls_ctx_init(struct mg_mgr *mgr) {
22344|  6.10k|  (void) mgr;
22345|  6.10k|}
mg_tls_ctx_free:
22346|  6.10k|void mg_tls_ctx_free(struct mg_mgr *mgr) {
22347|  6.10k|  (void) mgr;
22348|  6.10k|}
mg_url_is_ssl:
29656|  6.10k|bool mg_url_is_ssl(const char *url) {
29657|  6.10k|  return strncmp(url, "wss:", 4) == 0 || strncmp(url, "https:", 6) == 0 ||
  ------------------
  |  Branch (29657:10): [True: 0, False: 6.10k]
  |  Branch (29657:42): [True: 0, False: 6.10k]
  ------------------
29658|  6.10k|         strncmp(url, "mqtts:", 6) == 0 || strncmp(url, "ssl:", 4) == 0 ||
  ------------------
  |  Branch (29658:10): [True: 0, False: 6.10k]
  |  Branch (29658:44): [True: 0, False: 6.10k]
  ------------------
29659|  6.10k|         strncmp(url, "tls:", 4) == 0 || strncmp(url, "tcps:", 5) == 0;
  ------------------
  |  Branch (29659:10): [True: 0, False: 6.10k]
  |  Branch (29659:42): [True: 0, False: 6.10k]
  ------------------
29660|  6.10k|}
mg_url_host:
29690|  6.10k|struct mg_str mg_url_host(const char *url) {
29691|  6.10k|  struct url u = urlparse(url);
29692|  6.10k|  size_t n = u.port  ? u.port - u.host - 1
  ------------------
  |  Branch (29692:14): [True: 6.10k, False: 0]
  ------------------
29693|  6.10k|             : u.uri ? u.uri - u.host
  ------------------
  |  Branch (29693:16): [True: 0, False: 0]
  ------------------
29694|      0|                     : u.end - u.host;
29695|  6.10k|  struct mg_str s = mg_str_n(url + u.host, n);
29696|  6.10k|  return s;
29697|  6.10k|}
mg_url_port:
29704|  6.10k|unsigned short mg_url_port(const char *url) {
29705|  6.10k|  struct url u = urlparse(url);
29706|  6.10k|  unsigned short port = 0;
29707|  6.10k|  if (strncmp(url, "http:", 5) == 0 || strncmp(url, "ws:", 3) == 0) port = 80;
  ------------------
  |  Branch (29707:7): [True: 6.10k, False: 0]
  |  Branch (29707:40): [True: 0, False: 0]
  ------------------
29708|  6.10k|  if (strncmp(url, "wss:", 4) == 0 || strncmp(url, "https:", 6) == 0)
  ------------------
  |  Branch (29708:7): [True: 0, False: 6.10k]
  |  Branch (29708:39): [True: 0, False: 6.10k]
  ------------------
29709|      0|    port = 443;
29710|  6.10k|  if (strncmp(url, "mqtt:", 5) == 0) port = 1883;
  ------------------
  |  Branch (29710:7): [True: 0, False: 6.10k]
  ------------------
29711|  6.10k|  if (strncmp(url, "mqtts:", 6) == 0) port = 8883;
  ------------------
  |  Branch (29711:7): [True: 0, False: 6.10k]
  ------------------
29712|  6.10k|  if (u.port) port = (unsigned short) atoi(url + u.port);
  ------------------
  |  Branch (29712:7): [True: 6.10k, False: 0]
  ------------------
29713|  6.10k|  return port;
29714|  6.10k|}
mg_bzero:
29745|  40.3k|void mg_bzero(volatile unsigned char *buf, size_t len) {
29746|  40.3k|  if (buf != NULL) {
  ------------------
  |  Branch (29746:7): [True: 15.9k, False: 24.4k]
  ------------------
29747|   272G|    while (len--) *buf++ = 0;
  ------------------
  |  Branch (29747:12): [True: 272G, False: 15.9k]
  ------------------
29748|  15.9k|  }
29749|  40.3k|}
mg_random:
29777|  11.4k|bool mg_random(void *buf, size_t len) {
29778|  11.4k|  bool success = false;
29779|  11.4k|  unsigned char *p = (unsigned char *) buf;
29780|       |#if MG_ARCH == MG_ARCH_ESP32
29781|       |  while (len--) *p++ = (unsigned char) (esp_random() & 255);
29782|       |  success = true;
29783|       |#elif MG_ARCH == MG_ARCH_CUBE && defined(HAL_RNG_MODULE_ENABLED)
29784|       |  extern RNG_HandleTypeDef hrng;
29785|       |  success = true;
29786|       |  for (size_t n = 0; n < len; n += sizeof(uint32_t)) {
29787|       |    uint32_t r = 0;
29788|       |    if (HAL_RNG_GenerateRandomNumber(&hrng, &r) != HAL_OK) success = false;
29789|       |    memcpy((char *) buf + n, &r, n + sizeof(r) > len ? len - n : sizeof(r));
29790|       |  }
29791|       |#elif MG_ARCH == MG_ARCH_PICOSDK
29792|       |  while (len--) *p++ = (unsigned char) (get_rand_32() & 255);
29793|       |  success = true;
29794|       |#elif MG_ARCH == MG_ARCH_ZEPHYR
29795|       |#if MG_TLS == MG_TLS_BUILTIN ||                                    \
29796|       |    (MG_TLS == MG_TLS_MBED && (!defined(MBEDTLS_VERSION_NUMBER) || \
29797|       |                               MBEDTLS_VERSION_NUMBER < 0x04000000))
29798|       |  return (sys_csrand_get(buf, len) == 0);  // do not fallback on reseed error
29799|       |#else
29800|       |  sys_rand_get(buf, len);
29801|       |  success = true;
29802|       |#endif
29803|       |#elif MG_ARCH == MG_ARCH_WIN32
29804|       |#if defined(_MSC_VER) && _MSC_VER < 1700
29805|       |  static bool initialised = false;
29806|       |  static HCRYPTPROV hProv;
29807|       |  // CryptGenRandom() implementation earlier than 2008 is weak, see
29808|       |  // https://en.wikipedia.org/wiki/CryptGenRandom
29809|       |  if (!initialised) {
29810|       |    initialised = CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
29811|       |                                      CRYPT_VERIFYCONTEXT);
29812|       |  }
29813|       |  if (initialised) success = CryptGenRandom(hProv, len, p);
29814|       |#else
29815|       |  size_t i;
29816|       |  for (i = 0; i < len; i++) {
29817|       |    unsigned int rand_v;
29818|       |    if (rand_s(&rand_v) == 0) {
29819|       |      p[i] = (unsigned char) (rand_v & 255);
29820|       |    } else {
29821|       |      break;
29822|       |    }
29823|       |  }
29824|       |  success = (i == len);
29825|       |#endif
29826|       |
29827|       |#elif MG_ARCH == MG_ARCH_UNIX
29828|       |  FILE *fp = fopen("/dev/urandom", "rb");
29829|  11.4k|  if (fp != NULL) {
  ------------------
  |  Branch (29829:7): [True: 11.4k, False: 0]
  ------------------
29830|  11.4k|    if (fread(buf, 1, len, fp) == len) success = true;
  ------------------
  |  Branch (29830:9): [True: 11.4k, False: 0]
  ------------------
29831|  11.4k|    fclose(fp);
29832|  11.4k|  }
29833|  11.4k|#endif
29834|       |  // If everything above did not work, fallback to a pseudo random generator
29835|  11.4k|  if (success == false) {
  ------------------
  |  Branch (29835:7): [True: 0, False: 11.4k]
  ------------------
29836|      0|    MG_ERROR(("Weak RNG: using rand()"));
  ------------------
  |  | 1802|      0|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
29837|      0|    while (len--) *p++ = (unsigned char) (rand() & 255);
  ------------------
  |  Branch (29837:12): [True: 0, False: 0]
  ------------------
29838|      0|  }
29839|  11.4k|  return success;
29840|  11.4k|}
mg_crc32:
29856|   170k|uint32_t mg_crc32(uint32_t crc, const char *buf, size_t len) {
29857|   170k|  static const uint32_t crclut[16] = {
29858|       |      // table for polynomial 0xEDB88320 (reflected)
29859|   170k|      0x00000000, 0x1DB71064, 0x3B6E20C8, 0x26D930AC, 0x76DC4190, 0x6B6B51F4,
29860|   170k|      0x4DB26158, 0x5005713C, 0xEDB88320, 0xF00F9344, 0xD6D6A3E8, 0xCB61B38C,
29861|   170k|      0x9B64C2B0, 0x86D3D2D4, 0xA00AE278, 0xBDBDF21C};
29862|   170k|  crc = ~crc;
29863|  59.9M|  while (len--) {
  ------------------
  |  Branch (29863:10): [True: 59.7M, False: 170k]
  ------------------
29864|  59.7M|    uint8_t b = *(uint8_t *) buf++;
29865|  59.7M|    crc = crclut[(crc ^ b) & 0x0F] ^ (crc >> 4);
29866|  59.7M|    crc = crclut[(crc ^ (b >> 4)) & 0x0F] ^ (crc >> 4);
29867|  59.7M|  }
29868|   170k|  return ~crc;
29869|   170k|}
mg_crc16:
29871|  3.29k|uint16_t mg_crc16(uint16_t crc, const char *buf, size_t len) {
29872|  3.29k|  static const uint16_t crclut[16] = {
29873|       |      // table for polynomial 0x8408 (reflected)
29874|  3.29k|      0x0000, 0x1081, 0x2102, 0x3183, 0x4204, 0x5285, 0x6306, 0x7387,
29875|  3.29k|      0x8408, 0x9489, 0xA50A, 0xB58B, 0xC60C, 0xD68D, 0xE70E, 0xF78F};
29876|  3.29k|  unsigned int c = (unsigned int) ~crc & 0xffff;
29877|   249k|  while (len--) {
  ------------------
  |  Branch (29877:10): [True: 246k, False: 3.29k]
  ------------------
29878|   246k|    uint8_t b = *(uint8_t *) buf++;
29879|   246k|    c = crclut[(c ^ b) & 0x0F] ^ (c >> 4);
29880|   246k|    c = crclut[(c ^ (b >> 4)) & 0x0F] ^ (c >> 4);
29881|   246k|  }
29882|  3.29k|  return (uint16_t) ~c;
29883|  3.29k|}
mg_path_is_sane:
29922|   254k|bool mg_path_is_sane(const struct mg_str path) {
29923|   254k|  const char *s = path.buf;
29924|   254k|  size_t n = path.len;
29925|   254k|  if (n == 0 || path.buf[0] == '\0') return true;
  ------------------
  |  Branch (29925:7): [True: 0, False: 254k]
  |  Branch (29925:17): [True: 0, False: 254k]
  ------------------
29926|   254k|  if (s[0] == '~') return false;  // Starts with ~
  ------------------
  |  Branch (29926:7): [True: 0, False: 254k]
  ------------------
29927|   254k|  if (s[0] == '.' && n > 1 && s[1] == '.')
  ------------------
  |  Branch (29927:7): [True: 254k, False: 0]
  |  Branch (29927:22): [True: 254k, False: 0]
  |  Branch (29927:31): [True: 0, False: 254k]
  ------------------
29928|      0|    return false;  // Starts with ..
29929|  5.32M|  for (; n > 0 && s[0] != '\0'; s++, n--) {
  ------------------
  |  Branch (29929:10): [True: 5.07M, False: 254k]
  |  Branch (29929:19): [True: 5.07M, False: 0]
  ------------------
29930|  5.07M|    if ((s[0] == '/' || s[0] == '\\') && n >= 2 && s[1] == '.' && n > 2 &&
  ------------------
  |  Branch (29930:10): [True: 4.66M, False: 404k]
  |  Branch (29930:25): [True: 6.72k, False: 397k]
  |  Branch (29930:42): [True: 4.43M, False: 244k]
  |  Branch (29930:52): [True: 31.5k, False: 4.39M]
  |  Branch (29930:67): [True: 31.0k, False: 555]
  ------------------
29931|  31.0k|        s[2] == '.')
  ------------------
  |  Branch (29931:9): [True: 337, False: 30.6k]
  ------------------
29932|    337|      return false;  // Subdir starts with ..
29933|  5.07M|  }
29934|   254k|  if (n > 0) return false;  // embedded nul (terminator not counted in len)
  ------------------
  |  Branch (29934:7): [True: 0, False: 254k]
  ------------------
29935|   254k|  return true;
29936|   254k|}
mg_micros:
29941|  12.4k|uint64_t mg_micros(void) {
29942|       |#if MG_ARCH == MG_ARCH_ESP32
29943|       |  return (uint64_t) esp_timer_get_time();
29944|       |#elif MG_ENABLE_FREERTOS
29945|       |  return (uint64_t) xTaskGetTickCount() * portTICK_PERIOD_MS * 1000;
29946|       |#elif MG_ARCH == MG_ARCH_THREADX
29947|       |  return (uint64_t) tx_time_get() *
29948|       |         (1000 /* MS per SEC */ / TX_TIMER_TICKS_PER_SECOND) * 1000;
29949|       |#elif MG_ARCH == MG_ARCH_TIRTOS
29950|       |  return (uint64_t) Clock_getTicks() * 1000;
29951|       |#elif MG_ARCH == MG_ARCH_ZEPHYR
29952|       |  return k_ticks_to_us_floor64((uint64_t) k_uptime_ticks());
29953|       |#elif MG_ARCH == MG_ARCH_CMSIS_RTOS1
29954|       |  return (uint64_t) rt_time_get() * 1000;
29955|       |#elif MG_ARCH == MG_ARCH_CMSIS_RTOS2
29956|       |  return (uint64_t) ((osKernelGetTickCount() * 1000) / osKernelGetTickFreq()) *
29957|       |         1000;
29958|       |#elif MG_ARCH == MG_ARCH_RTTHREAD
29959|       |  return (uint64_t) ((rt_tick_get() * 1000) / RT_TICK_PER_SECOND) * 1000;
29960|       |#elif MG_ARCH == MG_ARCH_WIN32
29961|       |  return (uint64_t) GetTickCount() * 1000;
29962|       |#elif MG_ARCH == MG_ARCH_PICOSDK
29963|       |  return time_us_64();
29964|       |#elif MG_ARCH == MG_ARCH_CUBE
29965|       |  return (uint64_t) HAL_GetTick() * 1000;
29966|       |#elif MG_ARCH == MG_ARCH_UNIX && defined(__APPLE__)
29967|       |  // Apple CLOCK_MONOTONIC_RAW is equivalent to CLOCK_BOOTTIME on linux
29968|       |  // Apple CLOCK_UPTIME_RAW is equivalent to CLOCK_MONOTONIC_RAW on linux
29969|       |  return clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1000;
29970|       |#elif MG_ARCH == MG_ARCH_UNIX
29971|       |  struct timespec ts = {0, 0};
29972|       |  // See #1615 - prefer monotonic clock
29973|  12.4k|#if defined(CLOCK_MONOTONIC_RAW)
29974|       |  // Raw hardware-based time that is not subject to NTP adjustment
29975|  12.4k|  clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
29976|       |#elif defined(CLOCK_MONOTONIC)
29977|       |  // Affected by the incremental adjustments performed by adjtime and NTP
29978|       |  clock_gettime(CLOCK_MONOTONIC, &ts);
29979|       |#else
29980|       |  // Affected by discontinuous jumps in the system time and by the incremental
29981|       |  // adjustments performed by adjtime and NTP
29982|       |  clock_gettime(CLOCK_REALTIME, &ts);
29983|       |#endif
29984|  12.4k|  return ((uint64_t) ts.tv_sec * 1000000 + (uint64_t) ts.tv_nsec / 1000);
29985|       |#elif defined(ARDUINO)
29986|       |  return (uint64_t) micros();
29987|       |#else
29988|       |  return (uint64_t) time(NULL) * 1000000;
29989|       |#endif
29990|  12.4k|}
mg_millis:
29994|  12.4k|uint64_t mg_millis(void) {
29995|  12.4k|  return mg_micros() / 1000;
29996|  12.4k|}
mg_ntohs:
30000|   104k|uint16_t mg_ntohs(uint16_t net) {
30001|   104k|  return MG_LOAD_BE16(&net);
  ------------------
  |  | 2019|   104k|  ((uint16_t) (((uint16_t) MG_U8P(p)[0] << 8U) | MG_U8P(p)[1]))
  |  |  ------------------
  |  |  |  | 2012|   104k|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  |                 ((uint16_t) (((uint16_t) MG_U8P(p)[0] << 8U) | MG_U8P(p)[1]))
  |  |  ------------------
  |  |  |  | 2012|   104k|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  ------------------
30002|   104k|}
mg_ntohl:
30004|  13.3k|uint32_t mg_ntohl(uint32_t net) {
30005|  13.3k|  return MG_LOAD_BE32(&net);
  ------------------
  |  | 2024|  13.3k|  ((uint32_t) (((uint32_t) MG_U8P(p)[0] << 24U) | \
  |  |  ------------------
  |  |  |  | 2012|  13.3k|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  | 2025|  13.3k|               ((uint32_t) MG_U8P(p)[1] << 16U) | \
  |  |  ------------------
  |  |  |  | 2012|  13.3k|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  | 2026|  13.3k|               ((uint32_t) MG_U8P(p)[2] << 8U) | MG_U8P(p)[3]))
  |  |  ------------------
  |  |  |  | 2012|  13.3k|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  |  |                              ((uint32_t) MG_U8P(p)[2] << 8U) | MG_U8P(p)[3]))
  |  |  ------------------
  |  |  |  | 2012|  13.3k|#define MG_U8P(ADDR) ((uint8_t *) (ADDR))
  |  |  ------------------
  ------------------
30006|  13.3k|}
mg_calloc:
30020|  36.6k|void *mg_calloc(size_t count, size_t size) {
30021|  36.6k|  return calloc(count, size);
30022|  36.6k|}
mg_free:
30024|  67.1k|void mg_free(void *ptr) {
30025|  67.1k|  free(ptr);
30026|  67.1k|}
fuzz.c:_ZL23mg_base64_encode_singlei:
   27|   289M|static int mg_base64_encode_single(int c) {
   28|   289M|  if (c < 26) {
  ------------------
  |  Branch (28:7): [True: 178M, False: 111M]
  ------------------
   29|   178M|    return c + 'A';
   30|   178M|  } else if (c < 52) {
  ------------------
  |  Branch (30:14): [True: 89.5M, False: 22.0M]
  ------------------
   31|  89.5M|    return c - 26 + 'a';
   32|  89.5M|  } else if (c < 62) {
  ------------------
  |  Branch (32:14): [True: 19.6M, False: 2.37M]
  ------------------
   33|  19.6M|    return c - 52 + '0';
   34|  19.6M|  } else {
   35|  2.37M|    return c == 62 ? '+' : '/';
  ------------------
  |  Branch (35:12): [True: 342k, False: 2.03M]
  ------------------
   36|  2.37M|  }
   37|   289M|}
fuzz.c:_ZL23mg_base64_decode_singlei:
   57|  2.94M|static int mg_base64_decode_single(int c) {
   58|  2.94M|  return base64_decode_single(c, '+', '/');
   59|  2.94M|}
fuzz.c:_ZL20base64_decode_singleicc:
   39|  2.94M|static int base64_decode_single(int c, char plus, char slash) {
   40|  2.94M|  if (c >= 'A' && c <= 'Z') {
  ------------------
  |  Branch (40:7): [True: 78.4k, False: 2.86M]
  |  Branch (40:19): [True: 12.3k, False: 66.1k]
  ------------------
   41|  12.3k|    return c - 'A';
   42|  2.93M|  } else if (c >= 'a' && c <= 'z') {
  ------------------
  |  Branch (42:14): [True: 65.0k, False: 2.87M]
  |  Branch (42:26): [True: 64.2k, False: 869]
  ------------------
   43|  64.2k|    return c + 26 - 'a';
   44|  2.87M|  } else if (c >= '0' && c <= '9') {
  ------------------
  |  Branch (44:14): [True: 2.85M, False: 18.0k]
  |  Branch (44:26): [True: 2.85M, False: 3.01k]
  ------------------
   45|  2.85M|    return c + 52 - '0';
   46|  2.85M|  } else if (c == plus) {
  ------------------
  |  Branch (46:14): [True: 2.47k, False: 18.5k]
  ------------------
   47|  2.47k|    return 62;
   48|  18.5k|  } else if (c == slash) {
  ------------------
  |  Branch (48:14): [True: 4.56k, False: 14.0k]
  ------------------
   49|  4.56k|    return 63;
   50|  14.0k|  } else if (c == '=') {
  ------------------
  |  Branch (50:14): [True: 518, False: 13.5k]
  ------------------
   51|    518|    return 64;
   52|  13.5k|  } else {
   53|  13.5k|    return -1;
   54|  13.5k|  }
   55|  2.94M|}
fuzz.c:_ZL17mg_dns_parse_namePKhmmPcm:
 2181|  1.03k|                                char *dst, size_t dstlen) {
 2182|  1.03k|  return mg_dns_parse_name_depth(s, n, ofs, dst, dstlen, 0, 0);
 2183|  1.03k|}
fuzz.c:_ZL23mg_dns_parse_name_depthPKhmmPcmmi:
 2145|  1.68k|                                      int depth) {
 2146|  1.68k|  size_t i = 0;
 2147|  1.68k|  if (tolen > 0 && depth == 0) to[0] = '\0';
  ------------------
  |  Branch (2147:7): [True: 667, False: 1.02k]
  |  Branch (2147:20): [True: 416, False: 251]
  ------------------
 2148|  1.68k|  if (depth > 5) return 0;
  ------------------
  |  Branch (2148:7): [True: 18, False: 1.67k]
  ------------------
 2149|       |  // MG_INFO(("ofs %lx %x %x", (unsigned long) ofs, s[ofs], s[ofs + 1]));
 2150|  4.76k|  while (ofs + i + 1 < len) {
  ------------------
  |  Branch (2150:10): [True: 4.68k, False: 78]
  ------------------
 2151|  4.68k|    size_t n = s[ofs + i];
 2152|  4.68k|    if (n == 0) {
  ------------------
  |  Branch (2152:9): [True: 556, False: 4.13k]
  ------------------
 2153|    556|      i++;
 2154|    556|      break;
 2155|    556|    }
 2156|  4.13k|    if (n & 0xc0) {
  ------------------
  |  Branch (2156:9): [True: 1.00k, False: 3.12k]
  ------------------
 2157|  1.00k|      size_t ptr = (((n & 0x3f) << 8) | s[ofs + i + 1]);  // 12 is hdr len
 2158|       |      // MG_INFO(("PTR %lx", (unsigned long) ptr));
 2159|  1.00k|      if (ptr + 1 < len && (s[ptr] & 0xc0) == 0 &&
  ------------------
  |  Branch (2159:11): [True: 714, False: 289]
  |  Branch (2159:28): [True: 659, False: 55]
  ------------------
 2160|    659|          mg_dns_parse_name_depth(s, len, ptr, to, tolen, j, depth + 1) == 0)
  ------------------
  |  Branch (2160:11): [True: 123, False: 536]
  ------------------
 2161|    123|        return 0;
 2162|    880|      i += 2;
 2163|    880|      break;
 2164|  1.00k|    }
 2165|  3.12k|    if (ofs + i + n + 1 >= len) return 0;
  ------------------
  |  Branch (2165:9): [True: 34, False: 3.09k]
  ------------------
 2166|  3.09k|    if (j > 0) {
  ------------------
  |  Branch (2166:9): [True: 2.71k, False: 380]
  ------------------
 2167|  2.71k|      if (j < tolen) to[j] = '.';
  ------------------
  |  Branch (2167:11): [True: 660, False: 2.05k]
  ------------------
 2168|  2.71k|      j++;
 2169|  2.71k|    }
 2170|  3.09k|    if (j + n < tolen) memcpy(&to[j], &s[ofs + i + 1], n);
  ------------------
  |  Branch (2170:9): [True: 809, False: 2.28k]
  ------------------
 2171|  3.09k|    j += n;
 2172|  3.09k|    i += n + 1;
 2173|  3.09k|    if (j < tolen) to[j] = '\0';  // Zero-terminate this chunk
  ------------------
  |  Branch (2173:9): [True: 809, False: 2.28k]
  ------------------
 2174|       |    // MG_INFO(("--> [%s]", to));
 2175|  3.09k|  }
 2176|  1.51k|  if (tolen > 0) to[tolen - 1] = '\0';  // Make sure it is nul-term
  ------------------
  |  Branch (2176:7): [True: 667, False: 847]
  ------------------
 2177|  1.51k|  return i;
 2178|  1.67k|}
fuzz.c:_ZL8is_digiti:
 3065|  1.96M|static bool is_digit(int c) {
 3066|  1.96M|  return c >= '0' && c <= '9';
  ------------------
  |  Branch (3066:10): [True: 1.70M, False: 260k]
  |  Branch (3066:22): [True: 569k, False: 1.13M]
  ------------------
 3067|  1.96M|}
fuzz.c:_ZL6mg_lldPclbb:
 3172|   569k|static size_t mg_lld(char *buf, int64_t val, bool is_signed, bool is_hex) {
 3173|   569k|  const char *letters = "0123456789abcdef";
 3174|   569k|  uint64_t v = (uint64_t) val;
 3175|   569k|  size_t s = 0, n, i;
 3176|   569k|  if (is_signed && val < 0) buf[s++] = '-', v = (uint64_t) (-val);
  ------------------
  |  Branch (3176:7): [True: 284k, False: 284k]
  |  Branch (3176:20): [True: 0, False: 284k]
  ------------------
 3177|       |  // This loop prints a number in reverse order. I guess this is because we
 3178|       |  // write numbers from right to left: least significant digit comes last.
 3179|       |  // Maybe because we use Arabic numbers, and Arabs write RTL?
 3180|   569k|  if (is_hex) {
  ------------------
  |  Branch (3180:7): [True: 0, False: 569k]
  ------------------
 3181|      0|    for (n = 0; v; v >>= 4) buf[s + n++] = letters[v & 15];
  ------------------
  |  Branch (3181:17): [True: 0, False: 0]
  ------------------
 3182|   569k|  } else {
 3183|  1.99M|    for (n = 0; v; v /= 10) buf[s + n++] = letters[v % 10];
  ------------------
  |  Branch (3183:17): [True: 1.42M, False: 569k]
  ------------------
 3184|   569k|  }
 3185|       |  // Reverse a string
 3186|  1.13M|  for (i = 0; i < n / 2; i++) {
  ------------------
  |  Branch (3186:15): [True: 569k, False: 569k]
  ------------------
 3187|   569k|    char t = buf[s + i];
 3188|   569k|    buf[s + i] = buf[s + n - i - 1], buf[s + n - i - 1] = t;
 3189|   569k|  }
 3190|   569k|  if (val == 0) buf[n++] = '0';  // Handle special case
  ------------------
  |  Branch (3190:7): [True: 0, False: 569k]
  ------------------
 3191|   569k|  return n + s;
 3192|   569k|}
fuzz.c:_ZL4scpyPFvcPvES_Pcm:
 3195|  4.24M|                   size_t len) {
 3196|  4.24M|  size_t i = 0;
 3197|  10.8M|  while (i < len && buf[i] != '\0') out(buf[i++], ptr);
  ------------------
  |  Branch (3197:10): [True: 6.63M, False: 4.24M]
  |  Branch (3197:21): [True: 6.63M, False: 0]
  ------------------
 3198|  4.24M|  return i;
 3199|  4.24M|}
fuzz.c:_ZL6p_statPKcPmPl:
 3675|   745k|static int p_stat(const char *path, size_t *size, time_t *mtime) {
 3676|       |#if !defined(S_ISDIR)
 3677|       |  MG_ERROR(("stat() API is not supported. %p %p %p", path, size, mtime));
 3678|       |  return 0;
 3679|       |#else
 3680|       |#if MG_ARCH == MG_ARCH_WIN32
 3681|       |  struct _stati64 st;
 3682|       |  wchar_t tmp[MG_PATH_MAX];
 3683|       |  MultiByteToWideChar(CP_UTF8, 0, path, -1, tmp, sizeof(tmp) / sizeof(tmp[0]));
 3684|       |  if (_wstati64(tmp, &st) != 0) return 0;
 3685|       |  // If path is a symlink, windows reports 0 in st.st_size.
 3686|       |  // Get a real file size by opening it and jumping to the end
 3687|       |  if (st.st_size == 0 && (st.st_mode & _S_IFREG)) {
 3688|       |    FILE *fp = _wfopen(tmp, L"rb");
 3689|       |    if (fp != NULL) {
 3690|       |      fseek(fp, 0, SEEK_END);
 3691|       |      if (ftell(fp) > 0) st.st_size = ftell(fp);  // Use _ftelli64 on win10+
 3692|       |      fclose(fp);
 3693|       |    }
 3694|       |  }
 3695|       |#else
 3696|   745k|  struct MG_STAT_STRUCT st;
 3697|   745k|  if (MG_STAT_FUNC(path, &st) != 0) return 0;
  ------------------
  |  | 3668|   745k|#define MG_STAT_FUNC stat
  ------------------
  |  Branch (3697:7): [True: 742k, False: 3.19k]
  ------------------
 3698|  3.19k|#endif
 3699|  3.19k|  if (size) *size = (size_t) st.st_size;
  ------------------
  |  Branch (3699:7): [True: 0, False: 3.19k]
  ------------------
 3700|  3.19k|  if (mtime) *mtime = st.st_mtime;
  ------------------
  |  Branch (3700:7): [True: 0, False: 3.19k]
  ------------------
 3701|  3.19k|  return MG_FS_READ | MG_FS_WRITE | (S_ISDIR(st.st_mode) ? MG_FS_DIR : 0);
  ------------------
  |  Branch (3701:38): [True: 3.19k, False: 0]
  ------------------
 3702|   745k|#endif
 3703|   745k|}
fuzz.c:_ZL6p_openPKci:
 3836|  10.2k|static void *p_open(const char *path, int flags) {
 3837|       |#if MG_ARCH == MG_ARCH_WIN32
 3838|       |  const char *mode = flags == MG_FS_READ    ? "rb"
 3839|       |                     : (flags & MG_FS_EXCL) ? "wxb"
 3840|       |                                            : "a+b";
 3841|       |  wchar_t b1[MG_PATH_MAX], b2[10];
 3842|       |  MultiByteToWideChar(CP_UTF8, 0, path, -1, b1, sizeof(b1) / sizeof(b1[0]));
 3843|       |  MultiByteToWideChar(CP_UTF8, 0, mode, -1, b2, sizeof(b2) / sizeof(b2[0]));
 3844|       |  return (void *) _wfopen(b1, b2);
 3845|       |#else
 3846|  10.2k|  const char *mode = flags == MG_FS_READ    ? "rbe"
  ------------------
  |  Branch (3846:22): [True: 10.2k, False: 0]
  ------------------
 3847|  10.2k|                     : (flags & MG_FS_EXCL) ? "wxbe"
  ------------------
  |  Branch (3847:24): [True: 0, False: 0]
  ------------------
 3848|      0|                                            : "a+be"; // e for CLOSEXEC
 3849|  10.2k|  return (void *) fopen(path, mode);
 3850|  10.2k|#endif
 3851|  10.2k|}
fuzz.c:_ZL11mg_ncasecmpPKcS0_m:
 4244|  1.10M|static int mg_ncasecmp(const char *s1, const char *s2, size_t len) {
 4245|  1.10M|  int diff = 0;
 4246|  4.08M|  if (len > 0) do {
  ------------------
  |  Branch (4246:7): [True: 1.10M, False: 0]
  ------------------
 4247|  4.08M|      int c = *s1++, d = *s2++;
 4248|  4.08M|      if (c >= 'A' && c <= 'Z') c += 'a' - 'A';
  ------------------
  |  Branch (4248:11): [True: 3.19M, False: 888k]
  |  Branch (4248:23): [True: 1.28M, False: 1.90M]
  ------------------
 4249|  4.08M|      if (d >= 'A' && d <= 'Z') d += 'a' - 'A';
  ------------------
  |  Branch (4249:11): [True: 3.21M, False: 861k]
  |  Branch (4249:23): [True: 2.81M, False: 407k]
  ------------------
 4250|  4.08M|      diff = c - d;
 4251|  4.08M|    } while (diff == 0 && s1[-1] != '\0' && --len > 0);
  ------------------
  |  Branch (4251:14): [True: 3.30M, False: 772k]
  |  Branch (4251:27): [True: 3.30M, False: 0]
  |  Branch (4251:45): [True: 2.97M, False: 331k]
  ------------------
 4252|  1.10M|  return diff;
 4253|  1.10M|}
fuzz.c:_ZL3isxi:
 4390|   174k|static bool isx(int c) {
 4391|   174k|  return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
  ------------------
  |  Branch (4391:11): [True: 172k, False: 2.51k]
  |  Branch (4391:23): [True: 2.20k, False: 169k]
  |  Branch (4391:37): [True: 154k, False: 18.2k]
  |  Branch (4391:49): [True: 152k, False: 2.15k]
  ------------------
 4392|  20.3k|         (c >= 'A' && c <= 'F');
  ------------------
  |  Branch (4392:11): [True: 17.8k, False: 2.55k]
  |  Branch (4392:23): [True: 15.6k, False: 2.20k]
  ------------------
 4393|   174k|}
fuzz.c:_ZL4isokh:
 4418|   187M|static bool isok(uint8_t c) {
 4419|   187M|  return c == '\n' || c == '\r' || c == '\t' || c >= ' ';
  ------------------
  |  Branch (4419:10): [True: 686k, False: 186M]
  |  Branch (4419:23): [True: 29.0k, False: 186M]
  |  Branch (4419:36): [True: 43.1k, False: 186M]
  |  Branch (4419:49): [True: 186M, False: 3.54k]
  ------------------
 4420|   187M|}
fuzz.c:_ZL4clenPKcS0_:
 4447|  72.0M|static size_t clen(const char *s, const char *end) {
 4448|  72.0M|  const unsigned char *u = (unsigned char *) s, c = *u;
 4449|  72.0M|  long n = (long) (end - s);
 4450|  72.0M|  if (c > ' ' && c <= '~') return 1;  // Usual ascii printed char
  ------------------
  |  Branch (4450:7): [True: 71.4M, False: 562k]
  |  Branch (4450:18): [True: 71.3M, False: 43.8k]
  ------------------
 4451|   606k|  if ((c & 0xe0) == 0xc0 && n > 1 && vcb(u[1])) return 2;  // 2-byte UTF8
  ------------------
  |  Branch (4451:7): [True: 17.1k, False: 589k]
  |  Branch (4451:29): [True: 17.1k, False: 0]
  |  Branch (4451:38): [True: 9.52k, False: 7.61k]
  ------------------
 4452|   596k|  if ((c & 0xf0) == 0xe0 && n > 2 && vcb(u[1]) && vcb(u[2])) return 3;
  ------------------
  |  Branch (4452:7): [True: 8.94k, False: 587k]
  |  Branch (4452:29): [True: 8.94k, False: 0]
  |  Branch (4452:38): [True: 8.09k, False: 855]
  |  Branch (4452:51): [True: 7.51k, False: 581]
  ------------------
 4453|   589k|  if ((c & 0xf8) == 0xf0 && n > 3 && vcb(u[1]) && vcb(u[2]) && vcb(u[3]))
  ------------------
  |  Branch (4453:7): [True: 15.3k, False: 573k]
  |  Branch (4453:29): [True: 14.1k, False: 1.25k]
  |  Branch (4453:38): [True: 11.6k, False: 2.51k]
  |  Branch (4453:51): [True: 10.1k, False: 1.46k]
  |  Branch (4453:64): [True: 5.49k, False: 4.65k]
  ------------------
 4454|  5.49k|    return 4;
 4455|   583k|  return 0;
 4456|   589k|}
fuzz.c:_ZL3vcbh:
 4442|  70.0k|static bool vcb(uint8_t c) {
 4443|  70.0k|  return (c & 0xc0) == 0x80;
 4444|  70.0k|}
fuzz.c:_ZL8skiptornPKcS0_P6mg_str:
 4459|   350k|static const char *skiptorn(const char *s, const char *end, struct mg_str *v) {
 4460|   350k|  v->buf = (char *) s;
 4461|  51.5M|  while (s < end && s[0] != '\n' && s[0] != '\r') s++, v->len++;  // To newline
  ------------------
  |  Branch (4461:10): [True: 51.5M, False: 0]
  |  Branch (4461:21): [True: 51.2M, False: 327k]
  |  Branch (4461:37): [True: 51.1M, False: 22.4k]
  ------------------
 4462|   350k|  if (s >= end || (s[0] == '\r' && s[1] != '\n')) return NULL;    // Stray \r
  ------------------
  |  Branch (4462:7): [True: 0, False: 350k]
  |  Branch (4462:20): [True: 22.4k, False: 327k]
  |  Branch (4462:36): [True: 317, False: 22.0k]
  ------------------
 4463|   349k|  if (s < end && s[0] == '\r') s++;                               // Skip \r
  ------------------
  |  Branch (4463:7): [True: 349k, False: 0]
  |  Branch (4463:18): [True: 22.0k, False: 327k]
  ------------------
 4464|   349k|  if (s >= end || *s++ != '\n') return NULL;                      // Skip \n
  ------------------
  |  Branch (4464:7): [True: 0, False: 349k]
  |  Branch (4464:19): [True: 0, False: 349k]
  ------------------
 4465|   349k|  return s;
 4466|   349k|}
fuzz.c:_ZL21mg_http_parse_headersPKcS0_P14mg_http_headerm:
 4469|   290k|                                  struct mg_http_header *h, size_t max_hdrs) {
 4470|   290k|  size_t i, n;
 4471|   290k|  int cl_count = 0, te_count = 0, auth_count = 0;
 4472|   290k|  int conn_count = 0, cookie_count = 0;
 4473|   349k|  for (i = 0; i < max_hdrs; i++) {
  ------------------
  |  Branch (4473:15): [True: 348k, False: 459]
  ------------------
 4474|   348k|    struct mg_str k = {NULL, 0}, v = {NULL, 0};
 4475|   348k|    if (s >= end) return false;
  ------------------
  |  Branch (4475:9): [True: 0, False: 348k]
  ------------------
 4476|   348k|    if (s[0] == '\n' || (s[0] == '\r' && s[1] == '\n')) break;
  ------------------
  |  Branch (4476:9): [True: 285k, False: 63.2k]
  |  Branch (4476:26): [True: 4.11k, False: 59.1k]
  |  Branch (4476:42): [True: 4.10k, False: 9]
  ------------------
 4477|  59.1k|    k.buf = (char *) s;
 4478|  44.0M|    while (s < end && s[0] != ':' && (n = clen(s, end)) > 0) s += n, k.len += n;
  ------------------
  |  Branch (4478:12): [True: 44.0M, False: 0]
  |  Branch (4478:23): [True: 43.9M, False: 58.7k]
  |  Branch (4478:38): [True: 43.9M, False: 420]
  ------------------
 4479|  59.1k|    if (k.len == 0) return false;                     // Empty name
  ------------------
  |  Branch (4479:9): [True: 103, False: 59.0k]
  ------------------
 4480|  59.0k|    if (s >= end || clen(s, end) == 0) return false;  // Invalid UTF-8
  ------------------
  |  Branch (4480:9): [True: 0, False: 59.0k]
  |  Branch (4480:21): [True: 335, False: 58.7k]
  ------------------
 4481|  58.7k|    if (*s++ != ':') return false;  // Invalid, not followed by :
  ------------------
  |  Branch (4481:9): [True: 0, False: 58.7k]
  ------------------
 4482|       |    // if (clen(s, end) == 0) return false;        // Invalid UTF-8
 4483|  86.7k|    while (s < end && (s[0] == ' ' || s[0] == '\t')) s++;  // Skip spaces
  ------------------
  |  Branch (4483:12): [True: 86.7k, False: 0]
  |  Branch (4483:24): [True: 27.8k, False: 58.9k]
  |  Branch (4483:39): [True: 190, False: 58.7k]
  ------------------
 4484|  58.7k|    if ((s = skiptorn(s, end, &v)) == NULL) return false;
  ------------------
  |  Branch (4484:9): [True: 16, False: 58.7k]
  ------------------
 4485|  61.3k|    while (v.len > 0 && (v.buf[v.len - 1] == ' ' || v.buf[v.len - 1] == '\t')) {
  ------------------
  |  Branch (4485:12): [True: 46.4k, False: 14.8k]
  |  Branch (4485:26): [True: 2.32k, False: 44.1k]
  |  Branch (4485:53): [True: 298, False: 43.8k]
  ------------------
 4486|  2.61k|      v.len--;  // Trim spaces
 4487|  2.61k|    }
 4488|       |    // detect duplicated headers -> discard
 4489|  58.7k|    if (((mg_strcasecmp(k, mg_str("Content-Length")) == 0) &&
  ------------------
  |  | 1503|  58.7k|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (4489:10): [True: 3.42k, False: 55.3k]
  ------------------
 4490|  3.42k|         (++cl_count > 1)) ||
  ------------------
  |  Branch (4490:10): [True: 3, False: 3.41k]
  ------------------
 4491|  58.7k|        ((mg_strcasecmp(k, mg_str("Transfer-Encoding")) == 0) &&
  ------------------
  |  | 1503|  58.7k|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (4491:10): [True: 14.4k, False: 44.2k]
  ------------------
 4492|  14.4k|         (++te_count > 1)) ||
  ------------------
  |  Branch (4492:10): [True: 3, False: 14.4k]
  ------------------
 4493|  58.7k|        ((mg_strcasecmp(k, mg_str("Authorization")) == 0) &&
  ------------------
  |  | 1503|  58.7k|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (4493:10): [True: 0, False: 58.7k]
  ------------------
 4494|      0|         (++auth_count > 1)) ||
  ------------------
  |  Branch (4494:10): [True: 0, False: 0]
  ------------------
 4495|  58.7k|        ((mg_strcasecmp(k, mg_str("Cookie")) == 0) && (++cookie_count > 1)) ||
  ------------------
  |  | 1503|  58.7k|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (4495:10): [True: 0, False: 58.7k]
  |  Branch (4495:55): [True: 0, False: 0]
  ------------------
 4496|  58.7k|        ((mg_strcasecmp(k, mg_str("Connection")) == 0) && (++conn_count > 1)))
  ------------------
  |  | 1503|  58.7k|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (4496:10): [True: 404, False: 58.3k]
  |  Branch (4496:59): [True: 3, False: 401]
  ------------------
 4497|      9|      return false;
 4498|       |    // MG_INFO(("--HH [%.*s] [%.*s]", (int) k.len, k.buf, (int) v.len, v.buf));
 4499|  58.7k|    h[i].name = k, h[i].value = v;  // Success. Assign values
 4500|  58.7k|  }
 4501|   289k|  if (i == max_hdrs &&
  ------------------
  |  Branch (4501:7): [True: 459, False: 289k]
  ------------------
 4502|    459|      !(s < end &&
  ------------------
  |  Branch (4502:9): [True: 459, False: 0]
  ------------------
 4503|    459|        (s[0] == '\n' ||
  ------------------
  |  Branch (4503:10): [True: 331, False: 128]
  ------------------
 4504|    128|         (s[0] == '\r' && s + 1 < end && s[1] == '\n')))) {
  ------------------
  |  Branch (4504:11): [True: 106, False: 22]
  |  Branch (4504:27): [True: 106, False: 0]
  |  Branch (4504:42): [True: 100, False: 6]
  ------------------
 4505|     28|    return false;
 4506|     28|  }
 4507|   289k|  return true;
 4508|   289k|}
fuzz.c:_ZL23mg_http_status_code_stri:
 4619|   284k|static const char *mg_http_status_code_str(int status_code) {
 4620|   284k|  switch (status_code) {
 4621|      0|    case 100: return "Continue";
  ------------------
  |  Branch (4621:5): [True: 0, False: 284k]
  ------------------
 4622|      0|    case 101: return "Switching Protocols";
  ------------------
  |  Branch (4622:5): [True: 0, False: 284k]
  ------------------
 4623|      0|    case 102: return "Processing";
  ------------------
  |  Branch (4623:5): [True: 0, False: 284k]
  ------------------
 4624|      0|    case 200: return "OK";
  ------------------
  |  Branch (4624:5): [True: 0, False: 284k]
  ------------------
 4625|      0|    case 201: return "Created";
  ------------------
  |  Branch (4625:5): [True: 0, False: 284k]
  ------------------
 4626|      0|    case 202: return "Accepted";
  ------------------
  |  Branch (4626:5): [True: 0, False: 284k]
  ------------------
 4627|      0|    case 203: return "Non-authoritative Information";
  ------------------
  |  Branch (4627:5): [True: 0, False: 284k]
  ------------------
 4628|      0|    case 204: return "No Content";
  ------------------
  |  Branch (4628:5): [True: 0, False: 284k]
  ------------------
 4629|      0|    case 205: return "Reset Content";
  ------------------
  |  Branch (4629:5): [True: 0, False: 284k]
  ------------------
 4630|      0|    case 206: return "Partial Content";
  ------------------
  |  Branch (4630:5): [True: 0, False: 284k]
  ------------------
 4631|      0|    case 207: return "Multi-Status";
  ------------------
  |  Branch (4631:5): [True: 0, False: 284k]
  ------------------
 4632|      0|    case 208: return "Already Reported";
  ------------------
  |  Branch (4632:5): [True: 0, False: 284k]
  ------------------
 4633|      0|    case 226: return "IM Used";
  ------------------
  |  Branch (4633:5): [True: 0, False: 284k]
  ------------------
 4634|      0|    case 300: return "Multiple Choices";
  ------------------
  |  Branch (4634:5): [True: 0, False: 284k]
  ------------------
 4635|      0|    case 301: return "Moved Permanently";
  ------------------
  |  Branch (4635:5): [True: 0, False: 284k]
  ------------------
 4636|      0|    case 302: return "Found";
  ------------------
  |  Branch (4636:5): [True: 0, False: 284k]
  ------------------
 4637|      0|    case 303: return "See Other";
  ------------------
  |  Branch (4637:5): [True: 0, False: 284k]
  ------------------
 4638|      0|    case 304: return "Not Modified";
  ------------------
  |  Branch (4638:5): [True: 0, False: 284k]
  ------------------
 4639|      0|    case 305: return "Use Proxy";
  ------------------
  |  Branch (4639:5): [True: 0, False: 284k]
  ------------------
 4640|      0|    case 307: return "Temporary Redirect";
  ------------------
  |  Branch (4640:5): [True: 0, False: 284k]
  ------------------
 4641|      0|    case 308: return "Permanent Redirect";
  ------------------
  |  Branch (4641:5): [True: 0, False: 284k]
  ------------------
 4642|  30.8k|    case 400: return "Bad Request";
  ------------------
  |  Branch (4642:5): [True: 30.8k, False: 254k]
  ------------------
 4643|      0|    case 401: return "Unauthorized";
  ------------------
  |  Branch (4643:5): [True: 0, False: 284k]
  ------------------
 4644|      0|    case 402: return "Payment Required";
  ------------------
  |  Branch (4644:5): [True: 0, False: 284k]
  ------------------
 4645|   244k|    case 403: return "Forbidden";
  ------------------
  |  Branch (4645:5): [True: 244k, False: 40.8k]
  ------------------
 4646|  10.0k|    case 404: return "Not Found";
  ------------------
  |  Branch (4646:5): [True: 10.0k, False: 274k]
  ------------------
 4647|      0|    case 405: return "Method Not Allowed";
  ------------------
  |  Branch (4647:5): [True: 0, False: 284k]
  ------------------
 4648|      0|    case 406: return "Not Acceptable";
  ------------------
  |  Branch (4648:5): [True: 0, False: 284k]
  ------------------
 4649|      0|    case 407: return "Proxy Authentication Required";
  ------------------
  |  Branch (4649:5): [True: 0, False: 284k]
  ------------------
 4650|      0|    case 408: return "Request Timeout";
  ------------------
  |  Branch (4650:5): [True: 0, False: 284k]
  ------------------
 4651|      0|    case 409: return "Conflict";
  ------------------
  |  Branch (4651:5): [True: 0, False: 284k]
  ------------------
 4652|      0|    case 410: return "Gone";
  ------------------
  |  Branch (4652:5): [True: 0, False: 284k]
  ------------------
 4653|      0|    case 411: return "Length Required";
  ------------------
  |  Branch (4653:5): [True: 0, False: 284k]
  ------------------
 4654|      0|    case 412: return "Precondition Failed";
  ------------------
  |  Branch (4654:5): [True: 0, False: 284k]
  ------------------
 4655|      0|    case 413: return "Payload Too Large";
  ------------------
  |  Branch (4655:5): [True: 0, False: 284k]
  ------------------
 4656|      0|    case 414: return "Request-URI Too Long";
  ------------------
  |  Branch (4656:5): [True: 0, False: 284k]
  ------------------
 4657|      0|    case 415: return "Unsupported Media Type";
  ------------------
  |  Branch (4657:5): [True: 0, False: 284k]
  ------------------
 4658|      0|    case 416: return "Requested Range Not Satisfiable";
  ------------------
  |  Branch (4658:5): [True: 0, False: 284k]
  ------------------
 4659|      0|    case 417: return "Expectation Failed";
  ------------------
  |  Branch (4659:5): [True: 0, False: 284k]
  ------------------
 4660|      0|    case 418: return "I'm a teapot";
  ------------------
  |  Branch (4660:5): [True: 0, False: 284k]
  ------------------
 4661|      0|    case 421: return "Misdirected Request";
  ------------------
  |  Branch (4661:5): [True: 0, False: 284k]
  ------------------
 4662|      0|    case 422: return "Unprocessable Entity";
  ------------------
  |  Branch (4662:5): [True: 0, False: 284k]
  ------------------
 4663|      0|    case 423: return "Locked";
  ------------------
  |  Branch (4663:5): [True: 0, False: 284k]
  ------------------
 4664|      0|    case 424: return "Failed Dependency";
  ------------------
  |  Branch (4664:5): [True: 0, False: 284k]
  ------------------
 4665|      0|    case 426: return "Upgrade Required";
  ------------------
  |  Branch (4665:5): [True: 0, False: 284k]
  ------------------
 4666|      0|    case 428: return "Precondition Required";
  ------------------
  |  Branch (4666:5): [True: 0, False: 284k]
  ------------------
 4667|      0|    case 429: return "Too Many Requests";
  ------------------
  |  Branch (4667:5): [True: 0, False: 284k]
  ------------------
 4668|      0|    case 431: return "Request Header Fields Too Large";
  ------------------
  |  Branch (4668:5): [True: 0, False: 284k]
  ------------------
 4669|      0|    case 444: return "Connection Closed Without Response";
  ------------------
  |  Branch (4669:5): [True: 0, False: 284k]
  ------------------
 4670|      0|    case 451: return "Unavailable For Legal Reasons";
  ------------------
  |  Branch (4670:5): [True: 0, False: 284k]
  ------------------
 4671|      0|    case 499: return "Client Closed Request";
  ------------------
  |  Branch (4671:5): [True: 0, False: 284k]
  ------------------
 4672|      0|    case 500: return "Internal Server Error";
  ------------------
  |  Branch (4672:5): [True: 0, False: 284k]
  ------------------
 4673|      0|    case 501: return "Not Implemented";
  ------------------
  |  Branch (4673:5): [True: 0, False: 284k]
  ------------------
 4674|      0|    case 502: return "Bad Gateway";
  ------------------
  |  Branch (4674:5): [True: 0, False: 284k]
  ------------------
 4675|      0|    case 503: return "Service Unavailable";
  ------------------
  |  Branch (4675:5): [True: 0, False: 284k]
  ------------------
 4676|      0|    case 504: return "Gateway Timeout";
  ------------------
  |  Branch (4676:5): [True: 0, False: 284k]
  ------------------
 4677|      0|    case 505: return "HTTP Version Not Supported";
  ------------------
  |  Branch (4677:5): [True: 0, False: 284k]
  ------------------
 4678|      0|    case 506: return "Variant Also Negotiates";
  ------------------
  |  Branch (4678:5): [True: 0, False: 284k]
  ------------------
 4679|      0|    case 507: return "Insufficient Storage";
  ------------------
  |  Branch (4679:5): [True: 0, False: 284k]
  ------------------
 4680|      0|    case 508: return "Loop Detected";
  ------------------
  |  Branch (4680:5): [True: 0, False: 284k]
  ------------------
 4681|      0|    case 510: return "Not Extended";
  ------------------
  |  Branch (4681:5): [True: 0, False: 284k]
  ------------------
 4682|      0|    case 511: return "Network Authentication Required";
  ------------------
  |  Branch (4682:5): [True: 0, False: 284k]
  ------------------
 4683|      0|    case 599: return "Network Connect Timeout Error";
  ------------------
  |  Branch (4683:5): [True: 0, False: 284k]
  ------------------
 4684|      0|    default: return "";
  ------------------
  |  Branch (4684:5): [True: 0, False: 284k]
  ------------------
 4685|   284k|  }
 4686|   284k|}
fuzz.c:_ZL18guess_content_type6mg_strPKc:
 4780|  10.0k|static struct mg_str guess_content_type(struct mg_str path, const char *extra) {
 4781|  10.0k|  struct mg_str entry, k, v, s = mg_str(extra), asterisk = mg_str_n("*", 1);
  ------------------
  |  | 1503|  10.0k|#define mg_str(s) mg_str_s(s)
  ------------------
 4782|  10.0k|  size_t i = 0;
 4783|       |
 4784|       |  // Shrink path to its extension only
 4785|   165k|  while (i < path.len && path.buf[path.len - i - 1] != '.') i++;
  ------------------
  |  Branch (4785:10): [True: 165k, False: 0]
  |  Branch (4785:26): [True: 155k, False: 10.0k]
  ------------------
 4786|  10.0k|  path.buf += path.len - i;
 4787|  10.0k|  path.len = i;
 4788|       |
 4789|       |  // Process user-provided mime type overrides, if any
 4790|  10.0k|  while (mg_span(s, &entry, &s, ',')) {
  ------------------
  |  Branch (4790:10): [True: 0, False: 10.0k]
  ------------------
 4791|      0|    if (mg_span(entry, &k, &v, '=') &&
  ------------------
  |  Branch (4791:9): [True: 0, False: 0]
  ------------------
 4792|      0|        (mg_strcmp(asterisk, k) == 0 || mg_strcmp(path, k) == 0))
  ------------------
  |  Branch (4792:10): [True: 0, False: 0]
  |  Branch (4792:41): [True: 0, False: 0]
  ------------------
 4793|      0|      return v;
 4794|      0|  }
 4795|       |
 4796|       |  // Process built-in mime types
 4797|   319k|  for (i = 0; s_known_types[i].buf != NULL; i += 2) {
  ------------------
  |  Branch (4797:15): [True: 309k, False: 9.97k]
  ------------------
 4798|   309k|    if (mg_strcmp(path, s_known_types[i]) == 0) return s_known_types[i + 1];
  ------------------
  |  Branch (4798:9): [True: 74, False: 309k]
  ------------------
 4799|   309k|  }
 4800|       |
 4801|  9.97k|  return mg_str("text/plain; charset=utf-8");
  ------------------
  |  | 1503|  9.97k|#define mg_str(s) mg_str_s(s)
  ------------------
 4802|  10.0k|}
fuzz.c:_ZL18uri_to_file_statusP13mg_connectionP15mg_http_messageP5mg_fsPKcPcm:
 5006|   285k|                              char *path, size_t path_size) {
 5007|   285k|  int flags, tmp;
 5008|   285k|  size_t n;
 5009|   285k|  if (!uri2path(root_dir, hm->uri, path, path_size)) {
  ------------------
  |  Branch (5009:7): [True: 30.8k, False: 254k]
  ------------------
 5010|  30.8k|    mg_http_reply(c, 400, "", "Invalid path");
 5011|  30.8k|    return -1;
 5012|  30.8k|  }
 5013|   254k|  n = strlen(path);
 5014|   254k|  flags = mg_strcmp(hm->uri, mg_str("/")) == 0 ? MG_FS_DIR
  ------------------
  |  | 1503|   254k|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (5014:11): [True: 241k, False: 13.2k]
  ------------------
 5015|   254k|                                               : fs->st(path, NULL, NULL);
 5016|   254k|  MG_VERBOSE(("%lu %.*s -> %s %d", c->id, (int) hm->uri.len, hm->uri.buf, path,
  ------------------
  |  | 1805|   254k|#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)
  |  |  ------------------
  |  |  |  | 1792|   254k|  do {                      \
  |  |  |  | 1793|   254k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 254k]
  |  |  |  |  ------------------
  |  |  |  | 1794|   254k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 254k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5017|   254k|              flags));
 5018|   254k|  if (flags == 0) {
  ------------------
  |  Branch (5018:7): [True: 10.0k, False: 244k]
  ------------------
 5019|       |    // Do nothing - let's caller decide
 5020|   244k|  } else if ((flags & MG_FS_DIR) && hm->uri.len > 0 &&
  ------------------
  |  Branch (5020:14): [True: 244k, False: 0]
  |  Branch (5020:37): [True: 244k, False: 0]
  ------------------
 5021|   244k|             hm->uri.buf[hm->uri.len - 1] != '/') {
  ------------------
  |  Branch (5021:14): [True: 526, False: 244k]
  ------------------
 5022|    526|    mg_printf(c,
 5023|    526|              "HTTP/1.1 301 Moved\r\n"
 5024|    526|              "Location: %.*s/\r\n"
 5025|    526|              "Content-Length: 0\r\n"
 5026|    526|              "\r\n",
 5027|    526|              (int) hm->uri.len, hm->uri.buf);
 5028|    526|    c->pfn_data = NULL;  // Response done
 5029|    526|    flags = -1;
 5030|   244k|  } else if (flags & MG_FS_DIR) {
  ------------------
  |  Branch (5030:14): [True: 244k, False: 0]
  ------------------
 5031|   244k|    if (((mg_snprintf(path + n, path_size - n, "/" MG_HTTP_INDEX) > 0 &&
  ------------------
  |  | 1259|   244k|#define MG_HTTP_INDEX "index.html"
  ------------------
  |  Branch (5031:11): [True: 244k, False: 0]
  ------------------
 5032|   244k|          (tmp = fs->st(path, NULL, NULL)) != 0) ||
  ------------------
  |  Branch (5032:11): [True: 0, False: 244k]
  ------------------
 5033|   244k|         (mg_snprintf(path + n, path_size - n, "/index.shtml") > 0 &&
  ------------------
  |  Branch (5033:11): [True: 244k, False: 0]
  ------------------
 5034|   244k|          (tmp = fs->st(path, NULL, NULL)) != 0))) {
  ------------------
  |  Branch (5034:11): [True: 0, False: 244k]
  ------------------
 5035|      0|      flags = tmp;
 5036|   244k|    } else if ((mg_snprintf(path + n, path_size - n, "/" MG_HTTP_INDEX ".gz") >
  ------------------
  |  Branch (5036:17): [True: 244k, False: 0]
  ------------------
 5037|   244k|                    0 &&
 5038|   244k|                (tmp = fs->st(path, NULL, NULL)) !=
  ------------------
  |  Branch (5038:17): [True: 0, False: 244k]
  ------------------
 5039|   244k|                    0)) {  // check for gzipped index
 5040|      0|      flags = tmp;
 5041|      0|      path[n + 1 + strlen(MG_HTTP_INDEX)] =
  ------------------
  |  | 1259|      0|#define MG_HTTP_INDEX "index.html"
  ------------------
 5042|      0|          '\0';  // Remove appended .gz in index file name
 5043|   244k|    } else {
 5044|   244k|      path[n] = '\0';  // Remove appended index file name
 5045|   244k|    }
 5046|   244k|  }
 5047|   254k|  return flags;
 5048|   285k|}
fuzz.c:_ZL8uri2pathPKc6mg_strPcm:
 4973|   285k|static bool uri2path(const char *r, struct mg_str uri, char *buf, size_t len) {
 4974|   285k|  struct mg_str k, v, part, s = mg_str(r), u = {NULL, 0}, d = u;
  ------------------
  |  | 1503|   285k|#define mg_str(s) mg_str_s(s)
  ------------------
 4975|   285k|  size_t n;
 4976|   285k|  bool matched = false;
 4977|   570k|  while (mg_span(s, &part, &s, ',')) {
  ------------------
  |  Branch (4977:10): [True: 285k, False: 285k]
  ------------------
 4978|   285k|    if (!mg_span(part, &k, &v, '=')) k = part, v = mg_str_n(NULL, 0);
  ------------------
  |  Branch (4978:9): [True: 0, False: 285k]
  ------------------
 4979|   285k|    if (v.len == 0) v = k, k = mg_str("/"), u = k, d = v;
  ------------------
  |  | 1503|   285k|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (4979:9): [True: 285k, False: 0]
  ------------------
 4980|   285k|    if (uri.len < k.len) continue;
  ------------------
  |  Branch (4980:9): [True: 0, False: 285k]
  ------------------
 4981|   285k|    if (mg_strcmp(k, mg_str_n(uri.buf, k.len)) != 0) continue;
  ------------------
  |  Branch (4981:9): [True: 25.7k, False: 259k]
  ------------------
 4982|   259k|    u = k, d = v, matched = true;
 4983|   259k|  }
 4984|   285k|  if (!matched) return false;
  ------------------
  |  Branch (4984:7): [True: 25.7k, False: 259k]
  ------------------
 4985|   259k|  n = mg_snprintf(buf, len, "%.*s", (int) d.len, d.buf);
 4986|   259k|  if (len == 0 || n + 2 >= len) return false;  // Path overflow
  ------------------
  |  Branch (4986:7): [True: 0, False: 259k]
  |  Branch (4986:19): [True: 0, False: 259k]
  ------------------
 4987|   259k|  if (n > 0 && buf[n - 1] != '/') buf[n++] = '/', buf[n] = '\0';  // Add slash
  ------------------
  |  Branch (4987:7): [True: 259k, False: 0]
  |  Branch (4987:16): [True: 259k, False: 0]
  ------------------
 4988|   259k|  {
 4989|   259k|    int dn;
 4990|   259k|    size_t p = n;
 4991|   259k|    dn = mg_url_decode(uri.buf + u.len, uri.len - u.len, buf + n, len - n, 0);
 4992|   259k|    if (dn < 0) return false;  // reject on malformed
  ------------------
  |  Branch (4992:9): [True: 4.63k, False: 255k]
  ------------------
 4993|   255k|    buf[len - 1] = '\0';  // Double-check
 4994|   255k|    n = strlen(buf);
 4995|   255k|    if (n != p + (size_t) dn) return false;  // reject on embedded NULs
  ------------------
  |  Branch (4995:9): [True: 90, False: 254k]
  ------------------
 4996|   255k|  }
 4997|   254k|  if (!mg_path_is_sane(mg_str_n(buf, n))) return false;
  ------------------
  |  Branch (4997:7): [True: 337, False: 254k]
  ------------------
 4998|   602k|  while (n > 1 && buf[n - 1] == '/') buf[--n] = 0;  // Trim trailing slashes
  ------------------
  |  Branch (4998:10): [True: 360k, False: 242k]
  |  Branch (4998:19): [True: 348k, False: 12.4k]
  ------------------
 4999|   254k|  return true;
 5000|   254k|}
fuzz.c:_ZL7http_cbP13mg_connectioniPv:
 5377|   609k|static void http_cb(struct mg_connection *c, int ev, void *ev_data) {
 5378|   609k|  if (ev == MG_EV_READ || ev == MG_EV_CLOSE ||
  ------------------
  |  Branch (5378:7): [True: 6.10k, False: 603k]
  |  Branch (5378:27): [True: 6.10k, False: 597k]
  ------------------
 5379|   597k|      (ev == MG_EV_POLL && c->is_accepted && !c->is_draining &&
  ------------------
  |  Branch (5379:8): [True: 6.10k, False: 591k]
  |  Branch (5379:28): [True: 0, False: 6.10k]
  |  Branch (5379:46): [True: 0, False: 0]
  ------------------
 5380|  12.2k|       c->recv.len > 0)) {  // see #2796
  ------------------
  |  Branch (5380:8): [True: 0, False: 0]
  ------------------
 5381|  12.2k|    struct mg_http_message hm;
 5382|  12.2k|    size_t ofs = 0;  // Parsing offset
 5383|       |    // c->pfn_data is the "response generation in progress" marker. While it
 5384|       |    // is set, don't parse the next pipelined request, to keep responses in order
 5385|   297k|    while (c->pfn_data == NULL && ofs < c->recv.len) {
  ------------------
  |  Branch (5385:12): [True: 297k, False: 0]
  |  Branch (5385:35): [True: 293k, False: 4.19k]
  ------------------
 5386|   293k|      const char *buf = (char *) c->recv.buf + ofs;
 5387|   293k|      int n = mg_http_parse(buf, c->recv.len - ofs, &hm);
 5388|   293k|      struct mg_str *te;  // Transfer - encoding header
 5389|   293k|      bool is_chunked = false, is_http_1_0 = false;
 5390|   293k|      size_t old_len = c->recv.len;
 5391|   293k|      if (n < 0) {
  ------------------
  |  Branch (5391:11): [True: 2.65k, False: 290k]
  ------------------
 5392|       |        // We don't use mg_error() here, to avoid closing pipelined requests
 5393|       |        // prematurely, see #2592
 5394|  2.65k|        MG_ERROR(("HTTP parse, %lu bytes", c->recv.len));
  ------------------
  |  | 1802|  2.65k|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|  2.65k|  do {                      \
  |  |  |  | 1793|  2.65k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 2.65k]
  |  |  |  |  ------------------
  |  |  |  | 1794|  2.65k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 2.65k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5395|  2.65k|        c->is_draining = 1;
 5396|  2.65k|        mg_hexdump(buf, c->recv.len - ofs > 16 ? 16 : c->recv.len - ofs);
  ------------------
  |  Branch (5396:25): [True: 1.71k, False: 947]
  ------------------
 5397|  2.65k|        c->recv.len = 0;
 5398|  2.65k|        return;
 5399|  2.65k|      }
 5400|   290k|      if (n == 0) break;                 // Request is not buffered yet
  ------------------
  |  Branch (5400:11): [True: 3.27k, False: 287k]
  ------------------
 5401|   287k|      mg_call(c, MG_EV_HTTP_HDRS, &hm);  // Got all HTTP headers
 5402|   287k|      if (c->recv.len != old_len) {
  ------------------
  |  Branch (5402:11): [True: 0, False: 287k]
  ------------------
 5403|       |        // User manipulated received data. Wash our hands
 5404|      0|        MG_DEBUG(("%lu detaching HTTP handler", c->id));
  ------------------
  |  | 1804|      0|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5405|      0|        c->pfn = NULL;
 5406|      0|        return;
 5407|      0|      }
 5408|   287k|      if (ev == MG_EV_CLOSE) {  // If client did not set Content-Length
  ------------------
  |  Branch (5408:11): [True: 7.38k, False: 280k]
  ------------------
 5409|  7.38k|        hm.message.len = c->recv.len - ofs;  // and closes now, deliver MSG
 5410|  7.38k|        hm.body.len = hm.message.len - (size_t) (hm.body.buf - hm.message.buf);
 5411|  7.38k|      }
 5412|   287k|      is_http_1_0 =
 5413|   287k|          hm.proto.len == 8 && mg_ncasecmp(hm.proto.buf, "HTTP/1.0", 8) == 0;
  ------------------
  |  Branch (5413:11): [True: 254k, False: 32.5k]
  |  Branch (5413:32): [True: 2.43k, False: 252k]
  ------------------
 5414|       |      // HTTP/1.0 does not use "Transfer-Encoding: chunked"
 5415|   287k|      if (!is_http_1_0 &&
  ------------------
  |  Branch (5415:11): [True: 285k, False: 2.43k]
  ------------------
 5416|   285k|          (te = mg_http_get_header(&hm, "Transfer-Encoding")) != NULL) {
  ------------------
  |  Branch (5416:11): [True: 13.9k, False: 271k]
  ------------------
 5417|  13.9k|        if (mg_strcasecmp(*te, mg_str("chunked")) == 0) {
  ------------------
  |  | 1503|  13.9k|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (5417:13): [True: 13.4k, False: 436]
  ------------------
 5418|  13.4k|          is_chunked = true;
 5419|  13.4k|        } else {
 5420|    436|          mg_error(c, "Invalid Transfer-Encoding");  // See #2460
 5421|    436|          return;
 5422|    436|        }
 5423|   273k|      } else if (mg_http_get_header(&hm, "Content-length") == NULL) {
  ------------------
  |  Branch (5423:18): [True: 270k, False: 2.91k]
  ------------------
 5424|       |        // #2593: HTTP packets must contain either Transfer-Encoding or
 5425|       |        // Content-length
 5426|   270k|        bool is_response = mg_ncasecmp(hm.method.buf, "HTTP/", 5) == 0;
 5427|   270k|        bool require_content_len = false;
 5428|   270k|        if (!is_response && (mg_strcasecmp(hm.method, mg_str("POST")) == 0 ||
  ------------------
  |  | 1503|   253k|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (5428:13): [True: 253k, False: 17.1k]
  |  Branch (5428:30): [True: 222, False: 253k]
  ------------------
 5429|   253k|                             mg_strcasecmp(hm.method, mg_str("PUT")) == 0)) {
  ------------------
  |  | 1503|   253k|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (5429:30): [True: 262, False: 253k]
  ------------------
 5430|       |          // POST and PUT should include an entity body. Therefore, they should
 5431|       |          // contain a Content-length header (unless the body length is 0, in
 5432|       |          // which case it can be omitted). Other requests can also contain a
 5433|       |          // body, but their content has no defined semantics (RFC-7231)
 5434|       |          // It is a non-chunked request, so the offset (ofs) is updated after
 5435|       |          // exiting this branch.
 5436|    484|          if (hm.body.len != 0) require_content_len = true;
  ------------------
  |  Branch (5436:15): [True: 9, False: 475]
  ------------------
 5437|   270k|        } else if (is_response) {
  ------------------
  |  Branch (5437:20): [True: 17.1k, False: 253k]
  ------------------
 5438|       |          // HTTP spec 7.2 Entity body: All other responses must include a body
 5439|       |          // or Content-Length header field defined with a value of 0.
 5440|  17.1k|          int status = mg_http_status(&hm);
 5441|  17.1k|          require_content_len = status >= 200 && status != 204 && status != 304;
  ------------------
  |  Branch (5441:33): [True: 15.4k, False: 1.72k]
  |  Branch (5441:50): [True: 158, False: 15.2k]
  |  Branch (5441:67): [True: 152, False: 6]
  ------------------
 5442|  17.1k|        }
 5443|   270k|        if (require_content_len) {
  ------------------
  |  Branch (5443:13): [True: 161, False: 270k]
  ------------------
 5444|    161|          if (!c->is_client) mg_http_reply(c, 411, "", "");
  ------------------
  |  Branch (5444:15): [True: 0, False: 161]
  ------------------
 5445|    161|          MG_ERROR(("Content length missing from %s",
  ------------------
  |  | 1802|    161|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|    161|  do {                      \
  |  |  |  | 1793|    161|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 161]
  |  |  |  |  |  Branch (1793:19): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|    161|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 161]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5446|    161|                    is_response ? "response" : "request"));
 5447|    161|        }
 5448|   270k|      }
 5449|       |
 5450|   287k|      if (is_chunked) {
  ------------------
  |  Branch (5450:11): [True: 13.4k, False: 273k]
  ------------------
 5451|       |        // For chunked data, strip off prefixes and suffixes from chunks
 5452|       |        // and relocate them right after the headers, then report a message
 5453|  13.4k|        char *s = (char *) c->recv.buf + ofs + n;
 5454|  13.4k|        int o = 0, pl, dl, cl, len = (int) (c->recv.len - ofs - (size_t) n);
 5455|       |
 5456|       |        // Find zero-length chunk (the end of the body)
 5457|  15.3k|        while ((cl = skip_chunk(s + o, len - o, &pl, &dl)) > 0 && dl) o += cl;
  ------------------
  |  Branch (5457:16): [True: 14.9k, False: 427]
  |  Branch (5457:67): [True: 1.85k, False: 13.0k]
  ------------------
 5458|  13.4k|        if (cl == 0) break;  // No zero-len chunk, buffer more data
  ------------------
  |  Branch (5458:13): [True: 144, False: 13.3k]
  ------------------
 5459|  13.3k|        if (cl < 0) {
  ------------------
  |  Branch (5459:13): [True: 283, False: 13.0k]
  ------------------
 5460|    283|          mg_error(c, "Invalid chunk");
 5461|    283|          break;
 5462|    283|        }
 5463|       |
 5464|       |        // Zero chunk found. Second pass: strip + relocate
 5465|  13.0k|        o = 0, hm.body.len = 0, hm.message.len = (size_t) n;
 5466|  13.8k|        while ((cl = skip_chunk(s + o, len - o, &pl, &dl)) > 0) {
  ------------------
  |  Branch (5466:16): [True: 13.8k, False: 0]
  ------------------
 5467|  13.8k|          memmove(s + hm.body.len, s + o + pl, (size_t) dl);
 5468|  13.8k|          o += cl, hm.body.len += (size_t) dl, hm.message.len += (size_t) dl;
 5469|  13.8k|          if (dl == 0) break;
  ------------------
  |  Branch (5469:15): [True: 13.0k, False: 827]
  ------------------
 5470|  13.8k|        }
 5471|  13.0k|        ofs += (size_t) (n + o);
 5472|   273k|      } else {  // Normal, non-chunked data
 5473|   273k|        size_t len = c->recv.len - ofs - (size_t) n;
 5474|   273k|        if (hm.body.len > len) break;  // Buffer more data
  ------------------
  |  Branch (5474:13): [True: 1.22k, False: 272k]
  ------------------
 5475|   272k|        ofs += (size_t) n + hm.body.len;
 5476|   272k|      }
 5477|       |
 5478|   285k|      if (c->is_accepted) c->pfn_data = c;  // Response started
  ------------------
  |  Branch (5478:11): [True: 0, False: 285k]
  ------------------
 5479|   285k|      mg_call(c, MG_EV_HTTP_MSG, &hm);  // Handler sets pfn_data NULL when done
 5480|   285k|      if (c->is_accepted && c->pfn_data == NULL) {
  ------------------
  |  Branch (5480:11): [True: 0, False: 285k]
  |  Branch (5480:29): [True: 0, False: 0]
  ------------------
 5481|      0|        struct mg_str *cc = mg_http_get_header(&hm, "Connection");
 5482|      0|        if (cc != NULL && mg_strcasecmp(*cc, mg_str("close")) == 0) {
  ------------------
  |  | 1503|      0|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (5482:13): [True: 0, False: 0]
  |  Branch (5482:27): [True: 0, False: 0]
  ------------------
 5483|      0|          c->is_draining = 1;  // honor "Connection: close"
 5484|      0|          break;
 5485|      0|        }
 5486|      0|      }
 5487|   285k|    }
 5488|  9.10k|    if (ofs > 0) mg_iobuf_del(&c->recv, 0, ofs);  // Delete processed data
  ------------------
  |  Branch (5488:9): [True: 1.74k, False: 7.36k]
  ------------------
 5489|  9.10k|  }
 5490|   606k|  (void) ev_data;
 5491|   606k|}
fuzz.c:_ZL10skip_chunkPKciPiS1_:
 5362|  29.2k|static int skip_chunk(const char *buf, int len, int *pl, int *dl) {
 5363|  29.2k|  int i = 0, n = 0;  // pass int to mg_str_to_num, treats as unsigned
 5364|  29.2k|  if (len < 3) return 0;
  ------------------
  |  Branch (5364:7): [True: 20, False: 29.1k]
  ------------------
 5365|  11.2M|  while (i < len && is_hex_digit(buf[i])) i++;
  ------------------
  |  Branch (5365:10): [True: 11.2M, False: 26]
  |  Branch (5365:21): [True: 11.2M, False: 29.1k]
  ------------------
 5366|  29.1k|  if (i == 0) return -1;  // Error, no length specified
  ------------------
  |  Branch (5366:7): [True: 23, False: 29.1k]
  ------------------
 5367|  29.1k|  if (len < i + 2 || buf[i] != '\r' || buf[i + 1] != '\n') return -1;  // Error
  ------------------
  |  Branch (5367:7): [True: 38, False: 29.1k]
  |  Branch (5367:22): [True: 41, False: 29.0k]
  |  Branch (5367:40): [True: 13, False: 29.0k]
  ------------------
 5368|  29.0k|  if (mg_str_to_num(mg_str_n(buf, (size_t) i), 16, &n, sizeof(n)) == false)
  ------------------
  |  Branch (5368:7): [True: 26, False: 29.0k]
  ------------------
 5369|     26|    return -1;                    // Decode chunk length, overflow
 5370|  29.0k|  if (n < 0) return -1;           // Chunk length is too big <0 = >0x80000000
  ------------------
  |  Branch (5370:7): [True: 66, False: 28.9k]
  ------------------
 5371|  28.9k|  if (n > len - i - 4) return 0;  // Chunk not yet fully buffered
  ------------------
  |  Branch (5371:7): [True: 124, False: 28.8k]
  ------------------
 5372|  28.8k|  if (buf[i + n + 2] != '\r' || buf[i + n + 3] != '\n') return -1;  // Error
  ------------------
  |  Branch (5372:7): [True: 42, False: 28.8k]
  |  Branch (5372:33): [True: 34, False: 28.7k]
  ------------------
 5373|  28.7k|  *pl = i + 2, *dl = n;
 5374|  28.7k|  return i + 2 + n + 2;
 5375|  28.8k|}
fuzz.c:_ZL12is_hex_digiti:
 5357|  11.2M|static bool is_hex_digit(int c) {
 5358|  11.2M|  return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
  ------------------
  |  Branch (5358:11): [True: 11.2M, False: 29.1k]
  |  Branch (5358:23): [True: 11.1M, False: 38.6k]
  |  Branch (5358:37): [True: 37.6k, False: 30.1k]
  |  Branch (5358:49): [True: 37.6k, False: 8]
  ------------------
 5359|  30.1k|         (c >= 'A' && c <= 'F');
  ------------------
  |  Branch (5359:11): [True: 1.04k, False: 29.1k]
  |  Branch (5359:23): [True: 1.02k, False: 25]
  ------------------
 5360|  11.2M|}
fuzz.c:_ZL7roundupmm:
 5513|  38.6k|static size_t roundup(size_t size, size_t align) {
 5514|  38.6k|  return align == 0 ? size : (size + align - 1) / align * align;
  ------------------
  |  Branch (5514:10): [True: 0, False: 38.6k]
  ------------------
 5515|  38.6k|}
fuzz.c:_ZL7mg_atodPKciPi:
 5610|   243k|static double mg_atod(const char *p, int len, int *numlen) {
 5611|   243k|  double d = 0.0;
 5612|   243k|  int i = 0, sign = 1;
 5613|       |
 5614|       |  // Sign
 5615|   243k|  if (i < len && *p == '-') {
  ------------------
  |  Branch (5615:7): [True: 243k, False: 0]
  |  Branch (5615:18): [True: 116k, False: 126k]
  ------------------
 5616|   116k|    sign = -1, i++;
 5617|   126k|  } else if (i < len && *p == '+') {
  ------------------
  |  Branch (5617:14): [True: 126k, False: 0]
  |  Branch (5617:25): [True: 0, False: 126k]
  ------------------
 5618|      0|    i++;
 5619|      0|  }
 5620|       |
 5621|       |  // Decimal
 5622|  14.6M|  for (; i < len && p[i] >= '0' && p[i] <= '9'; i++) {
  ------------------
  |  Branch (5622:10): [True: 14.6M, False: 136]
  |  Branch (5622:21): [True: 14.4M, False: 193k]
  |  Branch (5622:36): [True: 14.4M, False: 50.0k]
  ------------------
 5623|  14.4M|    d *= 10.0;
 5624|  14.4M|    d += p[i] - '0';
 5625|  14.4M|  }
 5626|   243k|  d *= sign;
 5627|       |
 5628|       |  // Fractional
 5629|   243k|  if (i < len && p[i] == '.') {
  ------------------
  |  Branch (5629:7): [True: 243k, False: 136]
  |  Branch (5629:18): [True: 89.5k, False: 153k]
  ------------------
 5630|  89.5k|    double frac = 0.0, base = 0.1;
 5631|  89.5k|    i++;
 5632|  3.55M|    for (; i < len && p[i] >= '0' && p[i] <= '9'; i++) {
  ------------------
  |  Branch (5632:12): [True: 3.55M, False: 78]
  |  Branch (5632:23): [True: 3.46M, False: 89.4k]
  |  Branch (5632:38): [True: 3.46M, False: 79]
  ------------------
 5633|  3.46M|      frac += base * (p[i] - '0');
 5634|  3.46M|      base /= 10.0;
 5635|  3.46M|    }
 5636|  89.5k|    d += frac * sign;
 5637|  89.5k|  }
 5638|       |
 5639|       |  // Exponential
 5640|   243k|  if (i < len && (p[i] == 'e' || p[i] == 'E')) {
  ------------------
  |  Branch (5640:7): [True: 243k, False: 214]
  |  Branch (5640:19): [True: 3.23k, False: 239k]
  |  Branch (5640:34): [True: 45.8k, False: 193k]
  ------------------
 5641|  49.0k|    int exp = 0, minus = 0;
 5642|  49.0k|    i++;
 5643|  49.0k|    if (i < len && p[i] == '-') minus = 1, i++;
  ------------------
  |  Branch (5643:9): [True: 49.0k, False: 37]
  |  Branch (5643:20): [True: 38.1k, False: 10.9k]
  ------------------
 5644|  49.0k|    if (i < len && p[i] == '+') i++;
  ------------------
  |  Branch (5644:9): [True: 49.0k, False: 56]
  |  Branch (5644:20): [True: 1.22k, False: 47.8k]
  ------------------
 5645|  3.26M|    while (i < len && p[i] >= '0' && p[i] <= '9' && exp < 308)
  ------------------
  |  Branch (5645:12): [True: 3.26M, False: 274]
  |  Branch (5645:23): [True: 3.21M, False: 46.8k]
  |  Branch (5645:38): [True: 3.21M, False: 1.91k]
  |  Branch (5645:53): [True: 3.21M, False: 54]
  ------------------
 5646|  3.21M|      exp = exp * 10 + (p[i++] - '0');
 5647|       |    // use fast exponentiation
 5648|       |    // https://en.wikipedia.org/wiki/Exponentiation_by_squaring
 5649|  49.0k|    if (exp != 0) {
  ------------------
  |  Branch (5649:9): [True: 44.4k, False: 4.59k]
  ------------------
 5650|  44.4k|      double x = 10, y = 1;
 5651|  44.4k|      if (exp > 308) exp = 308;
  ------------------
  |  Branch (5651:11): [True: 640, False: 43.8k]
  ------------------
 5652|  44.4k|      if (minus) x = 0.1;
  ------------------
  |  Branch (5652:11): [True: 37.4k, False: 6.99k]
  ------------------
 5653|   238k|      while (exp > 1) {
  ------------------
  |  Branch (5653:14): [True: 194k, False: 44.4k]
  ------------------
 5654|   194k|        if (exp & 1) {
  ------------------
  |  Branch (5654:13): [True: 59.3k, False: 135k]
  ------------------
 5655|  59.3k|          y *= x;
 5656|  59.3k|          --exp;
 5657|  59.3k|        }
 5658|   194k|        x *= x;
 5659|   194k|        exp >>= 1;
 5660|   194k|      }
 5661|  44.4k|      d *= x * y;
 5662|  44.4k|    }
 5663|  49.0k|  }
 5664|       |
 5665|   243k|  if (numlen != NULL) *numlen = i;
  ------------------
  |  Branch (5665:7): [True: 243k, False: 0]
  ------------------
 5666|   243k|  return d;
 5667|   243k|}
fuzz.c:_ZL14mg_pass_stringPKci:
 5596|  13.8k|static int mg_pass_string(const char *s, int len) {
 5597|  13.8k|  int i;
 5598|  38.5M|  for (i = 0; i < len; i++) {
  ------------------
  |  Branch (5598:15): [True: 38.5M, False: 465]
  ------------------
 5599|  38.5M|    if (s[i] == '\\' && i + 1 < len && json_esc(s[i + 1], 1)) {
  ------------------
  |  Branch (5599:9): [True: 575k, False: 37.9M]
  |  Branch (5599:25): [True: 575k, False: 22]
  |  Branch (5599:40): [True: 248k, False: 327k]
  ------------------
 5600|   248k|      i++;
 5601|  38.3M|    } else if (s[i] == '\0') {
  ------------------
  |  Branch (5601:16): [True: 130, False: 38.3M]
  ------------------
 5602|    130|      return MG_JSON_INVALID;
 5603|  38.3M|    } else if (s[i] == '"') {
  ------------------
  |  Branch (5603:16): [True: 13.2k, False: 38.2M]
  ------------------
 5604|  13.2k|      return i;
 5605|  13.2k|    }
 5606|  38.5M|  }
 5607|    465|  return MG_JSON_INVALID;
 5608|  13.8k|}
fuzz.c:_ZL8json_escii:
 5588|   575k|static char json_esc(int c, int esc) {
 5589|   575k|  const char *p, *esc1 = escapeseq(esc), *esc2 = escapeseq(!esc);
 5590|  3.90M|  for (p = esc1; *p != '\0'; p++) {
  ------------------
  |  Branch (5590:18): [True: 3.58M, False: 327k]
  ------------------
 5591|  3.58M|    if (*p == c) return esc2[p - esc1];
  ------------------
  |  Branch (5591:9): [True: 248k, False: 3.33M]
  ------------------
 5592|  3.58M|  }
 5593|   327k|  return 0;
 5594|   575k|}
fuzz.c:_ZL9escapeseqi:
 5584|  1.15M|static const char *escapeseq(int esc) {
 5585|  1.15M|  return esc ? "\b\f\n\r\t\\\"" : "bfnrt\\\"";
  ------------------
  |  Branch (5585:10): [True: 575k, False: 575k]
  ------------------
 5586|  1.15M|}
fuzz.c:_ZL13l2_ppp_header10mg_l2protoPh:
 6613|  4.06k|static uint8_t *l2_ppp_header(enum mg_l2proto proto, uint8_t *p) {
 6614|  4.06k|  uint16_t ppp_proto = proto == MG_TCPIP_L2PROTO_IPV4   ? MG_PPP_PROTO_IP
  ------------------
  |  | 6535|  4.06k|#define MG_PPP_PROTO_IP 0x0021
  ------------------
  |  Branch (6614:24): [True: 4.06k, False: 0]
  ------------------
 6615|  4.06k|                       : proto == MG_TCPIP_L2PROTO_IPV4 ? MG_PPP_PROTO_IPV6
  ------------------
  |  | 6536|      0|#define MG_PPP_PROTO_IPV6 0x0057
  ------------------
  |  Branch (6615:26): [True: 0, False: 0]
  ------------------
 6616|      0|                                                        : 0;
 6617|  4.06k|  return ppp_header(ppp_proto, p);
 6618|  4.06k|}
fuzz.c:_ZL10ppp_headertPh:
 6607|  5.32k|static uint8_t *ppp_header(uint16_t proto, uint8_t *p) {
 6608|  5.32k|  struct ppp *ppp = (struct ppp *) p;
 6609|  5.32k|  ppp->proto = mg_htons(proto);
  ------------------
  |  | 2093|  5.32k|#define mg_htons(x) mg_ntohs(x)
  ------------------
 6610|  5.32k|  return (uint8_t *) (ppp + 1);
 6611|  5.32k|}
fuzz.c:_ZL11hdlc_headerPh:
 6600|  3.29k|static uint8_t *hdlc_header(uint8_t *p) {
 6601|  3.29k|  struct hdlc_ *hdlc = (struct hdlc_ *) p;
 6602|  3.29k|  hdlc->addr = MG_PPP_ADDR;
  ------------------
  |  | 6532|  3.29k|#define MG_PPP_ADDR 0xff
  ------------------
 6603|  3.29k|  hdlc->ctrl = MG_PPP_CTRL;
  ------------------
  |  | 6533|  3.29k|#define MG_PPP_CTRL 0x03
  ------------------
 6604|  3.29k|  return (uint8_t *) (hdlc + 1);
 6605|  3.29k|}
fuzz.c:_ZL12pppoe_headerP11mg_tcpip_if10mg_l2protohtP9mg_l2addrS3_Ph:
 6635|  2.03k|                             struct mg_l2addr *dst, uint8_t *frame) {
 6636|  2.03k|  struct pppoe *pppoe =
 6637|  2.03k|      (struct pppoe *) mg_l2_eth_header(ifp, proto, src, dst, frame);
 6638|  2.03k|  pppoe->vertype = 0x11;
 6639|  2.03k|  pppoe->code = code;
 6640|  2.03k|  pppoe->id = id;
 6641|  2.03k|  return (uint8_t *) (pppoe + 1);
 6642|  2.03k|}
fuzz.c:_ZL13pppoe_trailerP11mg_tcpip_ifmPh:
 6667|  2.03k|static size_t pppoe_trailer(struct mg_tcpip_if *ifp, size_t len, uint8_t *cur) {
 6668|  2.03k|  struct pppoe *pppoe = (struct pppoe *) (cur - len - sizeof(struct pppoe));
 6669|  2.03k|  pppoe->len = mg_htons((uint16_t) len);
  ------------------
  |  | 2093|  2.03k|#define mg_htons(x) mg_ntohs(x)
  ------------------
 6670|  2.03k|  return mg_l2_eth_trailer(ifp, PDIFF(pppoe, cur), cur);
  ------------------
  |  | 6575|  2.03k|#define PDIFF(a, b) ((size_t) (((char *) (b)) - ((char *) (a))))
  ------------------
 6671|  2.03k|}
fuzz.c:_ZL6ppp_rxP11mg_tcpip_ifP10mg_l2protoP6mg_strS4_:
 6885|  1.50k|                   struct mg_str *pay, struct mg_str *raw) {
 6886|  1.50k|  struct ppp *ppp = (struct ppp *) pay->buf;
 6887|  1.50k|  if (pay->len < sizeof(*ppp)) return false;  // Truncated
  ------------------
  |  Branch (6887:7): [True: 1, False: 1.50k]
  ------------------
 6888|  1.50k|  pay->buf = (char *) (ppp + 1);
 6889|  1.50k|  pay->len = pay->len - sizeof(*ppp);
 6890|  1.50k|  switch (mg_ntohs(ppp->proto)) {
 6891|     26|    case MG_PPP_PROTO_LCP:
  ------------------
  |  | 6537|     26|#define MG_PPP_PROTO_LCP 0xc021
  ------------------
  |  Branch (6891:5): [True: 26, False: 1.47k]
  ------------------
 6892|     26|      ppp_handle_lcp(ifp, (uint8_t *) pay->buf, pay->len);
 6893|     26|      return false;
 6894|     29|    case MG_PPP_PROTO_IPCP:
  ------------------
  |  | 6538|     29|#define MG_PPP_PROTO_IPCP 0x8021
  ------------------
  |  Branch (6894:5): [True: 29, False: 1.47k]
  ------------------
 6895|     29|      if (s_lcpup) ppp_handle_ipcp(ifp, (uint8_t *) pay->buf, pay->len);
  ------------------
  |  Branch (6895:11): [True: 29, False: 0]
  ------------------
 6896|     29|      return false;
 6897|     24|    case MG_PPP_PROTO_IP:
  ------------------
  |  | 6535|     24|#define MG_PPP_PROTO_IP 0x0021
  ------------------
  |  Branch (6897:5): [True: 24, False: 1.47k]
  ------------------
 6898|     24|      if (!s_lcpup) return false;
  ------------------
  |  Branch (6898:11): [True: 0, False: 24]
  ------------------
 6899|     24|      MG_VERBOSE(("got IP packet of %d bytes", pay->len));
  ------------------
  |  | 1805|     24|#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)
  |  |  ------------------
  |  |  |  | 1792|     24|  do {                      \
  |  |  |  | 1793|     24|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 24]
  |  |  |  |  ------------------
  |  |  |  | 1794|     24|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 24]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6900|     24|      *proto = MG_TCPIP_L2PROTO_IPV4;
 6901|     24|      break;
 6902|       |#if MG_ENABLE_IPV6
 6903|       |    case MG_PPP_PROTO_IPV6CP:
 6904|       |      if (s_lcpup) ppp_handle_ipv6cp(ifp, (uint8_t *) pay->buf, pay->len);
 6905|       |      return false;
 6906|       |    case MG_PPP_PROTO_IPV6:
 6907|       |      if (!s_lcpup) return false;
 6908|       |      MG_VERBOSE(("got IPv6 packet of %d bytes", pay->len));
 6909|       |      *proto = MG_TCPIP_L2PROTO_IPV6;
 6910|       |      break;
 6911|       |#endif
 6912|  1.42k|    default: {
  ------------------
  |  Branch (6912:5): [True: 1.42k, False: 79]
  ------------------
 6913|  1.42k|      struct lcp rej;
 6914|  1.42k|      uint8_t *p;
 6915|  1.42k|      size_t msglen;
 6916|  1.42k|      MG_DEBUG(("unknown %u-byte PPP frame with proto 0x%04x:",
  ------------------
  |  | 1804|  1.42k|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|  1.42k|  do {                      \
  |  |  |  | 1793|  1.42k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 1.42k]
  |  |  |  |  ------------------
  |  |  |  | 1794|  1.42k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 1.42k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6917|  1.42k|                pay->len + sizeof(*ppp), mg_ntohs(ppp->proto)));
 6918|  1.42k|      if (mg_log_level >= MG_LL_DEBUG)
  ------------------
  |  Branch (6918:11): [True: 0, False: 1.42k]
  ------------------
 6919|      0|        mg_hexdump(ppp, pay->len > 14 ? 16 : pay->len + sizeof(*ppp));
  ------------------
  |  Branch (6919:25): [True: 0, False: 0]
  ------------------
 6920|  1.42k|      if (!s_lcpup) return false;  // RFC-1661 5.7: must reject on link down
  ------------------
  |  Branch (6920:11): [True: 185, False: 1.23k]
  ------------------
 6921|  1.23k|      if (pay->len > (size_t) (ifp->mtu - 20))
  ------------------
  |  Branch (6921:11): [True: 0, False: 1.23k]
  ------------------
 6922|      0|        pay->len = (size_t) (ifp->mtu - 20);  // truncate to some safe limit
 6923|  1.23k|      rej.code = MG_PPP_LCP_REJECT;
  ------------------
  |  | 6549|  1.23k|#define MG_PPP_LCP_REJECT 8
  ------------------
 6924|  1.23k|      mg_random(&rej.id, sizeof(rej.id));
 6925|  1.23k|      msglen = pay->len + sizeof(*ppp);
 6926|  1.23k|      rej.len = mg_htons((uint16_t) (msglen + sizeof(rej)));
  ------------------
  |  | 2093|  1.23k|#define mg_htons(x) mg_ntohs(x)
  ------------------
 6927|  1.23k|      p = ppp_tx_frame_header(ifp, MG_PPP_PROTO_LCP);
  ------------------
  |  | 6537|  1.23k|#define MG_PPP_PROTO_LCP 0xc021
  ------------------
 6928|  1.23k|      memmove(p, &rej, sizeof(rej));          // LCP reject
 6929|  1.23k|      memmove(p + sizeof(rej), ppp, msglen);  // rejected PPP message
 6930|  1.23k|      ppp_tx_frame_trailer(ifp, msglen + sizeof(rej), p + msglen + sizeof(rej));
 6931|  1.23k|    }
 6932|      0|      return false;
 6933|  1.50k|  }
 6934|     24|  (void) raw;
 6935|     24|  return true;
 6936|  1.50k|}
fuzz.c:_ZL14ppp_handle_lcpP11mg_tcpip_ifPhm:
 6703|     26|                           size_t lcpsz) {
 6704|     26|  uint8_t id;
 6705|     26|  uint16_t len;
 6706|     26|  struct lcp *lcp = (struct lcp *) lcpp;
 6707|     26|  if (lcpsz < sizeof(*lcp)) return;
  ------------------
  |  Branch (6707:7): [True: 2, False: 24]
  ------------------
 6708|     24|  id = lcp->id;
 6709|     24|  len = mg_ntohs(lcp->len);
 6710|     24|  if (len < sizeof(*lcp) || len > lcpsz) return;
  ------------------
  |  Branch (6710:7): [True: 1, False: 23]
  |  Branch (6710:29): [True: 14, False: 9]
  ------------------
 6711|      9|  switch (lcp->code) {
  ------------------
  |  Branch (6711:11): [True: 5, False: 4]
  ------------------
 6712|      2|    case MG_PPP_LCP_CFG_REQ: {
  ------------------
  |  | 6543|      2|#define MG_PPP_LCP_CFG_REQ 1
  ------------------
  |  Branch (6712:5): [True: 2, False: 7]
  ------------------
 6713|      2|      if (len == sizeof(*lcp)) {
  ------------------
  |  Branch (6713:11): [True: 1, False: 1]
  ------------------
 6714|      1|        MG_DEBUG(("LCP config request of %d bytes, acknowledging...", len));
  ------------------
  |  | 1804|      1|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|      1|  do {                      \
  |  |  |  | 1793|      1|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  |  | 1794|      1|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6715|      1|        lcp->code = MG_PPP_LCP_CFG_ACK;
  ------------------
  |  | 6544|      1|#define MG_PPP_LCP_CFG_ACK 2
  ------------------
 6716|      1|        ppp_tx_frame(ifp, MG_PPP_PROTO_LCP, lcpp, len);
  ------------------
  |  | 6537|      1|#define MG_PPP_PROTO_LCP 0xc021
  ------------------
 6717|      1|        lcp->code = MG_PPP_LCP_CFG_REQ;
  ------------------
  |  | 6543|      1|#define MG_PPP_LCP_CFG_REQ 1
  ------------------
 6718|      1|        ppp_tx_frame(ifp, MG_PPP_PROTO_LCP, lcpp, len);
  ------------------
  |  | 6537|      1|#define MG_PPP_PROTO_LCP 0xc021
  ------------------
 6719|      1|      } else {
 6720|      1|        MG_DEBUG(("LCP config request of %d bytes, rejecting...", len));
  ------------------
  |  | 1804|      1|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|      1|  do {                      \
  |  |  |  | 1793|      1|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  |  | 1794|      1|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6721|      1|        lcp->code = MG_PPP_LCP_CFG_REJECT;
  ------------------
  |  | 6546|      1|#define MG_PPP_LCP_CFG_REJECT 4
  ------------------
 6722|      1|        ppp_tx_frame(ifp, MG_PPP_PROTO_LCP, lcpp, len);
  ------------------
  |  | 6537|      1|#define MG_PPP_PROTO_LCP 0xc021
  ------------------
 6723|      1|      }
 6724|      2|    } break;
 6725|      0|    case MG_PPP_LCP_CFG_ACK:
  ------------------
  |  | 6544|      0|#define MG_PPP_LCP_CFG_ACK 2
  ------------------
  |  Branch (6725:5): [True: 0, False: 9]
  ------------------
 6726|      0|      s_lcpup = true;
 6727|      0|      break;
 6728|      2|    case MG_PPP_LCP_CFG_TERM_REQ: {
  ------------------
  |  | 6547|      2|#define MG_PPP_LCP_CFG_TERM_REQ 5
  ------------------
  |  Branch (6728:5): [True: 2, False: 7]
  ------------------
 6729|      2|      uint8_t ack[4] = {MG_PPP_LCP_CFG_TERM_ACK, id, 0, 4};
  ------------------
  |  | 6548|      2|#define MG_PPP_LCP_CFG_TERM_ACK 6
  ------------------
 6730|      2|      MG_DEBUG(("LCP termination request, acknowledging..."));
  ------------------
  |  | 1804|      2|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|      2|  do {                      \
  |  |  |  | 1793|      2|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  |  | 1794|      2|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6731|      2|      ppp_tx_frame(ifp, MG_PPP_PROTO_LCP, ack, sizeof(ack));
  ------------------
  |  | 6537|      2|#define MG_PPP_PROTO_LCP 0xc021
  ------------------
 6732|      2|      s_lcpup = false;
 6733|      2|    } break;
 6734|      1|    case MG_PPP_LCP_ECHO_REQ:  // RFC-1661 5.8: must respond
  ------------------
  |  | 6550|      1|#define MG_PPP_LCP_ECHO_REQ 9
  ------------------
  |  Branch (6734:5): [True: 1, False: 8]
  ------------------
 6735|      1|      MG_DEBUG(("LCP echo request of %d bytes, replying...", len));
  ------------------
  |  | 1804|      1|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|      1|  do {                      \
  |  |  |  | 1793|      1|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  |  | 1794|      1|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6736|      1|      lcp->code = MG_PPP_LCP_ECHO_REPLY;
  ------------------
  |  | 6551|      1|#define MG_PPP_LCP_ECHO_REPLY 10
  ------------------
 6737|      1|      ppp_tx_frame(ifp, MG_PPP_PROTO_LCP, lcpp, len);
  ------------------
  |  | 6537|      1|#define MG_PPP_PROTO_LCP 0xc021
  ------------------
 6738|      1|      break;
 6739|      9|  }
 6740|      9|}
fuzz.c:_ZL12ppp_tx_frameP11mg_tcpip_iftPhm:
 6696|     23|                           uint8_t *data, size_t datasz) {
 6697|     23|  uint8_t *pay = ppp_tx_frame_header(ifp, proto);
 6698|     23|  memcpy(pay, data, datasz);
 6699|     23|  return ppp_tx_frame_trailer(ifp, datasz, pay + datasz);
 6700|     23|}
fuzz.c:_ZL15ppp_handle_ipcpP11mg_tcpip_ifPhm:
 6758|     29|                            size_t ipcpsz) {
 6759|     29|  uint16_t len;
 6760|     29|  uint8_t id;
 6761|     29|  struct ipcp *ipcp = (struct ipcp *) ipcpp;
 6762|     29|  uint8_t req[] = {
 6763|     29|      MG_PPP_IPCP_CFG_REQ, 0, 0, 10, MG_PPP_IPCP_OPT_IPADDR, 6, 0, 0, 0, 0};
  ------------------
  |  | 6553|     29|#define MG_PPP_IPCP_CFG_REQ 1
  ------------------
                    MG_PPP_IPCP_CFG_REQ, 0, 0, 10, MG_PPP_IPCP_OPT_IPADDR, 6, 0, 0, 0, 0};
  ------------------
  |  | 6557|     29|#define MG_PPP_IPCP_OPT_IPADDR 3
  ------------------
 6764|     29|  if (ipcpsz < sizeof(*ipcp)) return;
  ------------------
  |  Branch (6764:7): [True: 2, False: 27]
  ------------------
 6765|     27|  id = ipcp->id;
 6766|     27|  len = mg_ntohs(ipcp->len);
 6767|     27|  if (len < sizeof(*ipcp) || len > ipcpsz) return;
  ------------------
  |  Branch (6767:7): [True: 1, False: 26]
  |  Branch (6767:30): [True: 6, False: 20]
  ------------------
 6768|     20|  switch (ipcp->code) {
  ------------------
  |  Branch (6768:11): [True: 20, False: 0]
  ------------------
 6769|      8|    case MG_PPP_IPCP_CFG_REQ:
  ------------------
  |  | 6553|      8|#define MG_PPP_IPCP_CFG_REQ 1
  ------------------
  |  Branch (6769:5): [True: 8, False: 12]
  ------------------
 6770|      8|      MG_VERBOSE(("got IPCP config request, acknowledging..."));
  ------------------
  |  | 1805|      8|#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)
  |  |  ------------------
  |  |  |  | 1792|      8|  do {                      \
  |  |  |  | 1793|      8|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  |  | 1794|      8|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6771|      8|      if (len >= 10 &&
  ------------------
  |  Branch (6771:11): [True: 8, False: 0]
  ------------------
 6772|      8|          find_opt(MG_PPP_IPCP_OPT_IPADDR, 6, (const uint8_t *) (ipcp + 1),
  ------------------
  |  | 6557|      8|#define MG_PPP_IPCP_OPT_IPADDR 3
  ------------------
  |  Branch (6772:11): [True: 3, False: 5]
  ------------------
 6773|      8|                   len - sizeof(*ipcp), (uint8_t *) &ifp->gw)) {
 6774|      3|        MG_DEBUG(("IPCP cfg, GW IP: %M", mg_print_ip4, &ifp->gw));
  ------------------
  |  | 1804|      3|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|      3|  do {                      \
  |  |  |  | 1793|      3|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  |  | 1794|      3|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6775|      3|        ipcp->code = MG_PPP_IPCP_CFG_ACK;
  ------------------
  |  | 6554|      3|#define MG_PPP_IPCP_CFG_ACK 2
  ------------------
 6776|      5|      } else if (ifp->gw == 0) {
  ------------------
  |  Branch (6776:18): [True: 0, False: 5]
  ------------------
 6777|      0|        MG_ERROR(("Peer did not provide its IP address"));
  ------------------
  |  | 1802|      0|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6778|       |        // NOTE: We should NACK with an added option, probably we can just store
 6779|       |        // the incoming address and offer a statically configured ifp->gw when
 6780|       |        // theirs == 0, but it is unlikely to find such a dumb PPP server and it
 6781|       |        // will complicate our config and this protocol state machine
 6782|      0|        ipcp->code = MG_PPP_IPCP_CFG_REJECT;
  ------------------
  |  | 6556|      0|#define MG_PPP_IPCP_CFG_REJECT 4
  ------------------
 6783|      0|        ppp_tx_frame(ifp, MG_PPP_PROTO_IPCP, ipcpp, len);
  ------------------
  |  | 6538|      0|#define MG_PPP_PROTO_IPCP 0x8021
  ------------------
 6784|      0|      }
 6785|      8|      ppp_tx_frame(ifp, MG_PPP_PROTO_IPCP, ipcpp, len);
  ------------------
  |  | 6538|      8|#define MG_PPP_PROTO_IPCP 0x8021
  ------------------
 6786|      8|      req[1] = id;
 6787|      8|      memcpy(req + 6, &ifp->ip, 4);  // Request config IP address or 0.0.0.0
 6788|      8|      ppp_tx_frame(ifp, MG_PPP_PROTO_IPCP, req, sizeof(req));
  ------------------
  |  | 6538|      8|#define MG_PPP_PROTO_IPCP 0x8021
  ------------------
 6789|      8|      break;
 6790|      0|    case MG_PPP_IPCP_CFG_ACK:
  ------------------
  |  | 6554|      0|#define MG_PPP_IPCP_CFG_ACK 2
  ------------------
  |  Branch (6790:5): [True: 0, False: 20]
  ------------------
 6791|       |      // Our peer accepted our IP address
 6792|      0|      MG_VERBOSE(("got IPCP config ack"));
  ------------------
  |  | 1805|      0|#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6793|      0|      ifp->mask = 0xffffffff;  // send to gw
 6794|      0|      ifp->state = MG_TCPIP_STATE_IP;
  ------------------
  |  | 4865|      0|#define MG_TCPIP_STATE_IP 4         // IP address assigned; resolving gateway MAC
  ------------------
 6795|      0|      ifp->gw_ready = true;
 6796|      0|      break;
 6797|     11|    case MG_PPP_IPCP_CFG_NACK:
  ------------------
  |  | 6555|     11|#define MG_PPP_IPCP_CFG_NACK 3
  ------------------
  |  Branch (6797:5): [True: 11, False: 9]
  ------------------
 6798|     11|      MG_VERBOSE(("got IPCP config nack"));
  ------------------
  |  | 1805|     11|#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)
  |  |  ------------------
  |  |  |  | 1792|     11|  do {                      \
  |  |  |  | 1793|     11|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  |  | 1794|     11|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6799|       |      // NACK contains our "suggested" IP address, use it
 6800|     11|      if (len >= 10 &&
  ------------------
  |  Branch (6800:11): [True: 11, False: 0]
  ------------------
 6801|     11|          find_opt(MG_PPP_IPCP_OPT_IPADDR, 6, (const uint8_t *) (ipcp + 1),
  ------------------
  |  | 6557|     11|#define MG_PPP_IPCP_OPT_IPADDR 3
  ------------------
  |  Branch (6801:11): [True: 1, False: 10]
  ------------------
 6802|     11|                   len - sizeof(*ipcp), (uint8_t *) &ifp->ip)) {
 6803|      1|        MG_DEBUG(("IPCP cfg, IP: %M", mg_print_ip4, &ifp->ip));
  ------------------
  |  | 1804|      1|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|      1|  do {                      \
  |  |  |  | 1793|      1|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  |  | 1794|      1|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6804|      1|        ipcp->code = MG_PPP_IPCP_CFG_REQ;
  ------------------
  |  | 6553|      1|#define MG_PPP_IPCP_CFG_REQ 1
  ------------------
 6805|      1|        ppp_tx_frame(ifp, MG_PPP_PROTO_IPCP, ipcpp, len);
  ------------------
  |  | 6538|      1|#define MG_PPP_PROTO_IPCP 0x8021
  ------------------
 6806|      1|      }
 6807|     11|      break;
 6808|      1|    case MG_PPP_IPCP_CFG_REJECT:
  ------------------
  |  | 6556|      1|#define MG_PPP_IPCP_CFG_REJECT 4
  ------------------
  |  Branch (6808:5): [True: 1, False: 19]
  ------------------
 6809|      1|      MG_ERROR(("Peer rejected our IP address, need to properly set ifp->ip"));
  ------------------
  |  | 1802|      1|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|      1|  do {                      \
  |  |  |  | 1793|      1|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  |  | 1794|      1|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6810|      1|      break;
 6811|     20|  }
 6812|     20|}
fuzz.c:_ZL8find_opthhPKhmPh:
 6743|     19|                     const uint8_t *opts, size_t optslen, uint8_t *dest) {
 6744|     19|  uint8_t *p = (uint8_t *) opts;
 6745|    176|  while (optslen >= 2) {  // parse options for requested one
  ------------------
  |  Branch (6745:10): [True: 173, False: 3]
  ------------------
 6746|    173|    if (p[1] > optslen || p[1] < 2) return false;  // truncated / malformed
  ------------------
  |  Branch (6746:9): [True: 10, False: 163]
  |  Branch (6746:27): [True: 2, False: 161]
  ------------------
 6747|    161|    if (p[0] == opt && p[1] == optlen) {
  ------------------
  |  Branch (6747:9): [True: 81, False: 80]
  |  Branch (6747:24): [True: 4, False: 77]
  ------------------
 6748|      4|      memcpy(dest, p + 2, optlen - 2);
 6749|      4|      return true;
 6750|      4|    }
 6751|    157|    optslen -= p[1];
 6752|    157|    p += p[1];
 6753|    157|  }
 6754|      3|  return false;
 6755|     19|}
fuzz.c:_ZL19ppp_tx_frame_headerP11mg_tcpip_ift:
 6679|  1.26k|static uint8_t *ppp_tx_frame_header(struct mg_tcpip_if *ifp, uint16_t proto) {
 6680|  1.26k|  uint8_t *l2p = (uint8_t *) ifp->tx.buf;
 6681|  1.26k|  if (ifp->l2type == MG_TCPIP_L2_PPP)
  ------------------
  |  Branch (6681:7): [True: 1.25k, False: 3]
  ------------------
 6682|  1.25k|    return ppp_header(proto, hdlc_header(l2p));
 6683|      3|  return ppp_header(proto, pppoe_header(ifp, MG_TCPIP_L2PROTO_PPPoE_SESS, 0,
 6684|      3|                                        s_id, (struct mg_l2addr *) ifp->mac,
 6685|      3|                                        (struct mg_l2addr *) ifp->gwmac, l2p));
 6686|  1.26k|}
fuzz.c:_ZL20ppp_tx_frame_trailerP11mg_tcpip_ifmPh:
 6688|  1.26k|                                   uint8_t *cur) {
 6689|  1.26k|  return mg_l2_driver_output(ifp, ifp->l2type == MG_TCPIP_L2_PPPoE
  ------------------
  |  Branch (6689:35): [True: 3, False: 1.25k]
  ------------------
 6690|  1.26k|                                      ? mg_l2_pppoe_trailer(ifp, len, cur)
 6691|  1.26k|                                      : mg_l2_ppp_trailer(ifp, len, cur));
 6692|  1.26k|}
fuzz.c:_ZL14pppoe_tx_frameP11mg_tcpip_ifhtPhmP9mg_l2addr:
 6997|      1|                             struct mg_l2addr *dst) {
 6998|      1|  uint8_t *l2p = (uint8_t *) ifp->tx.buf;
 6999|      1|  uint8_t *p = pppoe_header(ifp, MG_TCPIP_L2PROTO_PPPoE_DISC, code, id,
 7000|      1|                            (struct mg_l2addr *) ifp->mac, dst, l2p);
 7001|      1|  memmove(p, data, datasz);
 7002|      1|  return mg_l2_driver_output(ifp, pppoe_trailer(ifp, datasz, p + datasz));
 7003|      1|}
fuzz.c:_ZL4logsPKcm:
 7405|  17.5k|static void logs(const char *buf, size_t len) {
 7406|  17.5k|  size_t i;
 7407|  99.2k|  for (i = 0; i < len; i++) logc(((unsigned char *) buf)[i]);
  ------------------
  |  Branch (7407:15): [True: 81.7k, False: 17.5k]
  ------------------
 7408|  17.5k|}
fuzz.c:_ZL4logch:
 7401|   199k|static void logc(unsigned char c) {
 7402|   199k|  s_log_func((char) c, s_log_func_param);
 7403|   199k|}
fuzz.c:_ZL6nibblej:
 7434|  79.2k|static unsigned char nibble(unsigned c) {
 7435|  79.2k|  return (unsigned char) (c < 10 ? c + '0' : c + 'W');
  ------------------
  |  Branch (7435:27): [True: 62.7k, False: 16.4k]
  ------------------
 7436|  79.2k|}
fuzz.c:_ZL20mqtt_prop_type_by_idh:
 8240|  7.84k|static int mqtt_prop_type_by_id(uint8_t prop_id) {
 8241|  7.84k|  size_t i, num_properties = sizeof(s_prop_map) / sizeof(s_prop_map[0]);
 8242|   165k|  for (i = 0; i < num_properties; ++i) {
  ------------------
  |  Branch (8242:15): [True: 165k, False: 114]
  ------------------
 8243|   165k|    if (s_prop_map[i].id == prop_id) return s_prop_map[i].type;
  ------------------
  |  Branch (8243:9): [True: 7.72k, False: 158k]
  ------------------
 8244|   165k|  }
 8245|    114|  return -1;  // Property ID not found
 8246|  7.84k|}
fuzz.c:_ZL13decode_varintPKhmPj:
 8228|    984|static size_t decode_varint(const uint8_t *buf, size_t len, uint32_t *value) {
 8229|    984|  uint32_t mul = 1, ofs;
 8230|    984|  *value = 0;
 8231|  1.25k|  for (ofs = 0; ofs < 4 && ofs < len; ofs++) {
  ------------------
  |  Branch (8231:17): [True: 1.23k, False: 18]
  |  Branch (8231:28): [True: 1.21k, False: 21]
  ------------------
 8232|  1.21k|    uint8_t enc_byte = buf[ofs];
 8233|  1.21k|    *value += (enc_byte & 0x7f) * mul;
 8234|  1.21k|    mul *= 128;
 8235|  1.21k|    if ((enc_byte & 0x80) == 0) return ofs + 1;
  ------------------
  |  Branch (8235:9): [True: 945, False: 270]
  ------------------
 8236|  1.21k|  }
 8237|     39|  return 0;
 8238|    984|}
fuzz.c:_ZL8mg_atone6mg_strP7mg_addr:
 8814|  6.10k|static bool mg_atone(struct mg_str str, struct mg_addr *addr) {
 8815|  6.10k|  if (str.len > 0) return false;
  ------------------
  |  Branch (8815:7): [True: 6.10k, False: 0]
  ------------------
 8816|      0|  memset(addr->addr.ip, 0, sizeof(addr->addr.ip));
 8817|      0|  addr->is_ip6 = false;
 8818|      0|  return true;
 8819|  6.10k|}
fuzz.c:_ZL8mg_atonl6mg_strP7mg_addr:
 8806|  6.10k|static bool mg_atonl(struct mg_str str, struct mg_addr *addr) {
 8807|  6.10k|  uint32_t localhost = mg_htonl(0x7f000001);
  ------------------
  |  | 2094|  6.10k|#define mg_htonl(x) mg_ntohl(x)
  ------------------
 8808|  6.10k|  if (mg_strcasecmp(str, mg_str("localhost")) != 0) return false;
  ------------------
  |  | 1503|  6.10k|#define mg_str(s) mg_str_s(s)
  ------------------
  |  Branch (8808:7): [True: 0, False: 6.10k]
  ------------------
 8809|  6.10k|  memcpy(addr->addr.ip, &localhost, sizeof(uint32_t));
 8810|  6.10k|  addr->is_ip6 = false;
 8811|  6.10k|  return true;
 8812|  6.10k|}
fuzz.c:_ZL13driver_outputP11mg_tcpip_ifm:
 9525|  6.10k|static size_t driver_output(struct mg_tcpip_if *ifp, size_t len) {
 9526|  6.10k|  size_t n = ifp->driver->tx(ifp->tx.buf, len, ifp);
 9527|  6.10k|  if (n == len) ifp->nsent++;
  ------------------
  |  Branch (9527:7): [True: 6.10k, False: 0]
  ------------------
 9528|  6.10k|  return n;
 9529|  6.10k|}
fuzz.c:_ZL5tx_ipP11mg_tcpip_ifPhhhjjm:
 9579|  6.10k|                        size_t plen) {
 9580|       |  // ifp->tx.buf is 8-bit aligned, keep other headers as pointers, see pkt
 9581|  6.10k|  uint8_t *l2p = (uint8_t *) ifp->tx.buf;
 9582|  6.10k|  struct ip *ip = (struct ip *) mg_l2_header(ifp, MG_TCPIP_L2PROTO_IPV4,
 9583|  6.10k|                                             ifp->mac, l2_dst, l2p);
 9584|  6.10k|  memset(ip, 0, sizeof(*ip));
 9585|  6.10k|  ip->ver = 0x45;  // Version 4, header length 5 words
 9586|  6.10k|  ip->tos = (uint8_t) (dscp << 2);
 9587|  6.10k|  ip->frag = mg_htons(0x4000);  // Don't fragment
  ------------------
  |  | 2093|  6.10k|#define mg_htons(x) mg_ntohs(x)
  ------------------
 9588|  6.10k|  ip->len = mg_htons((uint16_t) (sizeof(*ip) + plen));
  ------------------
  |  | 2093|  6.10k|#define mg_htons(x) mg_ntohs(x)
  ------------------
 9589|  6.10k|  ip->ttl = 64;
 9590|  6.10k|  ip->proto = proto;
 9591|  6.10k|  ip->src = ip_src;
 9592|  6.10k|  ip->dst = ip_dst;
 9593|  6.10k|  ip->csum = ipcsum(ip, sizeof(*ip));
 9594|  6.10k|  return ip;
 9595|  6.10k|}
fuzz.c:_ZL6ipcsumPKvm:
 9411|  6.13k|static uint16_t ipcsum(const void *buf, size_t len) {
 9412|  6.13k|  uint32_t sum = csumup(0, buf, len);
 9413|  6.13k|  return csumfin(sum);
 9414|  6.13k|}
fuzz.c:_ZL6csumupjPKvm:
 9399|  18.3k|static uint32_t csumup(uint32_t sum, const void *buf, size_t len) {
 9400|  18.3k|  size_t i;
 9401|  18.3k|  const uint8_t *p = (const uint8_t *) buf;
 9402|   360k|  for (i = 0; i < len; i++) sum += i & 1 ? p[i] : ((uint32_t) p[i]) << 8;
  ------------------
  |  Branch (9402:15): [True: 342k, False: 18.3k]
  |  Branch (9402:36): [True: 171k, False: 171k]
  ------------------
 9403|  18.3k|  return sum;
 9404|  18.3k|}
fuzz.c:_ZL7csumfinj:
 9406|  12.2k|static uint16_t csumfin(uint32_t sum) {
 9407|  24.4k|  while (sum >> 16) sum = (sum & 0xffff) + (sum >> 16);
  ------------------
  |  Branch (9407:10): [True: 12.2k, False: 12.2k]
  ------------------
 9408|  12.2k|  return mg_htons((uint16_t) ((uint16_t) ~sum & 0xffff));
  ------------------
  |  | 2093|  12.2k|#define mg_htons(x) mg_ntohs(x)
  ------------------
 9409|  12.2k|}
fuzz.c:_ZL5pcsumPvS_m:
 9425|  6.10k|static uint16_t pcsum(void *d, void *p, size_t plen) {
 9426|  6.10k|  uint32_t sum;
 9427|  6.10k|  struct ip *ip = (struct ip *) d;
 9428|       |#if defined(__DCC__)
 9429|       |  volatile /* Makes PPC & Diab4.3 happy */
 9430|       |#endif
 9431|  6.10k|      struct pseudoip pip;
 9432|  6.10k|  pip.src = ip->src;
 9433|  6.10k|  pip.dst = ip->dst;
 9434|  6.10k|  pip.zero = 0;
 9435|  6.10k|  pip.proto = ip->proto;
 9436|  6.10k|  pip.len = mg_htons((uint16_t) plen);
  ------------------
  |  | 2093|  6.10k|#define mg_htons(x) mg_ntohs(x)
  ------------------
 9437|  6.10k|  sum = csumup(0, &pip, sizeof(pip));  // even length
 9438|  6.10k|  sum = csumup(sum, p, plen);          // possibly odd length: last
 9439|  6.10k|  return csumfin(sum);
 9440|  6.10k|}
fuzz.c:_ZL6tx_tcpP11mg_tcpip_ifPhP7mg_addrS3_hhjjtPKvm:
10406|  6.10k|                     uint16_t win, const void *buf, size_t len) {
10407|  6.10k|  uint8_t *l3p;
10408|  6.10k|  struct ip *ip = NULL;
10409|  6.10k|  struct tcp *tcp;
10410|  6.10k|  uint16_t opts[4 / 2];
10411|  6.10k|  size_t hlen = sizeof(*tcp);
10412|       |#if MG_ENABLE_IPV6
10413|       |  struct ip6 *ip6 = NULL;
10414|       |#endif
10415|       |
10416|       |  // Handle any options first, here, to determine header size
10417|  6.10k|  if (flags & TH_SYN) {  // Send MSS
  ------------------
  |  | 9277|  6.10k|#define TH_SYN 0x02
  ------------------
  |  Branch (10417:7): [True: 6.10k, False: 0]
  ------------------
10418|  6.10k|    uint16_t mss;
10419|       |#if MG_ENABLE_IPV6  // RFC-9293 3.7.1; RFC-6691 2
10420|       |    mss = (uint16_t) (ifp->mtu - 60);
10421|       |#else
10422|  6.10k|    mss = (uint16_t) (ifp->mtu - 40);
10423|  6.10k|#endif
10424|  6.10k|    opts[0] = mg_htons(0x0204);  // RFC-9293 3.2
  ------------------
  |  | 2093|  6.10k|#define mg_htons(x) mg_ntohs(x)
  ------------------
10425|  6.10k|    opts[1] = mg_htons(mss);
  ------------------
  |  | 2093|  6.10k|#define mg_htons(x) mg_ntohs(x)
  ------------------
10426|  6.10k|    hlen += sizeof(opts);  // always whole number of 32-bit words
10427|  6.10k|  }
10428|       |
10429|       |#if MG_ENABLE_IPV6
10430|       |  if (ip_dst->is_ip6) {
10431|       |    ip6 = tx_ip6(ifp, l2_dst, 6, dscp, ip_src->addr.ip6, ip_dst->addr.ip6,
10432|       |                 hlen + len);
10433|       |    tcp = (struct tcp *) (ip6 + 1);
10434|       |    l3p = (uint8_t *) ip6;
10435|       |  } else
10436|       |#endif
10437|  6.10k|  {
10438|  6.10k|    ip = tx_ip(ifp, l2_dst, 6, dscp, ip_src->addr.ip4, ip_dst->addr.ip4,
10439|  6.10k|               hlen + len);
10440|  6.10k|    tcp = (struct tcp *) (ip + 1);
10441|  6.10k|    l3p = (uint8_t *) ip;
10442|  6.10k|  }
10443|  6.10k|  memset(tcp, 0, sizeof(*tcp));
10444|  6.10k|  memmove(tcp + 1, opts, hlen - sizeof(*tcp));  // copy opts if any
10445|  6.10k|  if (buf != NULL && len) memmove((uint8_t *) tcp + hlen, buf, len);
  ------------------
  |  Branch (10445:7): [True: 0, False: 6.10k]
  |  Branch (10445:22): [True: 0, False: 0]
  ------------------
10446|  6.10k|  tcp->sport = ip_src->port;
10447|  6.10k|  tcp->dport = ip_dst->port;
10448|  6.10k|  tcp->seq = seq;
10449|  6.10k|  tcp->ack = ack;
10450|  6.10k|  tcp->flags = flags;
10451|  6.10k|  tcp->win = mg_htons(win);
  ------------------
  |  | 2093|  6.10k|#define mg_htons(x) mg_ntohs(x)
  ------------------
10452|  6.10k|  tcp->off = (uint8_t) (hlen / 4 << 4);
10453|       |#if MG_ENABLE_IPV6
10454|       |  if (ip_dst->is_ip6) {
10455|       |    tcp->csum = p6csum(ip6, tcp, 6, hlen + len);
10456|       |  } else
10457|       |#endif
10458|  6.10k|  {
10459|  6.10k|    tcp->csum = pcsum(ip, tcp, hlen + len);
10460|  6.10k|  }
10461|  6.10k|  MG_VERBOSE(("TCP %M -> %M fl %x len %u", mg_print_ip_port, ip_src,
  ------------------
  |  | 1805|  6.10k|#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)
  |  |  ------------------
  |  |  |  | 1792|  6.10k|  do {                      \
  |  |  |  | 1793|  6.10k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 6.10k]
  |  |  |  |  ------------------
  |  |  |  | 1794|  6.10k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 6.10k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
10462|  6.10k|              mg_print_ip_port, ip_dst, tcp->flags, len));
10463|  6.10k|  return driver_output(
10464|  6.10k|      ifp, mg_l2_trailer(ifp, PDIFF(l3p, (uint8_t *) tcp + hlen + len),
  ------------------
  |  | 9139|  6.10k|#define PDIFF(a, b) ((size_t) (((char *) (b)) - ((char *) (a))))
  ------------------
10465|  6.10k|                         (uint8_t *) tcp + hlen + len));
10466|  6.10k|}
fuzz.c:_ZL8settmoutP13mg_connectionh:
 9511|  11.5k|static void settmout(struct mg_connection *c, uint8_t type) {
 9512|  11.5k|  struct mg_tcpip_if *ifp = c->mgr->ifp;
 9513|  11.5k|  struct connstate *s = (struct connstate *) (c + 1);
 9514|  11.5k|  unsigned n = type == MIP_TTYPE_ACK   ? MG_TCPIP_ACK_MS
  ------------------
  |  | 9186|  11.5k|#define MIP_TTYPE_ACK 1        // Peer sent us data, we have to ack it soon
  ------------------
                unsigned n = type == MIP_TTYPE_ACK   ? MG_TCPIP_ACK_MS
  ------------------
  |  | 9146|      0|#define MG_TCPIP_ACK_MS 150    // Timeout for ACKing
  ------------------
  |  Branch (9514:16): [True: 0, False: 11.5k]
  ------------------
 9515|  11.5k|               : type == MIP_TTYPE_ARP ? MG_TCPIP_ARP_MS
  ------------------
  |  | 9187|  11.5k|#define MIP_TTYPE_ARP 2        // ARP resolve sent, waiting for response
  ------------------
                             : type == MIP_TTYPE_ARP ? MG_TCPIP_ARP_MS
  ------------------
  |  | 9150|      0|#define MG_TCPIP_ARP_MS 100    // Timeout for ARP response
  ------------------
  |  Branch (9515:18): [True: 0, False: 11.5k]
  ------------------
 9516|  11.5k|               : type == MIP_TTYPE_SYN ? MG_TCPIP_SYN_MS
  ------------------
  |  | 9188|  11.5k|#define MIP_TTYPE_SYN 3        // SYN sent, waiting for response
  ------------------
                             : type == MIP_TTYPE_SYN ? MG_TCPIP_SYN_MS
  ------------------
  |  | 9153|  6.10k|#define MG_TCPIP_SYN_MS 15000  // Timeout for connection establishment
  ------------------
  |  Branch (9516:18): [True: 6.10k, False: 5.40k]
  ------------------
 9517|  11.5k|               : type == MIP_TTYPE_FIN ? MG_TCPIP_FIN_MS
  ------------------
  |  | 9189|  5.40k|#define MIP_TTYPE_FIN 4  // FIN sent, waiting until terminating the connection
  ------------------
                             : type == MIP_TTYPE_FIN ? MG_TCPIP_FIN_MS
  ------------------
  |  | 9154|      0|#define MG_TCPIP_FIN_MS 1000   // Timeout for closing connection
  ------------------
  |  Branch (9517:18): [True: 0, False: 5.40k]
  ------------------
 9518|  5.40k|                                       : MG_TCPIP_KEEPALIVE_MS;
  ------------------
  |  | 9142|  16.9k|#define MG_TCPIP_KEEPALIVE_MS 45000  // TCP keep-alive period, ms
  ------------------
 9519|  11.5k|  if (s->ttype == MIP_TTYPE_FIN) return;  // skip if 3-way closing
  ------------------
  |  | 9189|  11.5k|#define MIP_TTYPE_FIN 4  // FIN sent, waiting until terminating the connection
  ------------------
  |  Branch (9519:7): [True: 0, False: 11.5k]
  ------------------
 9520|  11.5k|  s->timer = ifp->now + n;
 9521|  11.5k|  s->ttype = type;
 9522|  11.5k|  MG_VERBOSE(("%lu %d -> %llx", c->id, type, s->timer));
  ------------------
  |  | 1805|  11.5k|#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)
  |  |  ------------------
  |  |  |  | 1792|  11.5k|  do {                      \
  |  |  |  | 1793|  11.5k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 11.5k]
  |  |  |  |  ------------------
  |  |  |  | 1794|  11.5k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 11.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 9523|  11.5k|}
fuzz.c:_ZL10close_connP13mg_connection:
11456|  6.10k|static void close_conn(struct mg_connection *c) {
11457|  6.10k|  struct connstate *s = (struct connstate *) (c + 1);
11458|  6.10k|  mg_iobuf_free(&s->txq);
11459|  6.10k|  mg_close_conn(c);
11460|  6.10k|}
fuzz.c:_ZL15l2addr_resolvedP13mg_connection:
11476|  6.10k|static void l2addr_resolved(struct mg_connection *c) {
11477|  6.10k|  if (c->is_udp) {
  ------------------
  |  Branch (11477:7): [True: 0, False: 6.10k]
  ------------------
11478|      0|    c->is_connecting = 0;
11479|      0|    mg_call(c, MG_EV_CONNECT, NULL);
11480|  6.10k|  } else {
11481|  6.10k|    send_syn(c);
11482|  6.10k|    settmout(c, MIP_TTYPE_SYN);
  ------------------
  |  | 9188|  6.10k|#define MIP_TTYPE_SYN 3        // SYN sent, waiting for response
  ------------------
11483|  6.10k|  }
11484|  6.10k|}
fuzz.c:_ZL8send_synP13mg_connection:
11469|  6.10k|static void send_syn(struct mg_connection *c) {
11470|  6.10k|  struct connstate *s = (struct connstate *) (c + 1);
11471|  6.10k|  uint32_t isn = mg_htonl((uint32_t) mg_ntohs(c->loc.port));
  ------------------
  |  | 2094|  6.10k|#define mg_htonl(x) mg_ntohl(x)
  ------------------
11472|  6.10k|  tx_tcp(c->mgr->ifp, s->mac, &c->loc, &c->rem, c->dscp, TH_SYN, isn, 0,
  ------------------
  |  | 9277|  6.10k|#define TH_SYN 0x02
  ------------------
11473|  6.10k|         MG_TCPIP_WIN, NULL, 0);
  ------------------
  |  | 9161|  6.10k|#define MG_TCPIP_WIN 6000  // TCP window size
  ------------------
11474|  6.10k|}
fuzz.c:_ZL13mg_tcpip_pollP11mg_tcpip_ifm:
11284|  6.10k|static void mg_tcpip_poll(struct mg_tcpip_if *ifp, uint64_t now) {
11285|  6.10k|  struct mg_connection *c;
11286|  6.10k|  bool expired_1000ms = mg_timer_expired(&ifp->timer_1000ms, 1000, now);
11287|  6.10k|  ifp->now = now;
11288|       |
11289|  6.10k|  if (expired_1000ms) {
  ------------------
  |  Branch (11289:7): [True: 6.10k, False: 0]
  ------------------
11290|       |#if MG_ENABLE_TCPIP_PRINT_DEBUG_STATS
11291|       |    const char *names[] = {"down", "lnk up", "lnk rdy", "req", "ip", "ready"};
11292|       |    size_t max = sizeof(names) / sizeof(char *);
11293|       |    unsigned int state = ifp->state >= max ? max - 1 : ifp->state;
11294|       |    MG_INFO(("Status: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u", names[state],
11295|       |             mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent, ifp->ndrop,
11296|       |             ifp->nerr));
11297|       |#if MG_ENABLE_IPV6
11298|       |    state = ifp->state6 >= max ? max - 1 : ifp->state6;
11299|       |    if (state > MG_TCPIP_STATE_UP)
11300|       |      MG_INFO(("Status: %s, IPv6: %M", names[state], mg_print_ip6, &ifp->ip6));
11301|       |#endif
11302|       |#endif
11303|  6.10k|    backlog_poll(ifp->mgr);
11304|  6.10k|  }
11305|       |  // Handle gw ARP request timeout, order is important
11306|  6.10k|  if (expired_1000ms && ifp->state == MG_TCPIP_STATE_IP) {
  ------------------
  |  | 4865|  6.10k|#define MG_TCPIP_STATE_IP 4         // IP address assigned; resolving gateway MAC
  ------------------
  |  Branch (11306:7): [True: 6.10k, False: 0]
  |  Branch (11306:25): [True: 0, False: 6.10k]
  ------------------
11307|      0|    ifp->state = MG_TCPIP_STATE_READY;  // gw MAC not resolved, we'll retry
  ------------------
  |  | 4866|      0|#define MG_TCPIP_STATE_READY 5      // Fully operational; gateway MAC resolved
  ------------------
11308|      0|    onstatechange(ifp);
11309|      0|  }
11310|  6.10k|  if (expired_1000ms && ifp->state == MG_TCPIP_STATE_READY && !ifp->gw_ready &&
  ------------------
  |  | 4866|  12.2k|#define MG_TCPIP_STATE_READY 5      // Fully operational; gateway MAC resolved
  ------------------
  |  Branch (11310:7): [True: 6.10k, False: 0]
  |  Branch (11310:25): [True: 6.10k, False: 0]
  |  Branch (11310:63): [True: 0, False: 6.10k]
  ------------------
11311|      0|      ifp->gw != 0)
  ------------------
  |  Branch (11311:7): [True: 0, False: 0]
  ------------------
11312|      0|    mg_tcpip_arp_request(ifp, ifp->gw, NULL);  // retry GW ARP request
11313|       |#if MG_ENABLE_IPV6
11314|       |  // Handle gw NS/NA req/resp timeout, order is important
11315|       |  if (expired_1000ms && ifp->state6 == MG_TCPIP_STATE_IP) {
11316|       |    ifp->state6 = MG_TCPIP_STATE_READY;  // gw6 MAC not resolved, we'll retry
11317|       |    onstate6change(ifp);
11318|       |  }
11319|       |  if (expired_1000ms && ifp->state6 == MG_TCPIP_STATE_READY && !ifp->gw6_ready &&
11320|       |      (ifp->gw6[0] != 0 || ifp->gw6[1] != 0))
11321|       |    tx_ndp_ns(ifp, ifp->gw6, NULL);  // retry GW hwaddr resolution
11322|       |#endif
11323|       |
11324|  6.10k|  {  // poll driver and let L2 do its work, if any
11325|       |    // Handle physical interface up/down status
11326|  6.10k|    bool drv_up, l2_up;
11327|  6.10k|    drv_up = ifp->driver->poll ? ifp->driver->poll(ifp, expired_1000ms) : true;
  ------------------
  |  Branch (11327:14): [True: 6.10k, False: 0]
  ------------------
11328|  6.10k|    l2_up = mg_l2_poll(ifp, expired_1000ms);  // Handle L2 up/down link status;
11329|  6.10k|    if (expired_1000ms) {                     // ifp->state rules over state6
  ------------------
  |  Branch (11329:9): [True: 6.10k, False: 0]
  ------------------
11330|  6.10k|      mg_ip_link(ifp, drv_up, l2_up);         // Handle IPv4
11331|  6.10k|      mg_ip6_link(ifp, drv_up, l2_up);        // Handle IPv6
11332|  6.10k|      if (ifp->state < MG_TCPIP_STATE_UP) MG_ERROR(("Network is down"));
  ------------------
  |  | 4863|  6.10k|#define MG_TCPIP_STATE_UP 2         // L2 is ready (e.g. PPP negotiated)
  ------------------
                    if (ifp->state < MG_TCPIP_STATE_UP) MG_ERROR(("Network is down"));
  ------------------
  |  | 1802|    692|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|    692|  do {                      \
  |  |  |  | 1793|    692|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 692]
  |  |  |  |  ------------------
  |  |  |  | 1794|    692|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 692]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (11332:11): [True: 692, False: 5.40k]
  ------------------
11333|  6.10k|      mg_tcpip_call(ifp, MG_TCPIP_EV_TIMER_1S, NULL);
11334|  6.10k|    }
11335|  6.10k|  }
11336|       |
11337|  6.10k|  mg_ip_poll(ifp, expired_1000ms);   // Handle IPv4
11338|  6.10k|  mg_ip6_poll(ifp, expired_1000ms);  // Handle IPv6
11339|       |
11340|       |  // Read data from the network (mg_tcpip_rx() will discard for us)
11341|  6.10k|  if (ifp->driver->rx != NULL) {  // Simple polling driver, returns one frame
  ------------------
  |  Branch (11341:7): [True: 6.10k, False: 0]
  ------------------
11342|  6.10k|    size_t len =
11343|  6.10k|        ifp->driver->rx(ifp->recv_queue.buf, ifp->recv_queue.size, ifp);
11344|  6.10k|    if (len > 0) {
  ------------------
  |  Branch (11344:9): [True: 0, False: 6.10k]
  ------------------
11345|      0|      ifp->nrecv++;
11346|      0|      mg_tcpip_rx(ifp, ifp->recv_queue.buf, len);
11347|      0|    }
11348|  6.10k|  } else {  // Complex poll / Interrupt-based driver. Queues recvd frames
11349|      0|    char *buf;
11350|      0|    size_t len, cnt = 7;  // Max 7 packets to fetch
11351|      0|    while (cnt-- > 0 && (len = mg_queue_next(&ifp->recv_queue, &buf)) > 0) {
  ------------------
  |  Branch (11351:12): [True: 0, False: 0]
  |  Branch (11351:25): [True: 0, False: 0]
  ------------------
11352|      0|      mg_tcpip_rx(ifp, buf, len);
11353|      0|      mg_queue_del(&ifp->recv_queue, len);
11354|      0|    }
11355|      0|  }
11356|  6.10k|  if (ifp->state < MG_TCPIP_STATE_UP) return;  // need to let L2 do its job
  ------------------
  |  | 4863|  6.10k|#define MG_TCPIP_STATE_UP 2         // L2 is ready (e.g. PPP negotiated)
  ------------------
  |  Branch (11356:7): [True: 692, False: 5.40k]
  ------------------
11357|       |
11358|       |  // Process timeouts
11359|  10.8k|  for (c = ifp->mgr->conns; c != NULL; c = c->next) {
  ------------------
  |  Branch (11359:29): [True: 5.40k, False: 5.40k]
  ------------------
11360|  5.40k|    struct connstate *s = (struct connstate *) (c + 1);
11361|  5.40k|    if ((c->is_udp && !c->is_arplooking) || c->is_listening || c->is_resolving)
  ------------------
  |  Branch (11361:10): [True: 0, False: 5.40k]
  |  Branch (11361:23): [True: 0, False: 0]
  |  Branch (11361:45): [True: 0, False: 5.40k]
  |  Branch (11361:64): [True: 0, False: 5.40k]
  ------------------
11362|      0|      continue;
11363|  5.40k|    if (!c->is_full && s->is_full) {
  ------------------
  |  Branch (11363:9): [True: 5.40k, False: 0]
  |  Branch (11363:24): [True: 0, False: 5.40k]
  ------------------
11364|       |      // Application resumed the connection: advertise the restored window
11365|      0|      s->is_full = false;
11366|      0|      tx_tcp(ifp, s->mac, &c->loc, &c->rem, c->dscp, TH_ACK, mg_htonl(s->seq),
  ------------------
  |  | 9280|      0|#define TH_ACK 0x10
  ------------------
                    tx_tcp(ifp, s->mac, &c->loc, &c->rem, c->dscp, TH_ACK, mg_htonl(s->seq),
  ------------------
  |  | 2094|      0|#define mg_htonl(x) mg_ntohl(x)
  ------------------
11367|      0|             mg_htonl(s->ack), MG_TCPIP_WIN, NULL, 0);
  ------------------
  |  | 2094|      0|#define mg_htonl(x) mg_ntohl(x)
  ------------------
                           mg_htonl(s->ack), MG_TCPIP_WIN, NULL, 0);
  ------------------
  |  | 9161|      0|#define MG_TCPIP_WIN 6000  // TCP window size
  ------------------
11368|      0|    }
11369|  5.40k|    if (s->retransmit && s->txq.len > 0 && ifp->now > s->txq_timer) {
  ------------------
  |  Branch (11369:9): [True: 0, False: 5.40k]
  |  Branch (11369:26): [True: 0, False: 0]
  |  Branch (11369:44): [True: 0, False: 0]
  ------------------
11370|      0|      if (s->txq_retries < 255) s->txq_retries++;
  ------------------
  |  Branch (11370:11): [True: 0, False: 0]
  ------------------
11371|       |      // R1 reports a delivery problem; it does not close (RFC-9293, 3.8.3).
11372|      0|      if (s->txq_retries == MG_TCPIP_RTX_R1)
  ------------------
  |  | 9157|      0|#define MG_TCPIP_RTX_R1 3  // Delivery-problem threshold (RFC-9293, 3.8.3)
  ------------------
  |  Branch (11372:11): [True: 0, False: 0]
  ------------------
11373|      0|        MG_ERROR(("%lu retransmit", c->id));
  ------------------
  |  | 1802|      0|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
11374|      0|      retransmit(c);
11375|      0|    }
11376|  5.40k|    if (ifp->now > s->timer) {
  ------------------
  |  Branch (11376:9): [True: 5.40k, False: 0]
  ------------------
11377|  5.40k|      if (s->ttype == MIP_TTYPE_ARP) {
  ------------------
  |  | 9187|  5.40k|#define MIP_TTYPE_ARP 2        // ARP resolve sent, waiting for response
  ------------------
  |  Branch (11377:11): [True: 0, False: 5.40k]
  ------------------
11378|      0|        proto_error(c, false, "ARP timeout");
11379|  5.40k|      } else if (c->is_udp) {
  ------------------
  |  Branch (11379:18): [True: 0, False: 5.40k]
  ------------------
11380|      0|        continue;
11381|  5.40k|      } else if (s->ttype == MIP_TTYPE_ACK && s->acked != s->ack) {
  ------------------
  |  | 9186|  10.8k|#define MIP_TTYPE_ACK 1        // Peer sent us data, we have to ack it soon
  ------------------
  |  Branch (11381:18): [True: 0, False: 5.40k]
  |  Branch (11381:47): [True: 0, False: 0]
  ------------------
11382|      0|        MG_VERBOSE(("%lu ack %x %x", c->id, s->seq, s->ack));
  ------------------
  |  | 1805|      0|#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
11383|      0|        tx_tcp(ifp, s->mac, &c->loc, &c->rem, c->dscp, TH_ACK, mg_htonl(s->seq),
  ------------------
  |  | 9280|      0|#define TH_ACK 0x10
  ------------------
                      tx_tcp(ifp, s->mac, &c->loc, &c->rem, c->dscp, TH_ACK, mg_htonl(s->seq),
  ------------------
  |  | 2094|      0|#define mg_htonl(x) mg_ntohl(x)
  ------------------
11384|      0|               mg_htonl(s->ack), s->is_full ? 0 : MG_TCPIP_WIN, NULL, 0);
  ------------------
  |  | 2094|      0|#define mg_htonl(x) mg_ntohl(x)
  ------------------
                             mg_htonl(s->ack), s->is_full ? 0 : MG_TCPIP_WIN, NULL, 0);
  ------------------
  |  | 9161|      0|#define MG_TCPIP_WIN 6000  // TCP window size
  ------------------
  |  Branch (11384:34): [True: 0, False: 0]
  ------------------
11385|      0|        s->acked = s->ack;
11386|  5.40k|      } else if (s->ttype == MIP_TTYPE_SYN) {
  ------------------
  |  | 9188|  5.40k|#define MIP_TTYPE_SYN 3        // SYN sent, waiting for response
  ------------------
  |  Branch (11386:18): [True: 5.40k, False: 0]
  ------------------
11387|  5.40k|        proto_error(c, false, "Connection timeout");
11388|  5.40k|      } else if (s->ttype == MIP_TTYPE_FIN) {
  ------------------
  |  | 9189|      0|#define MIP_TTYPE_FIN 4  // FIN sent, waiting until terminating the connection
  ------------------
  |  Branch (11388:18): [True: 0, False: 0]
  ------------------
11389|      0|        s->is_closing = 1;
11390|      0|        continue;
11391|      0|      } else {
11392|      0|        if (s->tmiss++ > 2) {
  ------------------
  |  Branch (11392:13): [True: 0, False: 0]
  ------------------
11393|      0|          proto_error(c, false, "keepalive");
11394|      0|        } else {
11395|      0|          MG_VERBOSE(("%lu keepalive", c->id));
  ------------------
  |  | 1805|      0|#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
11396|      0|          tx_tcp(ifp, s->mac, &c->loc, &c->rem, c->dscp, TH_ACK,
  ------------------
  |  | 9280|      0|#define TH_ACK 0x10
  ------------------
11397|      0|                 mg_htonl(s->seq - 1), mg_htonl(s->ack),
  ------------------
  |  | 2094|      0|#define mg_htonl(x) mg_ntohl(x)
  ------------------
                               mg_htonl(s->seq - 1), mg_htonl(s->ack),
  ------------------
  |  | 2094|      0|#define mg_htonl(x) mg_ntohl(x)
  ------------------
11398|      0|                 s->is_full ? 0 : MG_TCPIP_WIN, NULL, 0);
  ------------------
  |  | 9161|      0|#define MG_TCPIP_WIN 6000  // TCP window size
  ------------------
  |  Branch (11398:18): [True: 0, False: 0]
  ------------------
11399|      0|        }
11400|      0|      }
11401|       |
11402|  5.40k|      settmout(c, MIP_TTYPE_KEEPALIVE);
  ------------------
  |  | 9185|  5.40k|#define MIP_TTYPE_KEEPALIVE 0  // Connection is idle for long, send keepalive
  ------------------
11403|  5.40k|    }
11404|  5.40k|  }
11405|  5.40k|}
fuzz.c:_ZL12backlog_pollP6mg_mgr:
10877|  6.10k|static void backlog_poll(struct mg_mgr *mgr) {
10878|  6.10k|  struct mg_connection *c = NULL;
10879|  12.2k|  for (c = mgr->conns; c != NULL; c = c->next) {
  ------------------
  |  Branch (10879:24): [True: 6.10k, False: 6.10k]
  ------------------
10880|  6.10k|    if (!c->is_udp && c->is_listening) backlog_maintain(c);
  ------------------
  |  Branch (10880:9): [True: 6.10k, False: 0]
  |  Branch (10880:23): [True: 0, False: 6.10k]
  ------------------
10881|  6.10k|  }
10882|  6.10k|}
fuzz.c:_ZL13onstatechangeP11mg_tcpip_if:
 9546|    692|static void onstatechange(struct mg_tcpip_if *ifp) {
 9547|    692|  if (ifp->state == MG_TCPIP_STATE_IP &&
  ------------------
  |  | 4865|  1.38k|#define MG_TCPIP_STATE_IP 4         // IP address assigned; resolving gateway MAC
  ------------------
  |  Branch (9547:7): [True: 0, False: 692]
  ------------------
 9548|      0|      (ifp->l2type == MG_TCPIP_L2_PPP || ifp->l2type == MG_TCPIP_L2_PPPoE))
  ------------------
  |  Branch (9548:8): [True: 0, False: 0]
  |  Branch (9548:42): [True: 0, False: 0]
  ------------------
 9549|      0|    ifp->state = MG_TCPIP_STATE_READY;
  ------------------
  |  | 4866|      0|#define MG_TCPIP_STATE_READY 5      // Fully operational; gateway MAC resolved
  ------------------
 9550|    692|  if (ifp->state == MG_TCPIP_STATE_READY) {
  ------------------
  |  | 4866|    692|#define MG_TCPIP_STATE_READY 5      // Fully operational; gateway MAC resolved
  ------------------
  |  Branch (9550:7): [True: 0, False: 692]
  ------------------
 9551|      0|    MG_INFO(("READY, IP: %M", mg_print_ip4, &ifp->ip));
  ------------------
  |  | 1803|      0|#define MG_INFO(args) MG_LOG(MG_LL_INFO, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 9552|      0|    MG_INFO(("       GW: %M", mg_print_ip4, &ifp->gw));
  ------------------
  |  | 1803|      0|#define MG_INFO(args) MG_LOG(MG_LL_INFO, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 9553|      0|    if (ifp->l2type == MG_TCPIP_L2_ETH ||
  ------------------
  |  Branch (9553:9): [True: 0, False: 0]
  ------------------
 9554|      0|        ifp->l2type == MG_TCPIP_L2_PPPoE)  // TODO(): print other l2
  ------------------
  |  Branch (9554:9): [True: 0, False: 0]
  ------------------
 9555|      0|      MG_INFO(("      MAC: %M", mg_print_mac, ifp->mac));
  ------------------
  |  | 1803|      0|#define MG_INFO(args) MG_LOG(MG_LL_INFO, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 9556|      0|    if (ifp->l2type == MG_TCPIP_L2_ETH)
  ------------------
  |  Branch (9556:9): [True: 0, False: 0]
  ------------------
 9557|      0|      mg_tcpip_arp_request(ifp, ifp->ip, ifp->mac);  // gratuitous ARP annc
 9558|      0|    if (ifp->is_ip_changed) {
  ------------------
  |  Branch (9558:9): [True: 0, False: 0]
  ------------------
 9559|      0|      struct mg_connection *c;
 9560|      0|      for (c = ifp->mgr->conns; c != NULL; c = c->next) {
  ------------------
  |  Branch (9560:33): [True: 0, False: 0]
  ------------------
 9561|      0|        if (!c->is_listening && !c->is_udp && !c->loc.is_ip6) c->is_closing = 1;
  ------------------
  |  Branch (9561:13): [True: 0, False: 0]
  |  Branch (9561:33): [True: 0, False: 0]
  |  Branch (9561:47): [True: 0, False: 0]
  ------------------
 9562|      0|      }
 9563|      0|      ifp->is_ip_changed = false;
 9564|      0|    }
 9565|    692|  } else if (ifp->state == MG_TCPIP_STATE_IP) {
  ------------------
  |  | 4865|    692|#define MG_TCPIP_STATE_IP 4         // IP address assigned; resolving gateway MAC
  ------------------
  |  Branch (9565:14): [True: 0, False: 692]
  ------------------
 9566|      0|    if (ifp->l2type == MG_TCPIP_L2_ETH) {
  ------------------
  |  Branch (9566:9): [True: 0, False: 0]
  ------------------
 9567|      0|      ifp->gw_ready = false;  // remove any prior state
 9568|      0|      if (ifp->gw != 0)  // send an unsolicited GW ARP request
  ------------------
  |  Branch (9568:11): [True: 0, False: 0]
  ------------------
 9569|      0|        mg_tcpip_arp_request(ifp, ifp->gw, NULL);
 9570|      0|    }
 9571|    692|  } else if (ifp->state == MG_TCPIP_STATE_UP) {
  ------------------
  |  | 4863|    692|#define MG_TCPIP_STATE_UP 2         // L2 is ready (e.g. PPP negotiated)
  ------------------
  |  Branch (9571:14): [True: 0, False: 692]
  ------------------
 9572|      0|    srand((unsigned int) mg_millis());
 9573|      0|  }
 9574|    692|  mg_tcpip_call(ifp, MG_TCPIP_EV_STATE_CHANGE, &ifp->state);
 9575|    692|}
fuzz.c:_ZL10mg_ip_linkP11mg_tcpip_ifbb:
11225|  6.10k|static void mg_ip_link(struct mg_tcpip_if *ifp, bool drv_up, bool l2_up) {
11226|  6.10k|  bool cur_drv = (ifp->state != MG_TCPIP_STATE_DOWN);
  ------------------
  |  | 4861|  6.10k|#define MG_TCPIP_STATE_DOWN 0       // Physical link is down
  ------------------
11227|  6.10k|  bool cur_l2 = (ifp->state >= MG_TCPIP_STATE_UP);
  ------------------
  |  | 4863|  6.10k|#define MG_TCPIP_STATE_UP 2         // L2 is ready (e.g. PPP negotiated)
  ------------------
11228|  6.10k|  if (!l2_up && ifp->enable_dhcp_client) ifp->ip = 0;
  ------------------
  |  Branch (11228:7): [True: 692, False: 5.40k]
  |  Branch (11228:17): [True: 0, False: 692]
  ------------------
11229|  6.10k|  if (drv_up != cur_drv || l2_up != cur_l2) {  // link/L2 state has changed
  ------------------
  |  Branch (11229:7): [True: 0, False: 6.10k]
  |  Branch (11229:28): [True: 692, False: 5.40k]
  ------------------
11230|    692|    ifp->state = !drv_up  ? MG_TCPIP_STATE_DOWN
  ------------------
  |  | 4861|      0|#define MG_TCPIP_STATE_DOWN 0       // Physical link is down
  ------------------
  |  Branch (11230:18): [True: 0, False: 692]
  ------------------
11231|    692|                 : !l2_up ? MG_TCPIP_STATE_LINK_UP
  ------------------
  |  | 4862|    692|#define MG_TCPIP_STATE_LINK_UP 1    // Driver reports physical link is up
  ------------------
  |  Branch (11231:20): [True: 692, False: 0]
  ------------------
11232|    692|                 : ifp->enable_dhcp_client || ifp->ip == 0 ? MG_TCPIP_STATE_UP
  ------------------
  |  | 4863|      0|#define MG_TCPIP_STATE_UP 2         // L2 is ready (e.g. PPP negotiated)
  ------------------
  |  Branch (11232:20): [True: 0, False: 0]
  |  Branch (11232:47): [True: 0, False: 0]
  ------------------
11233|      0|                                                           : MG_TCPIP_STATE_IP;
  ------------------
  |  | 4865|    692|#define MG_TCPIP_STATE_IP 4         // IP address assigned; resolving gateway MAC
  ------------------
11234|    692|    onstatechange(ifp);
11235|  5.40k|  } else if (!ifp->enable_dhcp_client && ifp->state == MG_TCPIP_STATE_UP &&
  ------------------
  |  | 4863|  10.8k|#define MG_TCPIP_STATE_UP 2         // L2 is ready (e.g. PPP negotiated)
  ------------------
  |  Branch (11235:14): [True: 5.40k, False: 0]
  |  Branch (11235:42): [True: 0, False: 5.40k]
  ------------------
11236|      0|             ifp->ip) {
  ------------------
  |  Branch (11236:14): [True: 0, False: 0]
  ------------------
11237|      0|    ifp->state = MG_TCPIP_STATE_IP;  // ifp->fn has set an IP
  ------------------
  |  | 4865|      0|#define MG_TCPIP_STATE_IP 4         // IP address assigned; resolving gateway MAC
  ------------------
11238|      0|    onstatechange(ifp);
11239|      0|  }
11240|  6.10k|}
fuzz.c:_ZL10mg_ip_pollP11mg_tcpip_ifb:
11201|  6.10k|static void mg_ip_poll(struct mg_tcpip_if *ifp, bool s1) {
11202|  6.10k|  if (ifp->state < MG_TCPIP_STATE_UP) return;
  ------------------
  |  | 4863|  6.10k|#define MG_TCPIP_STATE_UP 2         // L2 is ready (e.g. PPP negotiated)
  ------------------
  |  Branch (11202:7): [True: 692, False: 5.40k]
  ------------------
11203|       |  // DHCP RFC-2131 (4.4)
11204|  5.40k|  if (ifp->enable_dhcp_client && s1) {
  ------------------
  |  Branch (11204:7): [True: 0, False: 5.40k]
  |  Branch (11204:34): [True: 0, False: 0]
  ------------------
11205|      0|    if (ifp->state == MG_TCPIP_STATE_UP) {
  ------------------
  |  | 4863|      0|#define MG_TCPIP_STATE_UP 2         // L2 is ready (e.g. PPP negotiated)
  ------------------
  |  Branch (11205:9): [True: 0, False: 0]
  ------------------
11206|      0|      tx_dhcp_discover(ifp);  // INIT (4.4.1)
11207|      0|    } else if (ifp->state == MG_TCPIP_STATE_REQ &&
  ------------------
  |  | 4864|      0|#define MG_TCPIP_STATE_REQ 3        // DHCP REQUESTING: waiting for DHCP offer
  ------------------
  |  Branch (11207:16): [True: 0, False: 0]
  ------------------
11208|      0|               ifp->now >= ifp->lease_expire) {
  ------------------
  |  Branch (11208:16): [True: 0, False: 0]
  ------------------
11209|      0|      ifp->state = MG_TCPIP_STATE_UP;  // REQUEST or ACK lost: DISCOVER again
  ------------------
  |  | 4863|      0|#define MG_TCPIP_STATE_UP 2         // L2 is ready (e.g. PPP negotiated)
  ------------------
11210|      0|    } else if (ifp->state == MG_TCPIP_STATE_READY &&
  ------------------
  |  | 4866|      0|#define MG_TCPIP_STATE_READY 5      // Fully operational; gateway MAC resolved
  ------------------
  |  Branch (11210:16): [True: 0, False: 0]
  ------------------
11211|      0|               ifp->lease_expire > 0) {  // BOUND / RENEWING / REBINDING
  ------------------
  |  Branch (11211:16): [True: 0, False: 0]
  ------------------
11212|      0|      if (ifp->now >= ifp->lease_expire) {
  ------------------
  |  Branch (11212:11): [True: 0, False: 0]
  ------------------
11213|      0|        ifp->state = MG_TCPIP_STATE_UP, ifp->ip = 0;  // expired, release IP
  ------------------
  |  | 4863|      0|#define MG_TCPIP_STATE_UP 2         // L2 is ready (e.g. PPP negotiated)
  ------------------
11214|      0|        onstatechange(ifp);
11215|      0|      } else if (ifp->now + 30UL * 60UL * 1000UL > ifp->lease_expire &&
  ------------------
  |  Branch (11215:18): [True: 0, False: 0]
  ------------------
11216|      0|                 ((ifp->now / 1000) % 60) == 0) {
  ------------------
  |  Branch (11216:18): [True: 0, False: 0]
  ------------------
11217|       |        // hack: 30 min before deadline, try to rebind (4.3.6) every min
11218|      0|        tx_dhcp_request_re(
11219|       |            ifp, mg_l2_mapip(ifp->l2type, MG_TCPIP_L2ADDR_BCAST, NULL), ifp->ip,
11220|      0|            0xffffffff);
11221|      0|      }  // TODO(): Handle T1 (RENEWING) and T2 (REBINDING) (4.4.5)
11222|      0|    }
11223|      0|  }
11224|  5.40k|}
fuzz.c:_ZL11proto_errorP13mg_connectionbPKcz:
10343|  5.40k|static void proto_error(struct mg_connection *c, bool r, const char *f, ...) {
10344|  5.40k|  char buf[64];
10345|  5.40k|  va_list ap;
10346|  5.40k|  struct connstate *s = (struct connstate *) (c + 1);
10347|  5.40k|  va_start(ap, f);
10348|  5.40k|  mg_vsnprintf(buf, sizeof(buf), f, &ap);
10349|  5.40k|  va_end(ap);
10350|  5.40k|  MG_ERROR(("%lu %ld %s", c->id, c->fd, buf));
  ------------------
  |  | 1802|  5.40k|#define MG_ERROR(args) MG_LOG(MG_LL_ERROR, args)
  |  |  ------------------
  |  |  |  | 1792|  5.40k|  do {                      \
  |  |  |  | 1793|  5.40k|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 5.40k]
  |  |  |  |  ------------------
  |  |  |  | 1794|  5.40k|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 5.40k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
10351|  5.40k|  c->is_closing = 1;  // Stop Mongoose I/O
10352|  5.40k|  s->is_closing = 1;  // Transport-terminal; do not send FIN
10353|  5.40k|  if (r && !c->is_udp) s->send_rst = true;  // honot TCP RST request
  ------------------
  |  Branch (10353:7): [True: 0, False: 5.40k]
  |  Branch (10353:12): [True: 0, False: 0]
  ------------------
10354|  5.40k|  mg_call(c, MG_EV_ERROR, buf);
10355|  5.40k|}
fuzz.c:_ZL20mg_pfn_iobuf_privatecPvb:
14556|  30.9M|static void mg_pfn_iobuf_private(char ch, void *param, bool expand) {
14557|  30.9M|  struct mg_iobuf *io = (struct mg_iobuf *) param;
14558|  30.9M|  if (expand && io->len + 2 > io->size) mg_iobuf_resize(io, io->len + 2);
  ------------------
  |  Branch (14558:7): [True: 18.6M, False: 12.2M]
  |  Branch (14558:17): [True: 2.00k, False: 18.6M]
  ------------------
14559|  30.9M|  if (io->len + 2 <= io->size) {
  ------------------
  |  Branch (14559:7): [True: 30.9M, False: 4.39k]
  ------------------
14560|  30.9M|    io->buf[io->len++] = (uint8_t) ch;
14561|  30.9M|    io->buf[io->len] = 0;
14562|  30.9M|  } else if (io->len < io->size) {
  ------------------
  |  Branch (14562:14): [True: 1.84k, False: 2.55k]
  ------------------
14563|  1.84k|    io->buf[io->len++] = 0;  // Guarantee to 0-terminate
14564|  1.84k|  }
14565|  30.9M|}
fuzz.c:_ZL12gettimestampPKj:
15584|    594|static int64_t gettimestamp(const uint32_t *data) {
15585|    594|  uint32_t sec = mg_ntohl(data[0]), frac = mg_ntohl(data[1]);
15586|    594|  if (sec) sec -= SNTP_TIME_OFFSET;
  ------------------
  |  |15575|    560|#define SNTP_TIME_OFFSET 2208988800U  // (1970 - 1900) in seconds
  ------------------
  |  Branch (15586:7): [True: 560, False: 34]
  ------------------
15587|    594|  return ((int64_t) sec) * 1000 + (int64_t) (frac / SNTP_MAX_FRAC * 1000.0);
  ------------------
  |  |15576|    594|#define SNTP_MAX_FRAC 4294967295.0    // 2 ** 32 - 1
  ------------------
15588|    594|}
fuzz.c:_ZL7mg_tolcc:
16602|  2.91M|static int mg_tolc(char c) {
16603|  2.91M|  return (c >= 'A' && c <= 'Z') ? c + 'a' - 'A' : c;
  ------------------
  |  Branch (16603:11): [True: 2.70M, False: 202k]
  |  Branch (16603:23): [True: 1.62M, False: 1.07M]
  ------------------
16604|  2.91M|}
fuzz.c:_ZL8urlparsePKc:
29662|  12.2k|static struct url urlparse(const char *url) {
29663|  12.2k|  size_t i;
29664|  12.2k|  struct url u;
29665|  12.2k|  memset(&u, 0, sizeof(u));
29666|   280k|  for (i = 0; url[i] != '\0'; i++) {
  ------------------
  |  Branch (29666:15): [True: 268k, False: 12.2k]
  ------------------
29667|   268k|    if (url[i] == '/' && i > 0 && u.host == 0 && url[i - 1] == '/') {
  ------------------
  |  Branch (29667:9): [True: 24.4k, False: 244k]
  |  Branch (29667:26): [True: 24.4k, False: 0]
  |  Branch (29667:35): [True: 24.4k, False: 0]
  |  Branch (29667:50): [True: 12.2k, False: 12.2k]
  ------------------
29668|  12.2k|      u.host = i + 1;
29669|  12.2k|      u.port = 0;
29670|   256k|    } else if (url[i] == ']') {
  ------------------
  |  Branch (29670:16): [True: 0, False: 256k]
  ------------------
29671|      0|      u.port = 0;  // IPv6 URLs, like http://[::1]/bar
29672|   256k|    } else if (url[i] == ':' && u.port == 0 && u.uri == 0) {
  ------------------
  |  Branch (29672:16): [True: 24.4k, False: 231k]
  |  Branch (29672:33): [True: 24.4k, False: 0]
  |  Branch (29672:48): [True: 24.4k, False: 0]
  ------------------
29673|  24.4k|      u.port = i + 1;
29674|   231k|    } else if (url[i] == '@' && u.user == 0 && u.pass == 0 && u.uri == 0) {
  ------------------
  |  Branch (29674:16): [True: 0, False: 231k]
  |  Branch (29674:33): [True: 0, False: 0]
  |  Branch (29674:48): [True: 0, False: 0]
  |  Branch (29674:63): [True: 0, False: 0]
  ------------------
29675|      0|      u.user = u.host;
29676|      0|      u.pass = u.port;
29677|      0|      u.host = i + 1;
29678|      0|      u.port = 0;
29679|   231k|    } else if (url[i] == '/' && u.host && u.uri == 0) {
  ------------------
  |  Branch (29679:16): [True: 12.2k, False: 219k]
  |  Branch (29679:33): [True: 0, False: 12.2k]
  |  Branch (29679:43): [True: 0, False: 0]
  ------------------
29680|      0|      u.uri = i;
29681|      0|    }
29682|   268k|  }
29683|  12.2k|  u.end = i;
29684|       |#if 0
29685|       |  printf("[%s] %d %d %d %d %d\n", url, u.user, u.pass, u.host, u.port, u.uri);
29686|       |#endif
29687|  12.2k|  return u;
29688|  12.2k|}
fuzz.c:_ZL11mg_tcpip_rxP11mg_tcpip_ifPvm:
11178|  6.10k|static void mg_tcpip_rx(struct mg_tcpip_if *ifp, void *buf, size_t len) {
11179|  6.10k|  struct pkt pkt;
11180|  6.10k|  enum mg_l2proto proto;
11181|  6.10k|  memset(&pkt, 0, sizeof(pkt));
11182|  6.10k|  pkt.raw.buf = (char *) buf;
11183|  6.10k|  pkt.raw.len = len;
11184|  6.10k|  pkt.l2 = (uint8_t *) pkt.raw.buf;
11185|  6.10k|  if (!mg_l2_rx(ifp, &proto, &pkt.pay, &pkt.raw)) return;
  ------------------
  |  Branch (11185:7): [True: 5.98k, False: 117]
  ------------------
11186|    117|  if (ifp->state < MG_TCPIP_STATE_UP) return;  // discard while L2 is not up
  ------------------
  |  | 4863|    117|#define MG_TCPIP_STATE_UP 2         // L2 is ready (e.g. PPP negotiated)
  ------------------
  |  Branch (11186:7): [True: 0, False: 117]
  ------------------
11187|    117|  if (proto == MG_TCPIP_L2PROTO_ARP) {
  ------------------
  |  Branch (11187:7): [True: 25, False: 92]
  ------------------
11188|     25|    pkt.arp = (struct arp *) (pkt.pay.buf);
11189|     25|    if (pkt.pay.len < sizeof(*pkt.arp)) return;  // Truncated
  ------------------
  |  Branch (11189:9): [True: 2, False: 23]
  ------------------
11190|     23|    mg_tcpip_call(ifp, MG_TCPIP_EV_ARP, &pkt.raw);
11191|     23|    rx_arp(ifp, &pkt);
11192|     92|  } else if (proto == MG_TCPIP_L2PROTO_IPV6) {
  ------------------
  |  Branch (11192:14): [True: 5, False: 87]
  ------------------
11193|      5|    pkt.ip6 = (struct ip6 *) (pkt.pay.buf);
11194|      5|    rx_ip6(ifp, &pkt);
11195|     87|  } else if (proto == MG_TCPIP_L2PROTO_IPV4) {
  ------------------
  |  Branch (11195:14): [True: 55, False: 32]
  ------------------
11196|     55|    pkt.ip = (struct ip *) (pkt.pay.buf);
11197|     55|    rx_ip(ifp, &pkt);
11198|     55|  }
11199|    117|}
fuzz.c:_ZL6rx_arpP11mg_tcpip_ifP3pkt:
 9754|     23|static void rx_arp(struct mg_tcpip_if *ifp, struct pkt *pkt) {
 9755|     23|  if (pkt->arp->op == mg_htons(1) && pkt->arp->tpa == ifp->ip) {
  ------------------
  |  | 2093|     46|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (9755:7): [True: 7, False: 16]
  |  Branch (9755:38): [True: 0, False: 7]
  ------------------
 9756|       |    // ARP request. Make a response, then send
 9757|       |    // MG_VERBOSE(("ARP req from %M", mg_print_ip4, &pkt->arp->spa));
 9758|      0|    uint8_t *l2p = (uint8_t *) ifp->tx.buf;
 9759|      0|    struct arp *arp = (struct arp *) mg_l2_header(
 9760|      0|        ifp, MG_TCPIP_L2PROTO_ARP, ifp->mac, mg_l2_getaddr(ifp, pkt->l2), l2p);
 9761|      0|    *arp = *pkt->arp;
 9762|      0|    arp->op = mg_htons(2);
  ------------------
  |  | 2093|      0|#define mg_htons(x) mg_ntohs(x)
  ------------------
 9763|      0|    memcpy(arp->tha, pkt->arp->sha, sizeof(pkt->arp->tha));
 9764|      0|    memcpy(arp->sha, ifp->mac, sizeof(pkt->arp->sha));
 9765|      0|    arp->tpa = pkt->arp->spa;
 9766|      0|    arp->spa = ifp->ip;
 9767|      0|    MG_DEBUG(("ARP: tell %M we're %M", mg_print_ip4, &arp->tpa, mg_print_mac,
  ------------------
  |  | 1804|      0|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 9768|      0|              ifp->mac));
 9769|      0|    driver_output(ifp, mg_l2_trailer(ifp, sizeof(*arp), (uint8_t *) (arp + 1)));
 9770|     23|  } else if (pkt->arp->op == mg_htons(2)) {
  ------------------
  |  | 2093|     23|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (9770:14): [True: 3, False: 20]
  ------------------
 9771|      3|    if (memcmp(pkt->arp->tha, ifp->mac, sizeof(pkt->arp->tha)) != 0) return;
  ------------------
  |  Branch (9771:9): [True: 3, False: 0]
  ------------------
 9772|       |    // MG_VERBOSE(("ARP resp from %M", mg_print_ip4, &pkt->arp->spa));
 9773|      0|    if (pkt->arp->spa == ifp->gw) {
  ------------------
  |  Branch (9773:9): [True: 0, False: 0]
  ------------------
 9774|       |      // Got response for the GW ARP request. Set ifp->gwmac and IP -> READY
 9775|      0|      memcpy(ifp->gwmac, pkt->arp->sha, sizeof(ifp->gwmac));
 9776|      0|      ifp->gw_ready = true;
 9777|      0|      if (ifp->state == MG_TCPIP_STATE_IP) {
  ------------------
  |  | 4865|      0|#define MG_TCPIP_STATE_IP 4         // IP address assigned; resolving gateway MAC
  ------------------
  |  Branch (9777:11): [True: 0, False: 0]
  ------------------
 9778|      0|        ifp->state = MG_TCPIP_STATE_READY;
  ------------------
  |  | 4866|      0|#define MG_TCPIP_STATE_READY 5      // Fully operational; gateway MAC resolved
  ------------------
 9779|      0|        onstatechange(ifp);
 9780|      0|      }
 9781|      0|    } else {
 9782|      0|      struct mg_connection *c = getpeer(ifp->mgr, pkt, false);
 9783|      0|      if (c != NULL && c->is_arplooking) {
  ------------------
  |  Branch (9783:11): [True: 0, False: 0]
  |  Branch (9783:24): [True: 0, False: 0]
  ------------------
 9784|      0|        struct connstate *s = (struct connstate *) (c + 1);
 9785|      0|        memcpy(s->mac, pkt->arp->sha, sizeof(s->mac));
 9786|      0|        MG_DEBUG(("%lu ARP resolved %M -> %M", c->id, mg_print_ip4,
  ------------------
  |  | 1804|      0|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 9787|      0|                  &c->rem.addr.ip4, mg_print_mac, s->mac));
 9788|      0|        c->is_arplooking = 0;
 9789|      0|        l2addr_resolved(c);
 9790|      0|      }
 9791|      0|    }
 9792|      0|  }
 9793|     23|}
fuzz.c:_ZL5rx_ipP11mg_tcpip_ifP3pkt:
11000|     55|static void rx_ip(struct mg_tcpip_if *ifp, struct pkt *pkt) {
11001|     55|  uint8_t ihl;
11002|     55|  uint16_t frag, len;
11003|     55|  if (pkt->pay.len < sizeof(*pkt->ip)) return;  // Truncated
  ------------------
  |  Branch (11003:7): [True: 7, False: 48]
  ------------------
11004|     48|  if ((pkt->ip->ver >> 4) != 4) return;         // Not IP
  ------------------
  |  Branch (11004:7): [True: 0, False: 48]
  ------------------
11005|     48|  ihl = pkt->ip->ver & 0x0F;
11006|     48|  if (ihl < 5) return;                              // bad IHL
  ------------------
  |  Branch (11006:7): [True: 11, False: 37]
  ------------------
11007|     37|  if (pkt->pay.len < (uint16_t) (ihl * 4)) return;  // Truncated / malformed
  ------------------
  |  Branch (11007:7): [True: 2, False: 35]
  ------------------
11008|       |  // There can be link padding, take length from IP header
11009|     35|  len = mg_ntohs(pkt->ip->len);  // IP datagram length
11010|     35|  if (len < (uint16_t) (ihl * 4) || len > pkt->pay.len) return;  // malformed
  ------------------
  |  Branch (11010:7): [True: 0, False: 35]
  |  Branch (11010:37): [True: 8, False: 27]
  ------------------
11011|     27|  pkt->pay.len = len;                      // strip padding
11012|     27|  mkpay(pkt, (uint32_t *) pkt->ip + ihl);  // account for opts
11013|     27|  if (!ipcsum_ok(pkt->ip)) return;
  ------------------
  |  Branch (11013:7): [True: 24, False: 3]
  ------------------
11014|      3|  frag = mg_ntohs(pkt->ip->frag);
11015|      3|  if (frag & IP_FRAG_OFFSET_MSK) {  // Non-first fragment: ignore
  ------------------
  |  | 9213|      3|#define IP_FRAG_OFFSET_MSK 0x1fff
  ------------------
  |  Branch (11015:7): [True: 0, False: 3]
  ------------------
11016|      3|  } else if (frag & IP_MORE_FRAGS_MSK) {  // First fragment: find and close
  ------------------
  |  | 9214|      3|#define IP_MORE_FRAGS_MSK 0x2000
  ------------------
  |  Branch (11016:14): [True: 0, False: 3]
  ------------------
11017|      0|    if (pkt->ip->proto == 17 && pkt->pay.len >= sizeof(*pkt->udp))
  ------------------
  |  Branch (11017:9): [True: 0, False: 0]
  |  Branch (11017:33): [True: 0, False: 0]
  ------------------
11018|      0|      pkt->udp = (struct udp *) pkt->pay.buf;
11019|      0|    if (pkt->ip->proto == 6 && pkt->pay.len >= sizeof(*pkt->tcp))
  ------------------
  |  Branch (11019:9): [True: 0, False: 0]
  |  Branch (11019:32): [True: 0, False: 0]
  ------------------
11020|      0|      pkt->tcp = (struct tcp *) pkt->pay.buf;
11021|      0|    if (pkt->udp || pkt->tcp) {
  ------------------
  |  Branch (11021:9): [True: 0, False: 0]
  |  Branch (11021:21): [True: 0, False: 0]
  ------------------
11022|      0|      struct mg_connection *c = getpeer(ifp->mgr, pkt, false);
11023|      0|      if (c) proto_error(c, false, "Received fragmented packet");
  ------------------
  |  Branch (11023:11): [True: 0, False: 0]
  ------------------
11024|      0|    }  // else ignore                                      // else ignore
11025|      3|  } else if (pkt->ip->proto == 1) {
  ------------------
  |  Branch (11025:14): [True: 3, False: 0]
  ------------------
11026|      3|    pkt->icmp = (struct icmp *) (pkt->pay.buf);
11027|      3|    if (pkt->pay.len < sizeof(*pkt->icmp)) return;
  ------------------
  |  Branch (11027:9): [True: 0, False: 3]
  ------------------
11028|      3|    mkpay(pkt, pkt->icmp + 1);
11029|      3|    rx_icmp(ifp, pkt);
11030|      3|  } else if (pkt->ip->proto == 17) {
  ------------------
  |  Branch (11030:14): [True: 0, False: 0]
  ------------------
11031|      0|    pkt->udp = (struct udp *) (pkt->pay.buf);
11032|      0|    if (pkt->pay.len < sizeof(*pkt->udp)) return;  // truncated
  ------------------
  |  Branch (11032:9): [True: 0, False: 0]
  ------------------
11033|       |    // Take length from UDP header
11034|      0|    len = mg_ntohs(pkt->udp->len);  // UDP datagram length
11035|      0|    if (len < sizeof(*pkt->udp) || len > pkt->pay.len) return;  // malformed
  ------------------
  |  Branch (11035:9): [True: 0, False: 0]
  |  Branch (11035:36): [True: 0, False: 0]
  ------------------
11036|      0|    pkt->pay.len = len;  // strip excess data
11037|      0|    mkpay(pkt, pkt->udp + 1);
11038|      0|    MG_VERBOSE(("UDP %M:%hu -> %M:%hu len %u", mg_print_ip4, &pkt->ip->src,
  ------------------
  |  | 1805|      0|#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
11039|      0|                mg_ntohs(pkt->udp->sport), mg_print_ip4, &pkt->ip->dst,
11040|      0|                mg_ntohs(pkt->udp->dport), (int) pkt->pay.len));
11041|      0|    if (ifp->enable_dhcp_client && pkt->udp->dport == mg_htons(68) &&
  ------------------
  |  | 2093|      0|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (11041:9): [True: 0, False: 0]
  |  Branch (11041:36): [True: 0, False: 0]
  ------------------
11042|      0|        len >= offsetof(struct dhcp, options)) {
  ------------------
  |  Branch (11042:9): [True: 0, False: 0]
  ------------------
11043|      0|      pkt->dhcp = (struct dhcp *) (pkt->udp + 1);
11044|      0|      mkpay(pkt, &pkt->dhcp->options);
11045|      0|      rx_dhcp_client(ifp, pkt);
11046|      0|    } else if (ifp->enable_dhcp_server && pkt->udp->dport == mg_htons(67) &&
  ------------------
  |  | 2093|      0|#define mg_htons(x) mg_ntohs(x)
  ------------------
  |  Branch (11046:16): [True: 0, False: 0]
  |  Branch (11046:43): [True: 0, False: 0]
  ------------------
11047|      0|               len >= offsetof(struct dhcp, options)) {
  ------------------
  |  Branch (11047:16): [True: 0, False: 0]
  ------------------
11048|      0|      pkt->dhcp = (struct dhcp *) (pkt->udp + 1);
11049|      0|      mkpay(pkt, &pkt->dhcp->options);
11050|      0|      rx_dhcp_server(ifp, pkt);
11051|      0|    } else if (!rx_udp(ifp, pkt)) {
  ------------------
  |  Branch (11051:16): [True: 0, False: 0]
  ------------------
11052|       |      // Should send ICMP Destination Unreachable for unicasts, but keep
11053|       |      // silent
11054|      0|    }
11055|      0|  } else if (pkt->ip->proto == 6) {
  ------------------
  |  Branch (11055:14): [True: 0, False: 0]
  ------------------
11056|      0|    uint8_t off;
11057|      0|    pkt->tcp = (struct tcp *) (pkt->pay.buf);
11058|      0|    if (pkt->pay.len < sizeof(*pkt->tcp)) return;
  ------------------
  |  Branch (11058:9): [True: 0, False: 0]
  ------------------
11059|      0|    off = pkt->tcp->off >> 4;  // account for opts
11060|      0|    if (off < sizeof(*pkt->tcp) / 4 || pkt->pay.len < (uint16_t) (4 * off))
  ------------------
  |  Branch (11060:9): [True: 0, False: 0]
  |  Branch (11060:40): [True: 0, False: 0]
  ------------------
11061|      0|      return;
11062|      0|    mkpay(pkt, (uint32_t *) pkt->tcp + off);
11063|      0|    MG_VERBOSE(("TCP %M:%hu -> %M:%hu len %u", mg_print_ip4, &pkt->ip->src,
  ------------------
  |  | 1805|      0|#define MG_VERBOSE(args) MG_LOG(MG_LL_VERBOSE, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
11064|      0|                mg_ntohs(pkt->tcp->sport), mg_print_ip4, &pkt->ip->dst,
11065|      0|                mg_ntohs(pkt->tcp->dport), (int) pkt->pay.len));
11066|      0|    rx_tcp(ifp, pkt);
11067|      0|  } else {
11068|      0|    MG_DEBUG(("Unknown IP proto %x", (int) pkt->ip->proto));
  ------------------
  |  | 1804|      0|#define MG_DEBUG(args) MG_LOG(MG_LL_DEBUG, args)
  |  |  ------------------
  |  |  |  | 1792|      0|  do {                      \
  |  |  |  | 1793|      0|    if (0) mg_log args;     \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1793:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  |  | 1794|      0|  } while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1794:12): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
11069|      0|    if (mg_log_level >= MG_LL_VERBOSE)
  ------------------
  |  Branch (11069:9): [True: 0, False: 0]
  ------------------
11070|      0|      mg_hexdump(pkt->ip, pkt->pay.len >= 32 ? 32 : pkt->pay.len);
  ------------------
  |  Branch (11070:27): [True: 0, False: 0]
  ------------------
11071|      0|  }
11072|      3|}
fuzz.c:_ZL5mkpayP3pktPv:
 9393|     30|static void mkpay(struct pkt *pkt, void *p) {
 9394|     30|  pkt->pay =
 9395|     30|      mg_str_n((char *) p, (size_t) (&pkt->pay.buf[pkt->pay.len] - (char *) p));
 9396|     30|}
fuzz.c:_ZL9ipcsum_okPKv:
 9416|     27|static bool ipcsum_ok(const void *d) {
 9417|     27|  struct ip *ip = (struct ip *) d;
 9418|     27|  return (ipcsum(d, (ip->ver & 0x0F) * 4) == 0);
 9419|     27|}
fuzz.c:_ZL7rx_icmpP11mg_tcpip_ifP3pkt:
 9795|      3|static void rx_icmp(struct mg_tcpip_if *ifp, struct pkt *pkt) {
 9796|      3|  size_t plen = pkt->pay.len;
 9797|      3|  if (!icmpcsum_ok(pkt->icmp, sizeof(struct icmp) + plen)) return;
  ------------------
  |  Branch (9797:7): [True: 3, False: 0]
  ------------------
 9798|      0|  if (pkt->icmp->type == 8 && pkt->ip != NULL && pkt->ip->dst == ifp->ip) {
  ------------------
  |  Branch (9798:7): [True: 0, False: 0]
  |  Branch (9798:31): [True: 0, False: 0]
  |  Branch (9798:50): [True: 0, False: 0]
  ------------------
 9799|      0|    size_t l2_max_overhead = ifp->framesize - ifp->l2mtu;
 9800|      0|    size_t hlen = sizeof(struct ip) + sizeof(struct icmp);
 9801|      0|    size_t room = ifp->tx.len - hlen - l2_max_overhead;
 9802|      0|    uint8_t *l2addr;
 9803|      0|    struct ip *ip;
 9804|      0|    struct icmp *icmp;
 9805|      0|    struct mg_addr ips;
 9806|      0|    ips.addr.ip4 = pkt->ip->src;
 9807|      0|    ips.is_ip6 = false;
 9808|      0|    if ((l2addr = get_return_l2addr(ifp, &ips, false, pkt)) == NULL)
  ------------------
  |  Branch (9808:9): [True: 0, False: 0]
  ------------------
 9809|      0|      return;  // safety net for lousy networks
 9810|      0|    if (plen > room) plen = room;
  ------------------
  |  Branch (9810:9): [True: 0, False: 0]
  ------------------
 9811|      0|    ip = tx_ip(ifp, l2addr, 1, 0, ifp->ip, pkt->ip->src, sizeof(*icmp) + plen);
 9812|      0|    icmp = (struct icmp *) (ip + 1);
 9813|      0|    memset(icmp, 0, sizeof(*icmp));        // Set csum, type, code to 0
 9814|      0|    memcpy(icmp + 1, pkt->pay.buf, plen);  // Copy RX payload to TX
 9815|      0|    icmp->csum = ipcsum(icmp, sizeof(*icmp) + plen);
 9816|      0|    driver_output(
 9817|      0|        ifp, mg_l2_trailer(ifp, hlen + plen, (uint8_t *) ip + hlen + plen));
 9818|      0|  }
 9819|      0|}
fuzz.c:_ZL11icmpcsum_okPKvm:
 9421|      3|static bool icmpcsum_ok(const void *d, size_t len) {
 9422|      3|  return (ipcsum(d, len) == 0);
 9423|      3|}

