// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %r12
movslq %r12d, %r13
cmpl %r12d, %r14d
jle 0x2507
movq (%rbx,%r13,8), %rdx
cmpb $0x2d, (%rdx)
jne 0x2507
movb 0x2(%rdx), %r15b
testb %r15b, %r15b
je 0x244c
leaq 0x2(%rdx), %rdi
jmp 0x2451
movq 0x8(%rbx,%r13,8), %rdi
movzbl 0x1(%rdx), %eax
leal -0x61(%rax), %ecx
cmpl $0xe, %ecx
ja 0x247c
leaq 0x5bbc(%rip), %rsi      # 0x8020
movslq (%rsi,%rcx,4), %rax
addq %rsi, %rax
jmpq *%rax
callq 0x20a0
movsd %xmm0, 0xad46(%rip)     # 0xd1c0
jmp 0x24ed
cmpl $0x73, %eax
je 0x24e0
cmpl $0x76, %eax
je 0x2891
movq 0xad0f(%rip), %rsi      # 0xd1a0
xorl %r13d, %r13d
leaq 0x5c7c(%rip), %rdi      # 0x8117
xorl %eax, %eax
callq 0x6474
jmp 0x24f0
callq 0x20a0
movsd %xmm0, 0xacff(%rip)     # 0xd1b0
jmp 0x24ed
callq 0x20a0
movsd %xmm0, 0xafb0(%rip)     # 0xd470
jmp 0x24ed
callq 0x20a0
movsd %xmm0, 0xafb1(%rip)     # 0xd480
jmp 0x24ed
callq 0x20a0
movsd %xmm0, 0xaf7a(%rip)     # 0xd458
jmp 0x24ed
callq 0x20a0
movsd %xmm0, 0xaccb(%rip)     # 0xd1b8
movb $0x1, %r13b
testb %r15b, %r15b
sete %al
andb %r13b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
jmp 0x2424
subl %r12d, %r14d
jne 0x2518
movq 0xaac5(%rip), %rax      # 0xcfd8
movq (%rax), %rax
jmp 0x2538
cmpl $0x2, %r14d
je 0x254b
cmpl $0x1, %r14d
jne 0x28b4
movq (%rbx,%r13,8), %rdi
leaq 0x5df6(%rip), %rsi      # 0x8329
callq 0x65a4
movq %rax, 0xaf09(%rip)      # 0xd448
movq 0xaa8a(%rip), %rax      # 0xcfd0
movq (%rax), %rax
jmp 0x2573
movq (%rbx,%r13,8), %rdi
leaq 0x5dd3(%rip), %rsi      # 0x8329
callq 0x65a4
movq %rax, 0xaee6(%rip)      # 0xd448
movq 0x8(%rbx,%r13,8), %rdi
leaq 0x5af3(%rip), %rsi      # 0x8061
callq 0x65a4
movq %rax, 0xaed6(%rip)      # 0xd450
callq 0x28d8
callq 0x6800
movq %rax, %rbx
movq 0xaeba(%rip), %rdi      # 0xd448
movq %rax, %rsi
xorl %edx, %edx
callq 0x6b65
cvtsi2sdl 0x4(%rbx), %xmm0
movsd 0xaeb3(%rip), %xmm1     # 0xd458
mulsd %xmm0, %xmm1
movsd 0x5a57(%rip), %xmm2     # 0x8008
divsd %xmm2, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, 0xaea1(%rip)      # 0xd460
movsd 0xabe9(%rip), %xmm1     # 0xd1b0
mulsd %xmm0, %xmm1
divsd %xmm2, %xmm1
cvttsd2si %xmm1, %eax
divsd 0xabdd(%rip), %xmm0     # 0xd1b8
cvttsd2si %xmm0, %ecx
movl %eax, 0xae7f(%rip)      # 0xd464
movl %ecx, 0xae7d(%rip)      # 0xd468
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
mulsd 0xae75(%rip), %xmm0     # 0xd470
cvttsd2si %xmm0, %eax
cltd
idivl %ecx
movl %edx, 0xae70(%rip)      # 0xd478
movq 0xae41(%rip), %rdi      # 0xd450
leaq 0x5aa7(%rip), %rdx      # 0x80bd
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x7574
movl 0xc(%rbx), %edi
shll $0x2, %edi
callq 0x6629
movq %rax, %r14
cmpl $0x1, (%rbx)
je 0x2641
leaq 0x5a97(%rip), %rdi      # 0x80d1
xorl %eax, %eax
callq 0x6474
leaq 0x51b9(%rip), %r15      # 0x7801
leaq 0x622e(%rip), %r12      # 0x887d
xorl %r13d, %r13d
movslq 0xc(%rbx), %rax
movq 0xadeb(%rip), %rdi      # 0xd448
cmpq %rax, %r13
jge 0x2752
movq 0xade3(%rip), %rsi      # 0xd450
movl 0x8(%rbx), %edx
movq %r15, %rcx
callq 0x703a
movl %eax, %ecx
movl %eax, (%r14,%r13,4)
movl %r13d, %eax
subl 0xadd9(%rip), %eax      # 0xd460
cvtsi2sd %eax, %xmm1
movl 0xadd7(%rip), %esi      # 0xd468
movl 0xade1(%rip), %eax      # 0xd478
addl %r13d, %eax
cltd
idivl %esi
movl %edx, %edi
movl %esi, %eax
cltd
cvtsi2sd %esi, %xmm2
pushq $0x2
popq %r8
idivl %r8d
subl %edi, %esi
cmpl %eax, %edi
cmovll %edi, %esi
imull 0xada9(%rip), %esi      # 0xd464
cvtsi2sd %esi, %xmm0
mulsd 0x5949(%rip), %xmm2     # 0x8010
divsd %xmm2, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x5941(%rip), %xmm0     # 0x8018
jae 0x26ee
movq 0xad70(%rip), %rdi      # 0xd450
movq %r12, %rsi
movl %ecx, %edx
xorl %eax, %eax
callq 0x21d0
jmp 0x274a
movl 0xc(%rbx), %esi
movq %r14, %rdi
leaq 0x1a565(%rip), %rax     # 0x1cc60
callq *(%rax)
movq 0xad4c(%rip), %rdi      # 0xd450
cvtsi2sd %eax, %xmm1
movsd %xmm1, -0x30(%rbp)
movsd 0xaaab(%rip), %xmm0     # 0xd1c0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
addl (%r14,%r13,4), %edx
movq %r12, %rsi
xorl %eax, %eax
callq 0x21d0
cvtsi2sdl (%r14,%r13,4), %xmm0
movsd -0x30(%rbp), %xmm1
mulsd 0xad42(%rip), %xmm1     # 0xd480
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, (%r14,%r13,4)
incq %r13
jmp 0x2652
callq 0x20c0
movq 0xacf2(%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 0x59ba(%rip), %rdi      # 0x8135
callq 0x2090
leaq 0x59bf(%rip), %rdi      # 0x8146
callq 0x2090
leaq 0x59d7(%rip), %rdi      # 0x816a
callq 0x2090
leaq 0x59f1(%rip), %rdi      # 0x8190
callq 0x2090
movsd 0xaa14(%rip), %xmm0     # 0xd1c0
leaq 0x594c(%rip), %rbx      # 0x80ff
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x59f2(%rip), %rdi      # 0x81b6
callq 0x2090
leaq 0x5a0f(%rip), %rdi      # 0x81df
callq 0x2090
movsd 0xa9d3(%rip), %xmm0     # 0xd1b0
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x5a18(%rip), %rdi      # 0x8206
callq 0x2090
leaq 0x5a2c(%rip), %rdi      # 0x8226
callq 0x2090
movsd 0xac79(%rip), %xmm0     # 0xd480
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x5a38(%rip), %rdi      # 0x8250
callq 0x2090
movsd 0xac33(%rip), %xmm0     # 0xd458
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x5a47(%rip), %rdi      # 0x827d
callq 0x2090
leaq 0x5a68(%rip), %rdi      # 0x82aa
callq 0x2090
movsd 0xac21(%rip), %xmm0     # 0xd470
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x5a79(%rip), %rdi      # 0x82d9
callq 0x2090
movsd 0xa94b(%rip), %xmm0     # 0xd1b8
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x5a89(%rip), %rdi      # 0x8307
callq 0x2090
leaq 0x5aa1(%rip), %rdi      # 0x832b
callq 0x2090
jmp 0x28ad
movq 0xa908(%rip), %rsi      # 0xd1a0
movq 0xa909(%rip), %rdx      # 0xd1a8
leaq 0x584a(%rip), %rdi      # 0x80f0
xorl %eax, %eax
callq 0x20f0
xorl %edi, %edi
callq 0x22b0
movq 0xa73d(%rip), %rax      # 0xcff8
movq (%rax), %rcx
leaq 0x579e(%rip), %rdi      # 0x8063
pushq $0x59
popq %rsi
pushq $0x1
popq %rdx
callq 0x22c0
pushq $-0x1
popq %rdi
callq 0x22b0