#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 */

/* Variables and functions */
int /*<<< orphan*/ read_s24le(char *);
int /*<<< orphan*/ scale_sample_s24le(int /*<<< orphan*/, int);
int /*<<< orphan*/ write_s24le(char *, int /*<<< orphan*/);
void scale_samples_s24le(char *buf, unsigned int count, int l, int r) {
  int frames = count / 3 / 2;
  if (l != 65536 && r != 65536) {
    while (frames--) {
      write_s24le(buf, scale_sample_s24le(read_s24le(buf), l));
      buf += 3;
      write_s24le(buf, scale_sample_s24le(read_s24le(buf), r));
      buf += 3;
    }
  } else if (l != 65536) {
    while (frames--) {
      write_s24le(buf, scale_sample_s24le(read_s24le(buf), l));
      buf += 3 * 2;
    }
  } else if (r != 65536) {
    buf += 3;
    while (frames--) {
      write_s24le(buf, scale_sample_s24le(read_s24le(buf), r));
      buf += 3 * 2;
    }
  }
}


x86 assembly (clang, -O0):
<scale_samples_s24le>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3,%ecx
xor    %edx,%edx
div    %ecx
shr    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x10000,-0x10(%rbp)
je     11f8 <scale_samples_s24le+0xc8>
cmpl   $0x10000,-0x14(%rbp)
je     11f8 <scale_samples_s24le+0xc8>
jmp    1176 <scale_samples_s24le+0x46>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     11f3 <scale_samples_s24le+0xc3>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <read_s24le@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%esi
call   1040 <scale_sample_s24le@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1050 <write_s24le@plt>
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <read_s24le@plt>
mov    %eax,%edi
mov    -0x14(%rbp),%esi
call   1040 <scale_sample_s24le@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1050 <write_s24le@plt>
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
jmp    1176 <scale_samples_s24le+0x46>
jmp    12cd <scale_samples_s24le+0x19d>
cmpl   $0x10000,-0x10(%rbp)
je     125a <scale_samples_s24le+0x12a>
jmp    120a <scale_samples_s24le+0xda>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     1255 <scale_samples_s24le+0x125>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <read_s24le@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%esi
call   1040 <scale_sample_s24le@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1050 <write_s24le@plt>
mov    -0x8(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x8(%rbp)
jmp    120a <scale_samples_s24le+0xda>
jmp    12c8 <scale_samples_s24le+0x198>
cmpl   $0x10000,-0x14(%rbp)
je     12c3 <scale_samples_s24le+0x193>
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     12be <scale_samples_s24le+0x18e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <read_s24le@plt>
mov    %eax,%edi
mov    -0x14(%rbp),%esi
call   1040 <scale_sample_s24le@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1050 <write_s24le@plt>
mov    -0x8(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x8(%rbp)
jmp    1273 <scale_samples_s24le+0x143>
jmp    12c3 <scale_samples_s24le+0x193>
jmp    12c8 <scale_samples_s24le+0x198>
jmp    12cd <scale_samples_s24le+0x19d>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scale_samples_s24le>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rdi,%rbx
mov    %esi,%eax
mov    $0xaaaaaaab,%r12d
imul   %rax,%r12
shr    $0x22,%r12
cmp    $0x10000,%edx
je     11b8 <scale_samples_s24le+0x88>
cmp    $0x10000,%r14d
je     11b8 <scale_samples_s24le+0x88>
cmp    $0x6,%esi
jb     1236 <scale_samples_s24le+0x106>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <read_s24le@plt>
mov    %eax,%edi
mov    %r15d,%esi
call   1040 <scale_sample_s24le@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <write_s24le@plt>
lea    0x3(%rbx),%rbp
mov    %rbp,%rdi
call   1030 <read_s24le@plt>
mov    %eax,%edi
mov    %r14d,%esi
call   1040 <scale_sample_s24le@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1050 <write_s24le@plt>
add    $0x6,%rbx
add    $0xffffffff,%r12d
jne    1170 <scale_samples_s24le+0x40>
jmp    1236 <scale_samples_s24le+0x106>
cmp    $0x10000,%r15d
je     11f8 <scale_samples_s24le+0xc8>
cmp    $0x6,%esi
jb     1236 <scale_samples_s24le+0x106>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <read_s24le@plt>
mov    %eax,%edi
mov    %r15d,%esi
call   1040 <scale_sample_s24le@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <write_s24le@plt>
add    $0x6,%rbx
add    $0xffffffff,%r12d
jne    11d0 <scale_samples_s24le+0xa0>
jmp    1236 <scale_samples_s24le+0x106>
cmp    $0x10000,%r14d
je     1236 <scale_samples_s24le+0x106>
cmp    $0x6,%esi
jb     1236 <scale_samples_s24le+0x106>
add    $0x3,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <read_s24le@plt>
mov    %eax,%edi
mov    %r14d,%esi
call   1040 <scale_sample_s24le@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <write_s24le@plt>
add    $0x6,%rbx
add    $0xffffffff,%r12d
jne    1210 <scale_samples_s24le+0xe0>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @scale_samples_s24le(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %6
%11 = udiv i32 %10, 3
%12 = udiv i32 %11, 2
store i32 %12, i32* %9
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 65536
br i1 %14, label %15, label %41
15: ; preds = %4
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 65536
br i1 %17, label %18, label %41
18: ; preds = %15
br label %19
19: ; preds = %23, %18
%20 = load i32, i32* %9
%21 = add nsw i32 %20, -1
store i32 %21, i32* %9
%22 = icmp ne i32 %20, 0
br i1 %22, label %23, label %40
23: ; preds = %19
%24 = load i8*, i8** %5
%25 = load i8*, i8** %5
%26 = call i32 @read_s24le(i8* %25)
%27 = load i32, i32* %7
%28 = call i32 @scale_sample_s24le(i32 %26, i32 %27)
%29 = call i32 @write_s24le(i8* %24, i32 %28)
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 3
store i8* %31, i8** %5
%32 = load i8*, i8** %5
%33 = load i8*, i8** %5
%34 = call i32 @read_s24le(i8* %33)
%35 = load i32, i32* %8
%36 = call i32 @scale_sample_s24le(i32 %34, i32 %35)
%37 = call i32 @write_s24le(i8* %32, i32 %36)
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 3
store i8* %39, i8** %5
br label %19
40: ; preds = %19
br label %81
41: ; preds = %15, %4
%42 = load i32, i32* %7
%43 = icmp ne i32 %42, 65536
br i1 %43, label %44, label %59
44: ; preds = %41
br label %45
45: ; preds = %49, %44
%46 = load i32, i32* %9
%47 = add nsw i32 %46, -1
store i32 %47, i32* %9
%48 = icmp ne i32 %46, 0
br i1 %48, label %49, label %58
49: ; preds = %45
%50 = load i8*, i8** %5
%51 = load i8*, i8** %5
%52 = call i32 @read_s24le(i8* %51)
%53 = load i32, i32* %7
%54 = call i32 @scale_sample_s24le(i32 %52, i32 %53)
%55 = call i32 @write_s24le(i8* %50, i32 %54)
%56 = load i8*, i8** %5
%57 = getelementptr inbounds i8, i8* %56, i64 6
store i8* %57, i8** %5
br label %45
58: ; preds = %45
br label %80
59: ; preds = %41
%60 = load i32, i32* %8
%61 = icmp ne i32 %60, 65536
br i1 %61, label %62, label %79
62: ; preds = %59
%63 = load i8*, i8** %5
%64 = getelementptr inbounds i8, i8* %63, i64 3
store i8* %64, i8** %5
br label %65
65: ; preds = %69, %62
%66 = load i32, i32* %9
%67 = add nsw i32 %66, -1
store i32 %67, i32* %9
%68 = icmp ne i32 %66, 0
br i1 %68, label %69, label %78
69: ; preds = %65
%70 = load i8*, i8** %5
%71 = load i8*, i8** %5
%72 = call i32 @read_s24le(i8* %71)
%73 = load i32, i32* %8
%74 = call i32 @scale_sample_s24le(i32 %72, i32 %73)
%75 = call i32 @write_s24le(i8* %70, i32 %74)
%76 = load i8*, i8** %5
%77 = getelementptr inbounds i8, i8* %76, i64 6
store i8* %77, i8** %5
br label %65
78: ; preds = %65
br label %79
79: ; preds = %78, %59
br label %80
80: ; preds = %79, %58
br label %81
81: ; preds = %80, %40
ret void
}

LLVM IR (-O2):
define void @scale_samples_s24le(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = udiv i32 %1, 6
%6 = icmp ne i32 %2, 65536
%7 = icmp ne i32 %3, 65536
%8 = and i1 %6, %7
br i1 %8, label %9, label %24
9: ; preds = %4
%10 = icmp ult i32 %1, 6
br i1 %10, label %50, label %11
11: ; preds = %9, %11
%12 = phi i32 [ %14, %11 ], [ %5, %9 ]
%13 = phi i8* [ %22, %11 ], [ %0, %9 ]
%14 = add nsw i32 %12, -1
%15 = tail call i32 @read_s24le(i8* %13)
%16 = tail call i32 @scale_sample_s24le(i32 %15, i32 %2)
%17 = tail call i32 @write_s24le(i8* %13, i32 %16)
%18 = getelementptr inbounds i8, i8* %13, i64 3
%19 = tail call i32 @read_s24le(i8* %18)
%20 = tail call i32 @scale_sample_s24le(i32 %19, i32 %3)
%21 = tail call i32 @write_s24le(i8* %18, i32 %20)
%22 = getelementptr inbounds i8, i8* %13, i64 6
%23 = icmp eq i32 %14, 0
br i1 %23, label %50, label %11
24: ; preds = %4
br i1 %6, label %25, label %36
25: ; preds = %24
%26 = icmp ult i32 %1, 6
br i1 %26, label %50, label %27
27: ; preds = %25, %27
%28 = phi i32 [ %30, %27 ], [ %5, %25 ]
%29 = phi i8* [ %34, %27 ], [ %0, %25 ]
%30 = add nsw i32 %28, -1
%31 = tail call i32 @read_s24le(i8* %29)
%32 = tail call i32 @scale_sample_s24le(i32 %31, i32 %2)
%33 = tail call i32 @write_s24le(i8* %29, i32 %32)
%34 = getelementptr inbounds i8, i8* %29, i64 6
%35 = icmp eq i32 %30, 0
br i1 %35, label %50, label %27
36: ; preds = %24
%37 = icmp ugt i32 %1, 5
%38 = and i1 %7, %37
br i1 %38, label %39, label %50
39: ; preds = %36
%40 = getelementptr inbounds i8, i8* %0, i64 3
br label %41
41: ; preds = %39, %41
%42 = phi i32 [ %44, %41 ], [ %5, %39 ]
%43 = phi i8* [ %48, %41 ], [ %40, %39 ]
%44 = add nsw i32 %42, -1
%45 = tail call i32 @read_s24le(i8* %43)
%46 = tail call i32 @scale_sample_s24le(i32 %45, i32 %3)
%47 = tail call i32 @write_s24le(i8* %43, i32 %46)
%48 = getelementptr inbounds i8, i8* %43, i64 6
%49 = icmp eq i32 %44, 0
br i1 %49, label %50, label %41
50: ; preds = %41, %27, %11, %25, %9, %36
ret void
}