#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct rte_mempool {
  int dummy;
};
struct rte_mbuf {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ RTE_VERIFY(int);
int /*<<< orphan*/ pktmbuf_reset(struct rte_mbuf *);
int /*<<< orphan*/ rte_mbuf_refcnt_read(struct rte_mbuf *);
int /*<<< orphan*/ rte_mbuf_refcnt_set(struct rte_mbuf *, int);
int rte_mempool_get_bulk(struct rte_mempool *, void **, unsigned int);
scalar_t__ unlikely(int);
int pg_pktmbuf_alloc_bulk(struct rte_mempool *pool, struct rte_mbuf **mbufs,
                          unsigned count) {
  unsigned idx = 0;
  int rc;
  rc = rte_mempool_get_bulk(pool, (void **)mbufs, count);
  if (unlikely(rc))
    return rc;
  switch (count % 4) {
  case 0:
    while (idx != count) {
      RTE_VERIFY(rte_mbuf_refcnt_read(mbufs[idx]) == 0);
      rte_mbuf_refcnt_set(mbufs[idx], 1);
      pktmbuf_reset(mbufs[idx]);
      idx++;
    case 3:
      RTE_VERIFY(rte_mbuf_refcnt_read(mbufs[idx]) == 0);
      rte_mbuf_refcnt_set(mbufs[idx], 1);
      pktmbuf_reset(mbufs[idx]);
      idx++;
    case 2:
      RTE_VERIFY(rte_mbuf_refcnt_read(mbufs[idx]) == 0);
      rte_mbuf_refcnt_set(mbufs[idx], 1);
      pktmbuf_reset(mbufs[idx]);
      idx++;
    case 1:
      RTE_VERIFY(rte_mbuf_refcnt_read(mbufs[idx]) == 0);
      rte_mbuf_refcnt_set(mbufs[idx], 1);
      pktmbuf_reset(mbufs[idx]);
      idx++;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<pg_pktmbuf_alloc_bulk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <rte_mempool_get_bulk@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <unlikely@plt>
cmp    $0x0,%rax
je     11aa <pg_pktmbuf_alloc_bulk+0x4a>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    132b <pg_pktmbuf_alloc_bulk+0x1cb>
mov    -0x1c(%rbp),%eax
and    $0x3,%eax
mov    %rax,-0x30(%rbp)
sub    $0x3,%eax
ja     1324 <pg_pktmbuf_alloc_bulk+0x1c4>
mov    -0x30(%rbp),%rax
lea    0xe38(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    11d6 <pg_pktmbuf_alloc_bulk+0x76>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     131f <pg_pktmbuf_alloc_bulk+0x1bf>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
call   1060 <rte_mbuf_refcnt_read@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <RTE_VERIFY@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    $0x1,%esi
call   1050 <rte_mbuf_refcnt_set@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
call   1040 <pktmbuf_reset@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
call   1060 <rte_mbuf_refcnt_read@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <RTE_VERIFY@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    $0x1,%esi
call   1050 <rte_mbuf_refcnt_set@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
call   1040 <pktmbuf_reset@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
call   1060 <rte_mbuf_refcnt_read@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <RTE_VERIFY@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    $0x1,%esi
call   1050 <rte_mbuf_refcnt_set@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
call   1040 <pktmbuf_reset@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
call   1060 <rte_mbuf_refcnt_read@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <RTE_VERIFY@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    $0x1,%esi
call   1050 <rte_mbuf_refcnt_set@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
call   1040 <pktmbuf_reset@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d6 <pg_pktmbuf_alloc_bulk+0x76>
jmp    1324 <pg_pktmbuf_alloc_bulk+0x1c4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pg_pktmbuf_alloc_bulk>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
call   1070 <rte_mempool_get_bulk@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <unlikely@plt>
test   %rax,%rax
jne    1278 <pg_pktmbuf_alloc_bulk+0x118>
mov    %r14d,%ebx
and    $0x3,%ebx
xor    %ebp,%ebp
lea    0xe6d(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
xor    %ebp,%ebp
cmp    %r14d,%ebx
je     1278 <pg_pktmbuf_alloc_bulk+0x118>
mov    %ebx,%ebp
mov    (%r15,%rbp,8),%rdi
call   1060 <rte_mbuf_refcnt_read@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <RTE_VERIFY@plt>
mov    (%r15,%rbp,8),%rdi
mov    $0x1,%esi
call   1050 <rte_mbuf_refcnt_set@plt>
mov    (%r15,%rbp,8),%rdi
call   1040 <pktmbuf_reset@plt>
add    $0x1,%ebx
mov    %ebx,%ebp
mov    %ebp,%ebx
mov    (%r15,%rbx,8),%rdi
call   1060 <rte_mbuf_refcnt_read@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <RTE_VERIFY@plt>
mov    (%r15,%rbx,8),%rdi
mov    $0x1,%esi
call   1050 <rte_mbuf_refcnt_set@plt>
mov    (%r15,%rbx,8),%rdi
call   1040 <pktmbuf_reset@plt>
add    $0x1,%ebp
mov    %ebp,%ebx
mov    (%r15,%rbx,8),%rdi
call   1060 <rte_mbuf_refcnt_read@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <RTE_VERIFY@plt>
mov    (%r15,%rbx,8),%rdi
mov    $0x1,%esi
call   1050 <rte_mbuf_refcnt_set@plt>
mov    (%r15,%rbx,8),%rdi
call   1040 <pktmbuf_reset@plt>
add    $0x1,%ebp
mov    %ebp,%ebx
mov    (%r15,%rbx,8),%rdi
call   1060 <rte_mbuf_refcnt_read@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <RTE_VERIFY@plt>
mov    (%r15,%rbx,8),%rdi
mov    $0x1,%esi
call   1050 <rte_mbuf_refcnt_set@plt>
mov    (%r15,%rbx,8),%rdi
call   1040 <pktmbuf_reset@plt>
add    $0x1,%ebp
mov    %ebp,%ebx
jmp    119c <pg_pktmbuf_alloc_bulk+0x3c>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rte_mempool = type { i32 }
%struct.rte_mbuf = type { i32 }
define i32 @pg_pktmbuf_alloc_bulk(%struct.rte_mempool* %0, %struct.rte_mbuf** %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.rte_mempool*
%6 = alloca %struct.rte_mbuf**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.rte_mempool* %0, %struct.rte_mempool** %5
store %struct.rte_mbuf** %1, %struct.rte_mbuf*** %6
store i32 %2, i32* %7
store i32 0, i32* %8
%10 = load %struct.rte_mempool*, %struct.rte_mempool** %5
%11 = load %struct.rte_mbuf**, %struct.rte_mbuf*** %6
%12 = bitcast %struct.rte_mbuf** %11 to i8**
%13 = load i32, i32* %7
%14 = call i32 @rte_mempool_get_bulk(%struct.rte_mempool* %10, i8** %12, i32 %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = call i64 @unlikely(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = load i32, i32* %9
store i32 %19, i32* %4
br label %126
20: ; preds = %3
%21 = load i32, i32* %7
%22 = urem i32 %21, 4
switch i32 %22, label %125 [
i32 0, label %23
i32 3, label %52
i32 2, label %76
i32 1, label %100
]
23: ; preds = %20
br label %24
24: ; preds = %100, %23
%25 = load i32, i32* %8
%26 = load i32, i32* %7
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %124
28: ; preds = %24
%29 = load %struct.rte_mbuf**, %struct.rte_mbuf*** %6
%30 = load i32, i32* %8
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %29, i64 %31
%33 = load %struct.rte_mbuf*, %struct.rte_mbuf** %32
%34 = call i32 @rte_mbuf_refcnt_read(%struct.rte_mbuf* %33)
%35 = icmp eq i32 %34, 0
%36 = zext i1 %35 to i32
%37 = call i32 @RTE_VERIFY(i32 %36)
%38 = load %struct.rte_mbuf**, %struct.rte_mbuf*** %6
%39 = load i32, i32* %8
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %38, i64 %40
%42 = load %struct.rte_mbuf*, %struct.rte_mbuf** %41
%43 = call i32 @rte_mbuf_refcnt_set(%struct.rte_mbuf* %42, i32 1)
%44 = load %struct.rte_mbuf**, %struct.rte_mbuf*** %6
%45 = load i32, i32* %8
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %44, i64 %46
%48 = load %struct.rte_mbuf*, %struct.rte_mbuf** %47
%49 = call i32 @pktmbuf_reset(%struct.rte_mbuf* %48)
%50 = load i32, i32* %8
%51 = add i32 %50, 1
store i32 %51, i32* %8
br label %52
52: ; preds = %20, %28
%53 = load %struct.rte_mbuf**, %struct.rte_mbuf*** %6
%54 = load i32, i32* %8
%55 = zext i32 %54 to i64
%56 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %53, i64 %55
%57 = load %struct.rte_mbuf*, %struct.rte_mbuf** %56
%58 = call i32 @rte_mbuf_refcnt_read(%struct.rte_mbuf* %57)
%59 = icmp eq i32 %58, 0
%60 = zext i1 %59 to i32
%61 = call i32 @RTE_VERIFY(i32 %60)
%62 = load %struct.rte_mbuf**, %struct.rte_mbuf*** %6
%63 = load i32, i32* %8
%64 = zext i32 %63 to i64
%65 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %62, i64 %64
%66 = load %struct.rte_mbuf*, %struct.rte_mbuf** %65
%67 = call i32 @rte_mbuf_refcnt_set(%struct.rte_mbuf* %66, i32 1)
%68 = load %struct.rte_mbuf**, %struct.rte_mbuf*** %6
%69 = load i32, i32* %8
%70 = zext i32 %69 to i64
%71 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %68, i64 %70
%72 = load %struct.rte_mbuf*, %struct.rte_mbuf** %71
%73 = call i32 @pktmbuf_reset(%struct.rte_mbuf* %72)
%74 = load i32, i32* %8
%75 = add i32 %74, 1
store i32 %75, i32* %8
br label %76
76: ; preds = %20, %52
%77 = load %struct.rte_mbuf**, %struct.rte_mbuf*** %6
%78 = load i32, i32* %8
%79 = zext i32 %78 to i64
%80 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %77, i64 %79
%81 = load %struct.rte_mbuf*, %struct.rte_mbuf** %80
%82 = call i32 @rte_mbuf_refcnt_read(%struct.rte_mbuf* %81)
%83 = icmp eq i32 %82, 0
%84 = zext i1 %83 to i32
%85 = call i32 @RTE_VERIFY(i32 %84)
%86 = load %struct.rte_mbuf**, %struct.rte_mbuf*** %6
%87 = load i32, i32* %8
%88 = zext i32 %87 to i64
%89 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %86, i64 %88
%90 = load %struct.rte_mbuf*, %struct.rte_mbuf** %89
%91 = call i32 @rte_mbuf_refcnt_set(%struct.rte_mbuf* %90, i32 1)
%92 = load %struct.rte_mbuf**, %struct.rte_mbuf*** %6
%93 = load i32, i32* %8
%94 = zext i32 %93 to i64
%95 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %92, i64 %94
%96 = load %struct.rte_mbuf*, %struct.rte_mbuf** %95
%97 = call i32 @pktmbuf_reset(%struct.rte_mbuf* %96)
%98 = load i32, i32* %8
%99 = add i32 %98, 1
store i32 %99, i32* %8
br label %100
100: ; preds = %20, %76
%101 = load %struct.rte_mbuf**, %struct.rte_mbuf*** %6
%102 = load i32, i32* %8
%103 = zext i32 %102 to i64
%104 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %101, i64 %103
%105 = load %struct.rte_mbuf*, %struct.rte_mbuf** %104
%106 = call i32 @rte_mbuf_refcnt_read(%struct.rte_mbuf* %105)
%107 = icmp eq i32 %106, 0
%108 = zext i1 %107 to i32
%109 = call i32 @RTE_VERIFY(i32 %108)
%110 = load %struct.rte_mbuf**, %struct.rte_mbuf*** %6
%111 = load i32, i32* %8
%112 = zext i32 %111 to i64
%113 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %110, i64 %112
%114 = load %struct.rte_mbuf*, %struct.rte_mbuf** %113
%115 = call i32 @rte_mbuf_refcnt_set(%struct.rte_mbuf* %114, i32 1)
%116 = load %struct.rte_mbuf**, %struct.rte_mbuf*** %6
%117 = load i32, i32* %8
%118 = zext i32 %117 to i64
%119 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %116, i64 %118
%120 = load %struct.rte_mbuf*, %struct.rte_mbuf** %119
%121 = call i32 @pktmbuf_reset(%struct.rte_mbuf* %120)
%122 = load i32, i32* %8
%123 = add i32 %122, 1
store i32 %123, i32* %8
br label %24
124: ; preds = %24
br label %125
125: ; preds = %124, %20
store i32 0, i32* %4
br label %126
126: ; preds = %125, %18
%127 = load i32, i32* %4
ret i32 %127
}

LLVM IR (-O2):
%struct.rte_mempool = type { i32 }
%struct.rte_mbuf = type { i32 }
define i32 @pg_pktmbuf_alloc_bulk(%struct.rte_mempool* %0, %struct.rte_mbuf** %1, i32 %2) {
%4 = bitcast %struct.rte_mbuf** %1 to i8**
%5 = tail call i32 @rte_mempool_get_bulk(%struct.rte_mempool* %0, i8** %4, i32 %2)
%6 = tail call i64 @unlikely(i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %69
8: ; preds = %3
%9 = and i32 %2, 3
switch i32 %9, label %68 [
i32 0, label %10
i32 3, label %26
i32 2, label %40
i32 1, label %54
]
10: ; preds = %8, %54
%11 = phi i32 [ %67, %54 ], [ %9, %8 ]
%12 = icmp eq i32 %11, %2
br i1 %12, label %69, label %13
13: ; preds = %10
%14 = zext i32 %11 to i64
%15 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %1, i64 %14
%16 = load %struct.rte_mbuf*, %struct.rte_mbuf** %15
%17 = tail call i32 @rte_mbuf_refcnt_read(%struct.rte_mbuf* %16)
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
%20 = tail call i32 @RTE_VERIFY(i32 %19)
%21 = load %struct.rte_mbuf*, %struct.rte_mbuf** %15
%22 = tail call i32 @rte_mbuf_refcnt_set(%struct.rte_mbuf* %21, i32 1)
%23 = load %struct.rte_mbuf*, %struct.rte_mbuf** %15
%24 = tail call i32 @pktmbuf_reset(%struct.rte_mbuf* %23)
%25 = add i32 %11, 1
br label %26
26: ; preds = %8, %13
%27 = phi i32 [ %25, %13 ], [ 0, %8 ]
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %1, i64 %28
%30 = load %struct.rte_mbuf*, %struct.rte_mbuf** %29
%31 = tail call i32 @rte_mbuf_refcnt_read(%struct.rte_mbuf* %30)
%32 = icmp eq i32 %31, 0
%33 = zext i1 %32 to i32
%34 = tail call i32 @RTE_VERIFY(i32 %33)
%35 = load %struct.rte_mbuf*, %struct.rte_mbuf** %29
%36 = tail call i32 @rte_mbuf_refcnt_set(%struct.rte_mbuf* %35, i32 1)
%37 = load %struct.rte_mbuf*, %struct.rte_mbuf** %29
%38 = tail call i32 @pktmbuf_reset(%struct.rte_mbuf* %37)
%39 = add i32 %27, 1
br label %40
40: ; preds = %8, %26
%41 = phi i32 [ %39, %26 ], [ 0, %8 ]
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %1, i64 %42
%44 = load %struct.rte_mbuf*, %struct.rte_mbuf** %43
%45 = tail call i32 @rte_mbuf_refcnt_read(%struct.rte_mbuf* %44)
%46 = icmp eq i32 %45, 0
%47 = zext i1 %46 to i32
%48 = tail call i32 @RTE_VERIFY(i32 %47)
%49 = load %struct.rte_mbuf*, %struct.rte_mbuf** %43
%50 = tail call i32 @rte_mbuf_refcnt_set(%struct.rte_mbuf* %49, i32 1)
%51 = load %struct.rte_mbuf*, %struct.rte_mbuf** %43
%52 = tail call i32 @pktmbuf_reset(%struct.rte_mbuf* %51)
%53 = add i32 %41, 1
br label %54
54: ; preds = %8, %40
%55 = phi i32 [ 0, %8 ], [ %53, %40 ]
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds %struct.rte_mbuf*, %struct.rte_mbuf** %1, i64 %56
%58 = load %struct.rte_mbuf*, %struct.rte_mbuf** %57
%59 = tail call i32 @rte_mbuf_refcnt_read(%struct.rte_mbuf* %58)
%60 = icmp eq i32 %59, 0
%61 = zext i1 %60 to i32
%62 = tail call i32 @RTE_VERIFY(i32 %61)
%63 = load %struct.rte_mbuf*, %struct.rte_mbuf** %57
%64 = tail call i32 @rte_mbuf_refcnt_set(%struct.rte_mbuf* %63, i32 1)
%65 = load %struct.rte_mbuf*, %struct.rte_mbuf** %57
%66 = tail call i32 @pktmbuf_reset(%struct.rte_mbuf* %65)
%67 = add i32 %55, 1
br label %10
68: ; preds = %8
unreachable
69: ; preds = %10, %3
%70 = phi i32 [ %5, %3 ], [ 0, %10 ]
ret i32 %70
}