#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 buffer_h {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
int /*<<< orphan*/ process_chunk(struct buffer_h *, int);
unsigned int read_one_frame(int, struct buffer_h *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void read_all_frames(int fd, int channel) {
  unsigned int num_samples;
  char buf[(2048)];
  while ((num_samples = read_one_frame(fd, (struct buffer_h *)buf, 0))) {
    fprintf(stderr, "read %d samples\n", num_samples);
    process_chunk((struct buffer_h *)buf, channel);
  }
}


x86 assembly (clang, -O0):
<read_all_frames>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x810(%rbp),%rsi
xor    %edx,%edx
call   1040 <read_one_frame@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     118a <read_all_frames+0x5a>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe8f(%rip),%rsi
call   1030 <fprintf@plt>
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <process_chunk@plt>
jmp    1141 <read_all_frames+0x11>
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_all_frames>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %esi,%r15d
mov    %edi,%ebp
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <read_one_frame@plt>
test   %eax,%eax
je     1199 <read_all_frames+0x69>
mov    0x2e87(%rip),%r12
lea    0xea0(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1050 <process_chunk@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <read_one_frame@plt>
test   %eax,%eax
jne    1170 <read_all_frames+0x40>
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.buffer_h = type { i32 }
@stderr = global i32 0
@.str = [17 x i8] c"read %d samples\0A\00"
define void @read_all_frames(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2048 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %7
7: ; preds = %13, %2
%8 = load i32, i32* %3
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%10 = bitcast i8* %9 to %struct.buffer_h*
%11 = call i32 @read_one_frame(i32 %8, %struct.buffer_h* %10, i32 0)
store i32 %11, i32* %5
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %7
%14 = load i32, i32* @stderr
%15 = load i32, i32* %5
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%18 = bitcast i8* %17 to %struct.buffer_h*
%19 = load i32, i32* %4
%20 = call i32 @process_chunk(%struct.buffer_h* %18, i32 %19)
br label %7
21: ; preds = %7
ret void
}

LLVM IR (-O2):
%struct.buffer_h = type { i32 }
@stderr = global i32 0
@.str = [17 x i8] c"read %d samples\0A\00"
define void @read_all_frames(i32 %0, i32 %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = bitcast [2048 x i8]* %3 to %struct.buffer_h*
%6 = call i32 @read_one_frame(i32 %0, %struct.buffer_h* %5, i32 0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %2, %8
%9 = phi i32 [ %13, %8 ], [ %6, %2 ]
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %9)
%12 = call i32 @process_chunk(%struct.buffer_h* %5, i32 %1)
%13 = call i32 @read_one_frame(i32 %0, %struct.buffer_h* %5, i32 0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %8
15: ; preds = %8, %2
ret void
}