// File: /workspace/github_c_makefile_star2_O3/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 0x2893
movl $0x1, %r12d
movslq %r12d, %rax
movq (%rbx,%rax,8), %rdx
cmpb $0x2d, (%rdx)
jne 0x2893
movb 0x2(%rdx), %r15b
testb %r15b, %r15b
je 0x27d4
leaq 0x2(%rdx), %rdi
jmp 0x27d9
movq 0x8(%rbx,%rax,8), %rdi
movzbl 0x1(%rdx), %eax
leal -0x61(%rax), %ecx
cmpl $0xe, %ecx
ja 0x2804
leaq 0x6834(%rip), %rsi      # 0x9020
movslq (%rsi,%rcx,4), %rax
addq %rsi, %rax
jmpq *%rax
callq 0x20a0
movsd %xmm0, 0xa9be(%rip)     # 0xd1c0
jmp 0x2875
cmpl $0x73, %eax
je 0x2868
cmpl $0x76, %eax
je 0x2c3e
movq 0xa987(%rip), %rsi      # 0xd1a0
xorl %r13d, %r13d
leaq 0x68f4(%rip), %rdi      # 0x9117
xorl %eax, %eax
callq 0x6dc8
jmp 0x2878
callq 0x20a0
movsd %xmm0, 0xa977(%rip)     # 0xd1b0
jmp 0x2875
callq 0x20a0
movsd %xmm0, 0xac28(%rip)     # 0xd470
jmp 0x2875
callq 0x20a0
movsd %xmm0, 0xac29(%rip)     # 0xd480
jmp 0x2875
callq 0x20a0
movsd %xmm0, 0xabf2(%rip)     # 0xd458
jmp 0x2875
callq 0x20a0
movsd %xmm0, 0xa943(%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 0x27b5
subl %r12d, %r14d
jne 0x28a4
movq 0xa739(%rip), %rax      # 0xcfd8
movq (%rax), %rax
jmp 0x28c7
cmpl $0x2, %r14d
je 0x28da
cmpl $0x1, %r14d
jne 0x2c61
movslq %r12d, %rax
movq (%rbx,%rax,8), %rdi
leaq 0x6a67(%rip), %rsi      # 0x9329
callq 0x6e62
movq %rax, 0xab7a(%rip)      # 0xd448
movq 0xa6fb(%rip), %rax      # 0xcfd0
movq (%rax), %rax
jmp 0x2905
movslq %r12d, %r14
movq (%rbx,%r14,8), %rdi
leaq 0x6a41(%rip), %rsi      # 0x9329
callq 0x6e62
movq %rax, 0xab54(%rip)      # 0xd448
movq 0x8(%rbx,%r14,8), %rdi
leaq 0x6761(%rip), %rsi      # 0x9061
callq 0x6e62
movq %rax, 0xab44(%rip)      # 0xd450
callq 0x2c68
callq 0x70d3
movq %rax, %rbx
movq 0xab28(%rip), %rdi      # 0xd448
movq %rax, %rsi
xorl %edx, %edx
callq 0x74f9
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%rbx), %xmm0
movsd 0xab1e(%rip), %xmm1     # 0xd458
mulsd %xmm0, %xmm1
movsd 0x66c2(%rip), %xmm2     # 0x9008
divsd %xmm2, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, 0xab0c(%rip)      # 0xd460
movsd 0xa854(%rip), %xmm1     # 0xd1b0
mulsd %xmm0, %xmm1
divsd %xmm2, %xmm1
cvttsd2si %xmm1, %eax
divsd 0xa848(%rip), %xmm0     # 0xd1b8
cvttsd2si %xmm0, %ecx
movl %eax, 0xaaea(%rip)      # 0xd464
movl %ecx, 0xaae8(%rip)      # 0xd468
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
mulsd 0xaae0(%rip), %xmm0     # 0xd470
cvttsd2si %xmm0, %eax
cltd
idivl %ecx
movl %edx, 0xaadb(%rip)      # 0xd478
movq 0xaaac(%rip), %rdi      # 0xd450
leaq 0x6712(%rip), %rdx      # 0x90bd
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x7f94
movl 0xc(%rbx), %edi
shll $0x2, %edi
callq 0x6ee7
movq %rax, %r14
cmpl $0x1, (%rbx)
je 0x29d6
leaq 0x6702(%rip), %rdi      # 0x90d1
xorl %eax, %eax
callq 0x6dc8
cmpl $0x0, 0xc(%rbx)
jle 0x2af8
leaq 0x5878(%rip), %r15      # 0x825f
leaq 0x6eaf(%rip), %r12      # 0x989d
xorl %r13d, %r13d
movq 0xaa50(%rip), %rdi      # 0xd448
movq 0xaa51(%rip), %rsi      # 0xd450
movl 0x8(%rbx), %edx
movq %r15, %rcx
callq 0x79fc
movl %eax, %ecx
movl %eax, (%r14,%r13,4)
movl %r13d, %eax
subl 0xaa47(%rip), %eax      # 0xd460
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movl 0xaa42(%rip), %esi      # 0xd468
movl 0xaa4c(%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 0xaa14(%rip), %esi      # 0xd464
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
mulsd 0x65b1(%rip), %xmm2     # 0x9010
divsd %xmm2, %xmm0
addsd %xmm1, %xmm0
ucomisd 0x65a9(%rip), %xmm0     # 0x9018
jae 0x2a86
movq 0xa9d8(%rip), %rdi      # 0xd450
movq %r12, %rsi
movl %ecx, %edx
xorl %eax, %eax
callq 0x21d0
jmp 0x2ae8
movl 0xc(%rbx), %esi
movq %r14, %rdi
leaq 0x1a1cd(%rip), %rax     # 0x1cc60
callq *(%rax)
movq 0xa9b4(%rip), %rdi      # 0xd450
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd %xmm1, -0x30(%rbp)
movsd 0xa710(%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 0xa9a4(%rip), %xmm1     # 0xd480
addsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movl %eax, (%r14,%r13,4)
incq %r13
movslq 0xc(%rbx), %rax
cmpq %rax, %r13
jl 0x29f1
movq 0xa949(%rip), %rdi      # 0xd448
callq 0x20c0
movq 0xa945(%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 0x660d(%rip), %rdi      # 0x9135
callq 0x2090
leaq 0x6612(%rip), %rdi      # 0x9146
callq 0x2090
leaq 0x662a(%rip), %rdi      # 0x916a
callq 0x2090
leaq 0x6644(%rip), %rdi      # 0x9190
callq 0x2090
movsd 0xa667(%rip), %xmm0     # 0xd1c0
leaq 0x659f(%rip), %rbx      # 0x90ff
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x6645(%rip), %rdi      # 0x91b6
callq 0x2090
leaq 0x6662(%rip), %rdi      # 0x91df
callq 0x2090
movsd 0xa626(%rip), %xmm0     # 0xd1b0
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x666b(%rip), %rdi      # 0x9206
callq 0x2090
leaq 0x667f(%rip), %rdi      # 0x9226
callq 0x2090
movsd 0xa8cc(%rip), %xmm0     # 0xd480
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x668b(%rip), %rdi      # 0x9250
callq 0x2090
movsd 0xa886(%rip), %xmm0     # 0xd458
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x669a(%rip), %rdi      # 0x927d
callq 0x2090
leaq 0x66bb(%rip), %rdi      # 0x92aa
callq 0x2090
movsd 0xa874(%rip), %xmm0     # 0xd470
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x66cc(%rip), %rdi      # 0x92d9
callq 0x2090
movsd 0xa59e(%rip), %xmm0     # 0xd1b8
movq %rbx, %rdi
movb $0x1, %al
callq 0x20f0
leaq 0x66dc(%rip), %rdi      # 0x9307
callq 0x2090
leaq 0x66f4(%rip), %rdi      # 0x932b
callq 0x2090
jmp 0x2c5a
movq 0xa55b(%rip), %rsi      # 0xd1a0
movq 0xa55c(%rip), %rdx      # 0xd1a8
leaq 0x649d(%rip), %rdi      # 0x90f0
xorl %eax, %eax
callq 0x20f0
xorl %edi, %edi
callq 0x22c0
callq 0x2330
nop