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

    int i,leftSamplesDelayed,rightSamplesDelayed,maxDelayed;
    int Min,Max,clips = 0;
    int *data;
    FILE *in,*out;
    RRA *track;

    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
        {
        printf("usage: stereo [-aNN.N] [-dNN.N] [-l] [-r] "
            "[<input rra> [<output rra>]]\n");
        exit(-1);
        }

    track = newRRAHeader();
    readRRAHeader(in,track,0);
    
    if (track->channels != 1)
        Fatal("stereo requires a mono input");

    track->channels = 2;

    Min = (int) -pow(2,track->bitsPerSample-1);
    Max = (int) pow(2,track->bitsPerSample-1) - 1;

    writeRRAHeader(out,track,"modifiedBy: stereo",0);

    leftSamplesDelayed = (int) (LeftDelay * (track->sampleRate / 1000.0));
    rightSamplesDelayed = (int) (RightDelay * (track->sampleRate / 1000.0));
    maxDelayed = leftSamplesDelayed > rightSamplesDelayed?
        leftSamplesDelayed : rightSamplesDelayed;
    data = (int *) New(sizeof(int) * (track->samples + maxDelayed));

    for (i = 0; i < track->samples + maxDelayed; ++i)
        {
        int x,y,z;

        if (i >= track->samples)
            z = 0;
        else
            z = readRRAAmplitude(in,out,track->bitsPerSample,outputComment);

        data[i] = z;

        if (i < leftSamplesDelayed)
            x = 0;
        else
            x = data[i-leftSamplesDelayed];

        if (i < rightSamplesDelayed)
            y = 0;
        else
            y = data[i-rightSamplesDelayed];

        fprintf(out,"%d\n%d\n",
            (int)(x*LeftAttenuation),(int)(y*RightAttenuation));

        if (x > Max || x < Min || y > Max || y < Min)
            ++clips;
        }

    fclose(in);
    fclose(out);

    fprintf(stderr,"%s clips: %d\n",argv[0],clips);
    return 0;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, -0x38(%rbp)
movl %edi, %r14d
pushq $0x1
popq %rbx
movabsq $0x3ff0000000000000, %r12 # imm = 0x3FF0000000000000
movslq %ebx, %r15
cmpl %ebx, %r14d
jle 0x1457
movq -0x38(%rbp), %rax
movq (%rax,%r15,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x1457
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x139d
leaq 0x2(%rsi), %rdi
jmp 0x13a6
movq -0x38(%rbp), %rax
movq 0x8(%rax,%r15,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x4c, %eax
je 0x1416
cmpl $0x52, %eax
je 0x1432
cmpl $0x63, %eax
je 0x13f5
cmpl $0x6c, %eax
je 0x1425
cmpl $0x72, %eax
je 0x13e8
cmpl $0x68, %eax
je 0x16e3
cmpl $0x76, %eax
je 0x178b
xorl %r15d, %r15d
leaq 0x2cde(%rip), %rdi      # 0x40bd
xorl %eax, %eax
callq 0x17c4
jmp 0x1442
callq 0x11f0
movl %eax, 0x5d7d(%rip)      # 0x7170
jmp 0x143f
andl $0x0, 0x5d70(%rip)      # 0x716c
andl $0x0, 0x5d6d(%rip)      # 0x7170
movq %r12, 0x5d3e(%rip)      # 0x7148
movq %r12, 0x5d3f(%rip)      # 0x7150
xorl %r15d, %r15d
jmp 0x1442
callq 0x1080
movsd %xmm0, 0x5d25(%rip)     # 0x7148
jmp 0x143f
callq 0x11f0
movl %eax, 0x5d3c(%rip)      # 0x716c
jmp 0x143f
callq 0x1080
movsd %xmm0, 0x5d11(%rip)     # 0x7150
movb $0x1, %r15b
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %ebx
incl %ebx
jmp 0x1371
subl %ebx, %r14d
jne 0x1468
movq 0x5b75(%rip), %rax      # 0x6fd8
movq (%rax), %r14
jmp 0x148f
cmpl $0x2, %r14d
je 0x149b
cmpl $0x1, %r14d
jne 0x17ae
movq -0x38(%rbp), %rax
movq (%rax,%r15,8), %rdi
leaq 0x325b(%rip), %rsi      # 0x46e2
callq 0x18f4
movq %rax, %r14
movq 0x5b3a(%rip), %rax      # 0x6fd0
movq (%rax), %rax
jmp 0x14c3
movq -0x38(%rbp), %rbx
movq (%rbx,%r15,8), %rdi
leaq 0x3238(%rip), %rsi      # 0x46e2
callq 0x18f4
movq %rax, %r14
movq 0x8(%rbx,%r15,8), %rdi
leaq 0x2b77(%rip), %rsi      # 0x4035
callq 0x18f4
movq %rax, -0x30(%rbp)
callq 0x1b50
movq %rax, %rbx
movq %r14, -0x50(%rbp)
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x1eb5
movq %rbx, -0x40(%rbp)
cmpl $0x1, (%rbx)
je 0x14f7
leaq 0x2b47(%rip), %rdi      # 0x4037
xorl %eax, %eax
callq 0x17c4
movq -0x40(%rbp), %rbx
movl $0x2, (%rbx)
movl 0x8(%rbx), %edi
decl %edi
movsd 0x2afa(%rip), %xmm0     # 0x4008
callq 0x1050
xorpd 0x2b05(%rip), %xmm0     # 0x4020
cvttsd2si %xmm0, %eax
movl %eax, -0x48(%rbp)
movl 0x8(%rbx), %edi
decl %edi
movsd 0x2ad9(%rip), %xmm0     # 0x4008
callq 0x1050
cvttsd2si %xmm0, %eax
movl %eax, -0x44(%rbp)
leaq 0x2b12(%rip), %rdx      # 0x4054
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x28c4
cvtsi2sdl 0x5c14(%rip), %xmm0 # 0x716c
cvtsi2sdl 0x4(%rbx), %xmm1
divsd 0x2aab(%rip), %xmm1     # 0x4010
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %r14d
cvtsi2sdl 0x5bfa(%rip), %xmm0 # 0x7170
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %r15d
cmpl %r15d, %r14d
movl %r15d, %r12d
cmovgl %r14d, %r12d
movl 0xc(%rbx), %edi
addl %r12d, %edi
shll $0x2, %edi
callq 0x1979
movq %rax, %rbx
movslq %r15d, %rax
movslq %r14d, %rcx
movq %rax, -0x70(%rbp)
leaq (,%rax,4), %rax
negq %rax
movq %rax, -0x60(%rbp)
movq %rcx, -0x68(%rbp)
leaq (,%rcx,4), %rax
negq %rax
movq %rax, -0x58(%rbp)
movslq %r12d, %rax
movq %rax, -0x78(%rbp)
xorl %r12d, %r12d
xorl %r13d, %r13d
jmp 0x1686
xorl %r14d, %r14d
movl $0x0, %eax
cmpq %rcx, %r12
jge 0x1600
movq -0x40(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0x1556(%rip), %rcx      # 0x2b51
callq 0x238a
movl %eax, (%rbx)
cmpq -0x68(%rbp), %r12
jl 0x1610
movq -0x58(%rbp), %rax
movl (%rbx,%rax), %r14d
xorl %r15d, %r15d
cmpq -0x70(%rbp), %r12
jl 0x1621
movq -0x60(%rbp), %rax
movl (%rbx,%rax), %r15d
cvtsi2sd %r14d, %xmm0
mulsd 0x5b1a(%rip), %xmm0     # 0x7148
cvttsd2si %xmm0, %edx
cvtsi2sd %r15d, %xmm0
mulsd 0x5b11(%rip), %xmm0     # 0x7150
cvttsd2si %xmm0, %ecx
movq -0x30(%rbp), %rdi
leaq 0x2a19(%rip), %rsi      # 0x4067
xorl %eax, %eax
callq 0x1140
movl -0x44(%rbp), %edx
cmpl %edx, %r14d
setge %al
movl -0x48(%rbp), %esi
cmpl %esi, %r14d
setl %cl
cmpl %edx, %r15d
setge %dl
orb %al, %dl
cmpl %esi, %r15d
setl %al
orb %cl, %al
orb %dl, %al
movzbl %al, %eax
addl %eax, %r13d
incq %r12
addq $0x4, %rbx
movq -0x40(%rbp), %rax
movslq 0xc(%rax), %rcx
movq -0x78(%rbp), %rax
addq %rcx, %rax
cmpq %rax, %r12
jl 0x15d8
movq -0x50(%rbp), %rdi
callq 0x1090
movq -0x30(%rbp), %rdi
callq 0x1090
movq 0x5941(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
leaq 0x29a6(%rip), %rsi      # 0x406e
movl %r13d, %ecx
xorl %eax, %eax
callq 0x1140
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2a34(%rip), %rdi      # 0x411e
callq 0x1070
leaq 0x2a38(%rip), %rdi      # 0x412e
callq 0x1070
movl 0x5a6b(%rip), %esi      # 0x716c
leaq 0x2983(%rip), %rbx      # 0x408b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10b0
leaq 0x2a4c(%rip), %rdi      # 0x4165
callq 0x1070
movsd 0x5a22(%rip), %xmm0     # 0x7148
leaq 0x2977(%rip), %r14      # 0x40a4
movq %r14, %rdi
movb $0x1, %al
callq 0x10b0
leaq 0x2a5e(%rip), %rdi      # 0x419c
callq 0x1070
movl 0x5a27(%rip), %esi      # 0x7170
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10b0
leaq 0x2a7a(%rip), %rdi      # 0x41d4
callq 0x1070
movsd 0x59e9(%rip), %xmm0     # 0x7150
movq %r14, %rdi
movb $0x1, %al
callq 0x10b0
leaq 0x2a94(%rip), %rdi      # 0x420c
callq 0x1070
leaq 0x2aae(%rip), %rdi      # 0x4232
callq 0x1070
jmp 0x17a7
movq 0x59a6(%rip), %rsi      # 0x7138
movq 0x59a7(%rip), %rdx      # 0x7140
leaq 0x28dc(%rip), %rdi      # 0x407c
xorl %eax, %eax
callq 0x10b0
xorl %edi, %edi
callq 0x1200
leaq 0x2922(%rip), %rdi      # 0x40d7
callq 0x1070
pushq $-0x1
popq %rdi
callq 0x1200
nop