// File: /workspace/github_c_makefile_star2_O0/pipde[P]deos-songlib/utils/fixclip/fixclip.c
// Function: smooth
static void
smooth(RRA *r,int channel,int start,int finish,int pass)
    {
    int i,j;
    int begin = start - Width;
    int end = finish + Width;
    int width = Width * pass;

    //printf("clipping from %d to %d\n",start,finish);
    //printf("smoothing from %d to %d\n",begin,end);
    //for (i = begin; i < end; ++i)
    //    printf("before: %d is %d\n",i,r->data[channel][i]);

    if (begin < 0) begin = 0;
    if (end > r->samples) end = r->samples;

    for (i = begin; i < finish; ++i) //yes, I mean finish, not end
        {
        double total = 0.0;
        int weight = abs((start+finish) / 2 - (i + width/2)) + 1;
        //printf("weight is %d\n",weight);
        for (j = 0; j < width; ++j)
            {
            if (j == width/2)
                total += r->data[channel][i+j] * weight;
            else
                total += r->data[channel][i+j];
            }
        int divisor = width - 1 + weight;
        //printf("average for %d is %d, divisor is %d\n",
        //    i+width/2,(int)(total / divisor),divisor);
        r->data[channel][i+width/2] = (int)(total / divisor);
        //if (r->data[channel][i+width/2] > Max)
        //    {
        //    printf("Max is %d, smoothed amp is %d, weight is %d\n",
        //        Max,r->data[channel][i+width/2],weight);
        //    for (j = 0; j < width; ++j)
        //        printf("    amp[%d] is %d\n",i+j,r->data[channel][i+j]);
        //    exit(-1);
        //    }
        }

    //for (i = begin; i < end; ++i)
    //    printf("after: %d is %d\n",i,r->data[channel][i]);
    //getchar();
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl -0x10(%rbp), %eax
subl 0x640a(%rip), %eax      # 0x8138
movl %eax, -0x24(%rbp)
movl -0x14(%rbp), %eax
addl 0x63fe(%rip), %eax      # 0x8138
movl %eax, -0x28(%rbp)
movl 0x63f5(%rip), %eax      # 0x8138
imull -0x18(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x1d57
movl $0x0, -0x24(%rbp)
movl -0x28(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jle 0x1d6d
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x1eb3
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x10(%rbp), %eax
addl -0x14(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x44(%rbp)
movl -0x1c(%rbp), %ecx
movl -0x2c(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movl -0x44(%rbp), %eax
addl %edx, %ecx
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x1e51
movl -0x20(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x2c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x48(%rbp), %eax
cmpl %ecx, %eax
jne 0x1e19
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x1c(%rbp), %ecx
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
imull -0x3c(%rbp), %eax
cvtsi2sd %eax, %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x1e41
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x1c(%rbp), %ecx
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x1e43
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1dc3
movl -0x2c(%rbp), %eax
subl $0x1, %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movsd -0x38(%rbp), %xmm0
cvtsi2sdl -0x40(%rbp), %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x54(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
movl -0x1c(%rbp), %ecx
movl -0x2c(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
movl -0x54(%rbp), %edx
movl %eax, %esi
movq -0x50(%rbp), %rax
addl %esi, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1d73
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop