#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 */
typedef size_t off_t;

/* Variables and functions */
scalar_t__ stp_count_pkts(char *, size_t);
scalar_t__ stp_find_first_block(char *, size_t, size_t, size_t *, size_t *);
size_t stp_count_pkts_in_raw_etb(char *buf, size_t u8size) {
  off_t start = 0;
  off_t block_off;
  size_t block_len;
  size_t count = 0;
  while (stp_find_first_block(buf, u8size, start, &block_off, &block_len) ==
         0) {
    count += stp_count_pkts(&buf[block_off], block_len);
    start = block_off + block_len;
  }
  return count;
}


x86 assembly (clang, -O0):
<stp_count_pkts_in_raw_etb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%r8
call   1030 <stp_find_first_block@plt>
cmp    $0x0,%rax
jne    118d <stp_count_pkts_in_raw_etb+0x6d>
mov    -0x8(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <stp_count_pkts@plt>
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1140 <stp_count_pkts_in_raw_etb+0x20>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stp_count_pkts_in_raw_etb>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
lea    0x8(%rsp),%rcx
mov    %rsp,%r8
xor    %edx,%edx
call   1030 <stp_find_first_block@plt>
test   %rax,%rax
jne    1193 <stp_count_pkts_in_raw_etb+0x73>
xor    %ebx,%ebx
lea    0x8(%rsp),%r12
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x8(%rsp),%rdi
add    %r15,%rdi
mov    (%rsp),%rsi
call   1040 <stp_count_pkts@plt>
add    %rax,%rbx
mov    (%rsp),%rdx
add    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rcx
mov    %r13,%r8
call   1030 <stp_find_first_block@plt>
test   %rax,%rax
je     1160 <stp_count_pkts_in_raw_etb+0x40>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @stp_count_pkts_in_raw_etb(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %5
store i64 0, i64* %8
br label %9
9: ; preds = %15, %2
%10 = load i8*, i8** %3
%11 = load i64, i64* %4
%12 = load i64, i64* %5
%13 = call i64 @stp_find_first_block(i8* %10, i64 %11, i64 %12, i64* %6, i64* %7)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = load i64, i64* %6
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i64, i64* %7
%20 = call i64 @stp_count_pkts(i8* %18, i64 %19)
%21 = load i64, i64* %8
%22 = add i64 %21, %20
store i64 %22, i64* %8
%23 = load i64, i64* %6
%24 = load i64, i64* %7
%25 = add i64 %23, %24
store i64 %25, i64* %5
br label %9
26: ; preds = %9
%27 = load i64, i64* %8
ret i64 %27
}

LLVM IR (-O2):
define i64 @stp_count_pkts_in_raw_etb(i8* %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = bitcast i64* %3 to i8*
%6 = bitcast i64* %4 to i8*
%7 = call i64 @stp_find_first_block(i8* %0, i64 %1, i64 0, i64* %3, i64* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %2, %9
%10 = phi i64 [ %15, %9 ], [ 0, %2 ]
%11 = load i64, i64* %3
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i64, i64* %4
%14 = call i64 @stp_count_pkts(i8* %12, i64 %13)
%15 = add i64 %14, %10
%16 = load i64, i64* %3
%17 = load i64, i64* %4
%18 = add i64 %17, %16
%19 = call i64 @stp_find_first_block(i8* %0, i64 %1, i64 %18, i64* %3, i64* %4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %9, label %21
21: ; preds = %9, %2
%22 = phi i64 [ 0, %2 ], [ %15, %9 ]
ret i64 %22
}