// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x2790
movl %eax, -0x14(%rbp)
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x0, %eax
jne 0x241e
movq 0xebda(%rip), %rax      # 0x10fd8
movq (%rax), %rax
movq %rax, 0xf010(%rip)      # 0x11418
movq 0xebc1(%rip), %rax      # 0x10fd0
movq (%rax), %rax
movq %rax, 0xf007(%rip)      # 0x11420
jmp 0x24d1
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x1, %eax
jne 0x245b
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x9caf(%rip), %rsi      # 0xc0eb
callq 0x8e80
movq %rax, 0xefd0(%rip)      # 0x11418
movq 0xeb81(%rip), %rax      # 0x10fd0
movq (%rax), %rax
movq %rax, 0xefc7(%rip)      # 0x11420
jmp 0x24cf
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x2, %eax
jne 0x24ab
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x9c72(%rip), %rsi      # 0xc0eb
callq 0x8e80
movq %rax, 0xef93(%rip)      # 0x11418
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x9be0(%rip), %rsi      # 0xc07d
callq 0x8e80
movq %rax, 0xef77(%rip)      # 0x11420
jmp 0x24cd
movq 0xeb46(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x9bc3(%rip), %rsi      # 0xc07f
movb $0x0, %al
callq 0x2190
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2270
jmp 0x24cf
jmp 0x24d1
callq 0x2b60
callq 0x9360
movq %rax, -0x28(%rbp)
movq 0xef32(%rip), %rdi      # 0x11418
movq -0x28(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x9860
movq -0x28(%rbp), %rax
cvtsi2sdl 0x4(%rax), %xmm0
mulsd 0xef24(%rip), %xmm0     # 0x11428
movsd 0x9afc(%rip), %xmm1     # 0xc008
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0xef16(%rip)      # 0x11430
movq -0x28(%rbp), %rax
cvtsi2sdl 0x4(%rax), %xmm0
mulsd 0xec55(%rip), %xmm0     # 0x11180
movsd 0x9ad5(%rip), %xmm1     # 0xc008
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0xeef3(%rip)      # 0x11434
movq -0x28(%rbp), %rax
cvtsi2sdl 0x4(%rax), %xmm0
divsd 0xec36(%rip), %xmm0     # 0x11188
cvttsd2si %xmm0, %eax
movl %eax, 0xeedc(%rip)      # 0x11438
movsd 0xeedc(%rip), %xmm0     # 0x11440
cvtsi2sdl 0xeecc(%rip), %xmm1 # 0x11438
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
cltd
idivl 0xeebd(%rip)            # 0x11438
movl %edx, 0xeec7(%rip)      # 0x11448
movq 0xee98(%rip), %rdi      # 0x11420
movq -0x28(%rbp), %rsi
leaq 0x9b46(%rip), %rdx      # 0xc0d9
xorl %eax, %eax
movl %eax, %ecx
callq 0xa800
movq -0x28(%rbp), %rax
movslq 0xc(%rax), %rax
shlq $0x2, %rax
movl %eax, %edi
callq 0x8f80
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
je 0x25ca
leaq 0x9b2a(%rip), %rdi      # 0xc0ed
movb $0x0, %al
callq 0x8d30
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x276d
movq 0xee30(%rip), %rdi      # 0x11418
movq 0xee31(%rip), %rsi      # 0x11420
movq -0x28(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0x8643(%rip), %rcx      # 0xac40
callq 0x9f90
movl %eax, %edx
movq -0x20(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
subl 0xee18(%rip), %eax      # 0x11430
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x40(%rbp)
movl 0xee11(%rip), %edi      # 0x11438
movl 0xee07(%rip), %esi      # 0x11434
movl 0xee15(%rip), %edx      # 0x11448
movl -0x18(%rbp), %ecx
callq 0x2ad0
movaps %xmm0, %xmm1
movsd -0x40(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x273d
leaq 0x1e5cb(%rip), %rax     # 0x20c30
movq (%rax), %rax
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rcx
movl 0xc(%rcx), %esi
movsd -0x30(%rbp), %xmm0
callq *%rax
movl %eax, -0x34(%rbp)
movq 0xed9c(%rip), %rdi      # 0x11420
movq -0x20(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movsd 0xeaf9(%rip), %xmm0     # 0x11190
mulsd 0xeaf9(%rip), %xmm0     # 0x11198
cvtsi2sdl -0x34(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
addl %eax, %edx
leaq 0xa1b8(%rip), %rsi      # 0xc86d
movb $0x0, %al
callq 0x2190
movsd 0xed8c(%rip), %xmm0     # 0x11450
addsd 0xeac4(%rip), %xmm0     # 0x11190
movsd %xmm0, 0xeabc(%rip)     # 0x11190
xorps %xmm0, %xmm0
ucomisd 0xeab1(%rip), %xmm0     # 0x11190
jbe 0x26ec
xorps %xmm0, %xmm0
movsd %xmm0, 0xeaa4(%rip)     # 0x11190
movsd 0xea9c(%rip), %xmm0     # 0x11190
movsd 0x9914(%rip), %xmm1     # 0xc010
ucomisd %xmm1, %xmm0
jbe 0x2712
movsd 0x9906(%rip), %xmm0     # 0xc010
movsd %xmm0, 0xea7e(%rip)     # 0x11190
movsd 0xed3e(%rip), %xmm0     # 0x11458
cvtsi2sdl -0x34(%rbp), %xmm2
movq -0x20(%rbp), %rax
movslq -0x18(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x275d
movq 0xecdc(%rip), %rdi      # 0x11420
movq -0x20(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0xa117(%rip), %rsi      # 0xc86d
movb $0x0, %al
callq 0x2190
jmp 0x275f
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x25d1
movq 0xeca4(%rip), %rdi      # 0x11418
callq 0x2090
movq 0xeca0(%rip), %rdi      # 0x11420
callq 0x2090
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)