// File: /workspace/github_c_makefile_star2_O0/FH0[P]tun_direct/lwip-2.1.2/src/core/pbuf.c
// Function: pbuf_alloc
struct pbuf *
pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
{
  struct pbuf *p;
  u16_t offset = (u16_t)layer;
  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc(length=%"U16_F")\n", length));

  switch (type) {
    case PBUF_REF: /* fall through */
    case PBUF_ROM:
      p = pbuf_alloc_reference(NULL, length, type);
      break;
    case PBUF_POOL: {
      struct pbuf *q, *last;
      u16_t rem_len; /* remaining length */
      p = NULL;
      last = NULL;
      rem_len = length;
      do {
        u16_t qlen;
        q = (struct pbuf *)memp_malloc(MEMP_PBUF_POOL);
        if (q == NULL) {
          PBUF_POOL_IS_EMPTY();
          /* free chain so far allocated */
          if (p) {
            pbuf_free(p);
          }
          /* bail out unsuccessfully */
          return NULL;
        }
        qlen = LWIP_MIN(rem_len, (u16_t)(PBUF_POOL_BUFSIZE_ALIGNED - LWIP_MEM_ALIGN_SIZE(offset)));
        pbuf_init_alloced_pbuf(q, LWIP_MEM_ALIGN((void *)((u8_t *)q + SIZEOF_STRUCT_PBUF + offset)),
                               rem_len, qlen, type, 0);
        LWIP_ASSERT("pbuf_alloc: pbuf q->payload properly aligned",
                    ((mem_ptr_t)q->payload % MEM_ALIGNMENT) == 0);
        LWIP_ASSERT("PBUF_POOL_BUFSIZE must be bigger than MEM_ALIGNMENT",
                    (PBUF_POOL_BUFSIZE_ALIGNED - LWIP_MEM_ALIGN_SIZE(offset)) > 0 );
        if (p == NULL) {
          /* allocated head of pbuf chain (into p) */
          p = q;
        } else {
          /* make previous pbuf point to this pbuf */
          last->next = q;
        }
        last = q;
        rem_len = (u16_t)(rem_len - qlen);
        offset = 0;
      } while (rem_len > 0);
      break;
    }
    case PBUF_RAM: {
      u16_t payload_len = (u16_t)(LWIP_MEM_ALIGN_SIZE(offset) + LWIP_MEM_ALIGN_SIZE(length));
      mem_size_t alloc_len = (mem_size_t)(LWIP_MEM_ALIGN_SIZE(SIZEOF_STRUCT_PBUF) + payload_len);

      /* bug #50040: Check for integer overflow when calculating alloc_len */
      if ((payload_len < LWIP_MEM_ALIGN_SIZE(length)) ||
          (alloc_len < LWIP_MEM_ALIGN_SIZE(length))) {
        return NULL;
      }

      /* If pbuf is to be allocated in RAM, allocate memory for it. */
      p = (struct pbuf *)mem_malloc(alloc_len);
      if (p == NULL) {
        return NULL;
      }
      pbuf_init_alloced_pbuf(p, LWIP_MEM_ALIGN((void *)((u8_t *)p + SIZEOF_STRUCT_PBUF + offset)),
                             length, length, type, 0);
      LWIP_ASSERT("pbuf_alloc: pbuf->payload properly aligned",
                  ((mem_ptr_t)p->payload % MEM_ALIGNMENT) == 0);
      break;
    }
    default:
      LWIP_ASSERT("pbuf_alloc: erroneous type", 0);
      return NULL;
  }
  LWIP_DEBUGF(PBUF_DEBUG | LWIP_DBG_TRACE, ("pbuf_alloc(length=%"U16_F") == %p\n", length, (void *)p));
  return p;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movw %si, %ax
movl %edi, -0xc(%rbp)
movw %ax, -0xe(%rbp)
movl %edx, -0x14(%rbp)
movl -0xc(%rbp), %eax
movw %ax, -0x22(%rbp)
jmp 0x6e3e
movl -0x14(%rbp), %eax
movl %eax, -0x4c(%rbp)
subl $0x1, %eax
je 0x6e74
jmp 0x6e4b
movl -0x4c(%rbp), %eax
subl $0x41, %eax
je 0x6e74
jmp 0x6e55
movl -0x4c(%rbp), %eax
subl $0x182, %eax            # imm = 0x182
je 0x6e90
jmp 0x6e61
movl -0x4c(%rbp), %eax
subl $0x280, %eax            # imm = 0x280
je 0x7040
jmp 0x7149
movw -0xe(%rbp), %ax
movl -0x14(%rbp), %edx
xorl %ecx, %ecx
movl %ecx, %edi
movzwl %ax, %esi
callq 0x71a0
movq %rax, -0x20(%rbp)
jmp 0x717c
movq $0x0, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movw -0xe(%rbp), %ax
movw %ax, -0x3a(%rbp)
movl $0xb, %edi
callq 0x4930
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x6edf
callq 0x7250
cmpq $0x0, -0x20(%rbp)
je 0x6ed2
movq -0x20(%rbp), %rdi
callq 0x7260
movq $0x0, -0x8(%rbp)
jmp 0x7188
movzwl -0x3a(%rbp), %eax
movzwl -0x22(%rbp), %edx
addl $0x1, %edx
subl $0x1, %edx
andl $-0x1, %edx
movl $0x5ea, %ecx            # imm = 0x5EA
subl %edx, %ecx
movzwl %cx, %ecx
cmpl %ecx, %eax
jge 0x6f07
movzwl -0x3a(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x6f21
movzwl -0x22(%rbp), %ecx
addl $0x1, %ecx
subl $0x1, %ecx
andl $-0x1, %ecx
movl $0x5ea, %eax            # imm = 0x5EA
subl %ecx, %eax
movzwl %ax, %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movw %ax, -0x3c(%rbp)
movq -0x30(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x18, %rsi
movzwl -0x22(%rbp), %eax
cltq
addq %rax, %rsi
addq $0x1, %rsi
subq $0x1, %rsi
andq $-0x1, %rsi
movw -0x3a(%rbp), %cx
movw -0x3c(%rbp), %ax
movl -0x14(%rbp), %r8d
xorl %r9d, %r9d
movzwl %cx, %edx
movzwl %ax, %ecx
callq 0x7460
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x0, %rax
cmpq $0x0, %rax
je 0x6fa6
jmp 0x6f77
leaq 0x2034e(%rip), %rdi     # 0x272cc
leaq 0x208f7(%rip), %rsi     # 0x2787c
movl $0x101, %edx            # imm = 0x101
leaq 0x20918(%rip), %rcx     # 0x278a9
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x6fa8
jmp 0x6faa
movzwl -0x22(%rbp), %ecx
addl $0x1, %ecx
subl $0x1, %ecx
andl $-0x1, %ecx
movl $0x5ea, %eax            # imm = 0x5EA
subl %ecx, %eax
cmpl $0x0, %eax
ja 0x6ff4
jmp 0x6fc5
leaq 0x20300(%rip), %rdi     # 0x272cc
leaq 0x208f1(%rip), %rsi     # 0x278c4
movl $0x103, %edx            # imm = 0x103
leaq 0x208ca(%rip), %rcx     # 0x278a9
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x6ff6
cmpq $0x0, -0x20(%rbp)
jne 0x7007
movq -0x30(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x7012
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movzwl -0x3a(%rbp), %eax
movzwl -0x3c(%rbp), %ecx
subl %ecx, %eax
movw %ax, -0x3a(%rbp)
movw $0x0, -0x22(%rbp)
movzwl -0x3a(%rbp), %eax
cmpl $0x0, %eax
jg 0x6ea8
jmp 0x717c
movzwl -0x22(%rbp), %eax
addl $0x1, %eax
subl $0x1, %eax
andl $-0x1, %eax
movzwl -0xe(%rbp), %ecx
addl $0x1, %ecx
subl $0x1, %ecx
andl $-0x1, %ecx
addl %ecx, %eax
movw %ax, -0x3e(%rbp)
movzwl -0x3e(%rbp), %eax
addq $0x18, %rax
movq %rax, -0x48(%rbp)
movzwl -0x3e(%rbp), %eax
movzwl -0xe(%rbp), %ecx
addl $0x1, %ecx
subl $0x1, %ecx
andl $-0x1, %ecx
cmpl %ecx, %eax
jb 0x7099
movq -0x48(%rbp), %rax
movzwl -0xe(%rbp), %ecx
addl $0x1, %ecx
subl $0x1, %ecx
andl $-0x1, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x70a6
movq $0x0, -0x8(%rbp)
jmp 0x7188
movq -0x48(%rbp), %rdi
callq 0x4650
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x70c7
movq $0x0, -0x8(%rbp)
jmp 0x7188
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x18, %rsi
movzwl -0x22(%rbp), %eax
cltq
addq %rax, %rsi
addq $0x1, %rsi
subq $0x1, %rsi
andq $-0x1, %rsi
movw -0xe(%rbp), %cx
movw -0xe(%rbp), %ax
movl -0x14(%rbp), %r8d
xorl %r9d, %r9d
movzwl %cx, %edx
movzwl %ax, %ecx
callq 0x7460
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x0, %rax
cmpq $0x0, %rax
je 0x7145
jmp 0x7116
leaq 0x201af(%rip), %rdi     # 0x272cc
leaq 0x207d4(%rip), %rsi     # 0x278f8
movl $0x123, %edx            # imm = 0x123
leaq 0x20779(%rip), %rcx     # 0x278a9
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x7147
jmp 0x717c
jmp 0x714b
jmp 0x714d
leaq 0x20178(%rip), %rdi     # 0x272cc
leaq 0x207c8(%rip), %rsi     # 0x27923
movl $0x127, %edx            # imm = 0x127
leaq 0x20742(%rip), %rcx     # 0x278a9
movb $0x0, %al
callq 0x20d0
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
callq 0x2040
jmp 0x717e
jmp 0x7180
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)