// File: /workspace/github_c_makefile_star2_O1/pipde[P]deos-songlib/utils/flanger/flanger.c
// Function: main
int
main(int argc,char **argv)
    {
    int argIndex = 1;

    int i;
    int *data;
    RRA *h;

    argIndex = processOptions(argc,argv);

    if (argc-argIndex == 0)
        {
        in = stdin;
        out = stdout;
        }
    else if (argc-argIndex == 1)
        {
        in = OpenFile(argv[argIndex],"r");
        out = stdout;
        }
    else if (argc-argIndex == 2)
        {
        in = OpenFile(argv[argIndex],"r");
        out = OpenFile(argv[argIndex+1],"w");
        }
    else
        {
        fprintf(stderr,"usage: flanger -h -a<N.M> -w<N.M> -d<N.M> -l<N.M> "
            "[<input rra file> [<output rra file>]]\n");
        exit(-1);
        }

    songInit();

    h = newRRAHeader();
    
    readRRAHeader(in,h,0);

    minDelay = (int) (h->sampleRate * minDelayFactor / 1000);
    depth = (int) (h->sampleRate * depthFactor / 1000);
    speed = (int) (h->sampleRate / speedFactor);
    offset = (int) (offsetFactor * speed) % speed;

    writeRRAHeader(out,h,"modifiedBy: flanger",0);

    data = (int *) New(sizeof(int) * h->samples);

    if (h->channels != 1)
        Fatal("please run through mono first\n");

    for (i = 0; i < h->samples; ++i)
        {
        double delayed;

        data[i] = readRRAAmplitude(in,out,h->bitsPerSample,outputComment);

        delayed = i - minDelay - sawtooth(speed,depth,offset,i);

        if (delayed >= 0)
            {
            int amp = interp(data,h->samples,delayed);
            fprintf(out,"%d\n", data[i] +
                    (int) (flangeFactor *
                        attenuation * amp));
            flangeFactor += flangeFactorDelta;
            if (flangeFactor < 0) flangeFactor = 0;
            if (flangeFactor > 1) flangeFactor = 1;
            data[i] += feedback * amp;
            }
        else
            fprintf(out,"%d\n",data[i]);
        }

    fclose(in);
    fclose(out);

    return 0;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl %edi, %r14d
movl $0x1, %r12d
cmpl $0x2, %edi
jl 0x28a3
movl $0x1, %r12d
movslq %r12d, %rax
movq (%rbx,%rax,8), %rdx
cmpb $0x2d, (%rdx)
jne 0x28a3
movb 0x2(%rdx), %r15b
testb %r15b, %r15b
je 0x27e4
leaq 0x2(%rdx), %rdi
jmp 0x27e9
movq 0x8(%rbx,%rax,8), %rdi
movzbl 0x1(%rdx), %eax
leal -0x61(%rax), %ecx
cmpl $0xe, %ecx
ja 0x2814
leaq 0x6824(%rip), %rsi      # 0x9020
movslq (%rsi,%rcx,4), %rax
addq %rsi, %rax
jmpq *%rax
callq 0x20a0
movsd %xmm0, 0xa9ae(%rip)     # 0xd1c0
jmp 0x2885
cmpl $0x73, %eax
je 0x2878
cmpl $0x76, %eax
je 0x2c4e
movq 0xa977(%rip), %rsi      # 0xd1a0
xorl %r13d, %r13d
leaq 0x68e4(%rip), %rdi      # 0x9117
xorl %eax, %eax
callq 0x6c80
jmp 0x2888
callq 0x20a0
movsd %xmm0, 0xa967(%rip)     # 0xd1b0
jmp 0x2885
callq 0x20a0
movsd %xmm0, 0xac18(%rip)     # 0xd470
jmp 0x2885
callq 0x20a0
movsd %xmm0, 0xac19(%rip)     # 0xd480
jmp 0x2885
callq 0x20a0
movsd %xmm0, 0xabe2(%rip)     # 0xd458
jmp 0x2885
callq 0x20a0
movsd %xmm0, 0xa933(%rip)     # 0xd1b8
movb $0x1, %r13b
testb %r15b, %r15b
sete %al
andb %r13b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
cmpl %r14d, %r12d
jl 0x27c5
subl %r12d, %r14d
jne 0x28b4
movq 0xa729(%rip), %rax      # 0xcfd8
movq (%rax), %rax
jmp 0x28d7
cmpl $0x2, %r14d
je 0x28ea
cmpl $0x1, %r14d
jne 0x2c71
movslq %r12d, %rax
movq (%rbx,%rax,8), %rdi
leaq 0x6a57(%rip), %rsi      # 0x9329
callq 0x6d1a
movq %rax, 0xab6a(%rip)      # 0xd448
movq 0xa6eb(%rip), %rax      # 0xcfd0
movq (%rax), %rax
jmp 0x2915
movslq %r12d, %r14
movq (%rbx,%r14,8), %rdi
leaq 0x6a31(%rip), %rsi      # 0x9329
callq 0x6d1a
movq %rax, 0xab44(%rip)      # 0xd448
movq 0x8(%rbx,%r14,8), %rdi
leaq 0x6751(%rip), %rsi      # 0x9061
callq 0x6d1a
movq %rax, 0xab34(%rip)      # 0xd450
callq 0x2c78
callq 0x6f97
movq %rax, %rbx
movq 0xab18(%rip), %rdi      # 0xd448
movq %rax, %rsi
xorl %edx, %edx
callq 0x73a4
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%rbx), %xmm0
movsd 0xab0e(%rip), %xmm1     # 0xd458
mulsd %xmm0, %xmm1
movsd 0x66b2(%rip), %xmm2     # 0x9008
divsd %xmm2, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, 0xaafc(%rip)      # 0xd460
movsd 0xa844(%rip), %xmm1     # 0xd1b0
mulsd %xmm0, %xmm1
divsd %xmm2, %xmm1
cvttsd2si %xmm1, %eax
divsd 0xa838(%rip), %xmm0     # 0xd1b8
cvttsd2si %xmm0, %ecx
movl %eax, 0xaada(%rip)      # 0xd464
movl %ecx, 0xaad8(%rip)      # 0xd468
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
mulsd 0xaad0(%rip), %xmm0     # 0xd470
cvttsd2si %xmm0, %eax
cltd
idivl %ecx
movl %edx, 0xaacb(%rip)      # 0xd478
movq 0xaa9c(%rip), %rdi      # 0xd450
leaq 0x6702(%rip), %rdx      # 0x90bd
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x7df5
movl 0xc(%rbx), %edi
shll $0x2, %edi
callq 0x6dad
movq %rax, %r14
cmpl $0x1, (%rbx)
je 0x29e6
leaq 0x66f2(%rip), %rdi      # 0x90d1
xorl %eax, %eax
callq 0x6c80
cmpl $0x0, 0xc(%rbx)
jle 0x2b08
leaq 0x56ca(%rip), %r15      # 0x80c1
leaq 0x6e5f(%rip), %r12      # 0x985d
xorl %r13d, %r13d
movq 0xaa40(%rip), %rdi      # 0xd448
movq 0xaa41(%rip), %rsi      # 0xd450
movl 0x8(%rbx), %edx
movq %r15, %rcx
callq 0x7890
movl %eax, %ecx
movl %eax, (%r14,%r13,4)
movl %r13d, %eax
subl 0xaa37(%rip), %eax      # 0xd460
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movl 0xaa32(%rip), %esi      # 0xd468
movl 0xaa3c(%rip), %eax      # 0xd478
addl %r13d, %eax
cltd
idivl %esi
movl %esi, %eax
shrl $0x1f, %eax
addl %esi, %eax
xorps %xmm2, %xmm2
cvtsi2sd %esi, %xmm2
sarl %eax
subl %edx, %esi
cmpl %eax, %edx
cmovll %edx, %esi
imull 0xaa04(%rip), %esi      # 0xd464
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
mulsd 0x65a1(%rip), %xmm2     # 0x9010
divsd %xmm2, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x6599(%rip), %xmm0     # 0x9018
jae 0x2a96
movq 0xa9c8(%rip), %rdi      # 0xd450
movq %r12, %rsi
movl %ecx, %edx
xorl %eax, %eax
callq 0x21d0
jmp 0x2af8
movl 0xc(%rbx), %esi
movq %r14, %rdi
leaq 0x1a1bd(%rip), %rax     # 0x1cc60
callq *(%rax)
movq 0xa9a4(%rip), %rdi      # 0xd450
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd %xmm1, -0x30(%rbp)
movsd 0xa700(%rip), %xmm0     # 0xd1c0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
addl (%r14,%r13,4), %edx
movq %r12, %rsi
xorl %eax, %eax
callq 0x21d0
xorps %xmm0, %xmm0
cvtsi2sdl (%r14,%r13,4), %xmm0
movsd -0x30(%rbp), %xmm1
mulsd 0xa994(%rip), %xmm1     # 0xd480
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, (%r14,%r13,4)
incq %r13
movslq 0xc(%rbx), %rax
cmpq %rax, %r13
jl 0x2a01
movq 0xa939(%rip), %rdi      # 0xd448
callq 0x20c0
movq 0xa935(%rip), %rdi      # 0xd450
callq 0x20c0
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x65fd(%rip), %rdi      # 0x9135
callq 0x2090
leaq 0x6602(%rip), %rdi      # 0x9146
callq 0x2090
leaq 0x661a(%rip), %rdi      # 0x916a
callq 0x2090
leaq 0x6634(%rip), %rdi      # 0x9190
callq 0x2090
movsd 0xa657(%rip), %xmm0     # 0xd1c0
leaq 0x658f(%rip), %rbx      # 0x90ff
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x6635(%rip), %rdi      # 0x91b6
callq 0x2090
leaq 0x6652(%rip), %rdi      # 0x91df
callq 0x2090
movsd 0xa616(%rip), %xmm0     # 0xd1b0
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x665b(%rip), %rdi      # 0x9206
callq 0x2090
leaq 0x666f(%rip), %rdi      # 0x9226
callq 0x2090
movsd 0xa8bc(%rip), %xmm0     # 0xd480
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x667b(%rip), %rdi      # 0x9250
callq 0x2090
movsd 0xa876(%rip), %xmm0     # 0xd458
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x668a(%rip), %rdi      # 0x927d
callq 0x2090
leaq 0x66ab(%rip), %rdi      # 0x92aa
callq 0x2090
movsd 0xa864(%rip), %xmm0     # 0xd470
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x66bc(%rip), %rdi      # 0x92d9
callq 0x2090
movsd 0xa58e(%rip), %xmm0     # 0xd1b8
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x66cc(%rip), %rdi      # 0x9307
callq 0x2090
leaq 0x66e4(%rip), %rdi      # 0x932b
callq 0x2090
jmp 0x2c6a
movq 0xa54b(%rip), %rsi      # 0xd1a0
movq 0xa54c(%rip), %rdx      # 0xd1a8
leaq 0x648d(%rip), %rdi      # 0x90f0
xorl %eax, %eax
callq 0x20f0
xorl %edi, %edi
callq 0x22c0
callq 0x2330
nop