#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 tone_detector {
  int dummy;
};
typedef int /*<<< orphan*/ int16_t;

/* Variables and functions */
int /*<<< orphan*/ tone_detector_process_partial_frame(struct tone_detector *,
                                                       int /*<<< orphan*/ *,
                                                       int);
void tone_detector_process_frame(struct tone_detector *t, int16_t *frame,
                                 int samples) {
  while (samples > 0) {
    int s = samples > 256 ? 256 : samples;
    tone_detector_process_partial_frame(t, frame, s);
    samples -= s;
    frame += s;
  }
}


x86 assembly (clang, -O0):
<tone_detector_process_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1188 <tone_detector_process_frame+0x78>
cmpl   $0x100,-0x14(%rbp)
jle    1147 <tone_detector_process_frame+0x37>
mov    $0x100,%eax
mov    %eax,-0x1c(%rbp)
jmp    114d <tone_detector_process_frame+0x3d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <tone_detector_process_partial_frame@plt>
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1123 <tone_detector_process_frame+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tone_detector_process_frame>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    1153 <tone_detector_process_frame+0x43>
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x100,%ebp
mov    $0x100,%ebx
cmovb  %ebp,%ebx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <tone_detector_process_partial_frame@plt>
lea    (%r14,%rbx,4),%r14
sub    %ebx,%ebp
jg     1130 <tone_detector_process_frame+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tone_detector = type { i32 }
define void @tone_detector_process_frame(%struct.tone_detector* %0, i32* %1, i32 %2) {
%4 = alloca %struct.tone_detector*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store %struct.tone_detector* %0, %struct.tone_detector** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %17, %3
%9 = load i32, i32* %6
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %30
11: ; preds = %8
%12 = load i32, i32* %6
%13 = icmp sgt i32 %12, 256
br i1 %13, label %14, label %15
14: ; preds = %11
br label %17
15: ; preds = %11
%16 = load i32, i32* %6
br label %17
17: ; preds = %15, %14
%18 = phi i32 [ 256, %14 ], [ %16, %15 ]
store i32 %18, i32* %7
%19 = load %struct.tone_detector*, %struct.tone_detector** %4
%20 = load i32*, i32** %5
%21 = load i32, i32* %7
%22 = call i32 @tone_detector_process_partial_frame(%struct.tone_detector* %19, i32* %20, i32 %21)
%23 = load i32, i32* %7
%24 = load i32, i32* %6
%25 = sub nsw i32 %24, %23
store i32 %25, i32* %6
%26 = load i32, i32* %7
%27 = load i32*, i32** %5
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i32, i32* %27, i64 %28
store i32* %29, i32** %5
br label %8
30: ; preds = %8
ret void
}

LLVM IR (-O2):
%struct.tone_detector = type { i32 }
define void @tone_detector_process_frame(%struct.tone_detector* %0, i32* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %15
5: ; preds = %3, %5
%6 = phi i32* [ %13, %5 ], [ %1, %3 ]
%7 = phi i32 [ %11, %5 ], [ %2, %3 ]
%8 = icmp ult i32 %7, 256
%9 = select i1 %8, i32 %7, i32 256
%10 = tail call i32 @tone_detector_process_partial_frame(%struct.tone_detector* %0, i32* %6, i32 %9)
%11 = sub nsw i32 %7, %9
%12 = zext i32 %9 to i64
%13 = getelementptr inbounds i32, i32* %6, i64 %12
%14 = icmp sgt i32 %11, 0
br i1 %14, label %5, label %15
15: ; preds = %5, %3
ret void
}