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

/* Variables and functions */
int /*<<< orphan*/ c2enc_process_samples(struct c2enc_context_s *,
                                         int /*<<< orphan*/ *);
int c2enc_write(struct c2enc_context_s *ctx, int16_t *buf, uint32_t nsamples) {
  uint32_t done = 0;
  while (nsamples >= 80) {
    c2enc_process_samples(ctx, buf + done);
    done += 80;
    nsamples -= 80;
  }
  return done;
}


x86 assembly (clang, -O0):
<c2enc_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x50,-0x14(%rbp)
jl     1163 <c2enc_write+0x53>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <c2enc_process_samples@plt>
mov    -0x18(%rbp),%eax
add    $0x50,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x50,%eax
mov    %eax,-0x14(%rbp)
jmp    112a <c2enc_write+0x1a>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c2enc_write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
cmp    $0x50,%edx
jl     1156 <c2enc_write+0x46>
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
add    $0x50,%r14d
xor    %ebp,%ebp
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <c2enc_process_samples@plt>
add    $0x140,%rbx
mov    %ebp,%eax
add    $0xffffffb0,%ebp
add    %r14d,%eax
add    $0xffffffb0,%eax
cmp    $0x9f,%eax
ja     1130 <c2enc_write+0x20>
neg    %ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.c2enc_context_s = type { i32 }
define i32 @c2enc_write(%struct.c2enc_context_s* %0, i32* %1, i32 %2) {
%4 = alloca %struct.c2enc_context_s*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store %struct.c2enc_context_s* %0, %struct.c2enc_context_s** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %11, %3
%9 = load i32, i32* %6
%10 = icmp sge i32 %9, 80
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = load %struct.c2enc_context_s*, %struct.c2enc_context_s** %4
%13 = load i32*, i32** %5
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = call i32 @c2enc_process_samples(%struct.c2enc_context_s* %12, i32* %16)
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 80
store i32 %19, i32* %7
%20 = load i32, i32* %6
%21 = sub nsw i32 %20, 80
store i32 %21, i32* %6
br label %8
22: ; preds = %8
%23 = load i32, i32* %7
ret i32 %23
}

LLVM IR (-O2):
%struct.c2enc_context_s = type { i32 }
define i32 @c2enc_write(%struct.c2enc_context_s* %0, i32* %1, i32 %2) {
%4 = icmp sgt i32 %2, 79
br i1 %4, label %5, label %15
5: ; preds = %3, %5
%6 = phi i64 [ %10, %5 ], [ 0, %3 ]
%7 = phi i32 [ %11, %5 ], [ %2, %3 ]
%8 = getelementptr inbounds i32, i32* %1, i64 %6
%9 = tail call i32 @c2enc_process_samples(%struct.c2enc_context_s* %0, i32* %8)
%10 = add nuw nsw i64 %6, 80
%11 = add nsw i32 %7, -80
%12 = icmp ugt i32 %7, 159
br i1 %12, label %5, label %13
13: ; preds = %5
%14 = trunc i64 %10 to i32
br label %15
15: ; preds = %13, %3
%16 = phi i32 [ 0, %3 ], [ %14, %13 ]
ret i32 %16
}