// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movq %rsi, -0x38(%rbp)
movl %edi, %r14d
movl $0x1, %ebx
cmpl $0x2, %edi
jl 0x16b3
movl $0x1, %ebx
movabsq $0x3ff0000000000000, %r12 # imm = 0x3FF0000000000000
movslq %ebx, %rax
movq -0x38(%rbp), %rcx
movq (%rcx,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x16b3
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x15e4
leaq 0x2(%rsi), %rdi
jmp 0x15ed
movq -0x38(%rbp), %rcx
movq 0x8(%rcx,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x67, %eax
jg 0x162a
cmpl $0x4c, %eax
je 0x1653
cmpl $0x52, %eax
je 0x1662
cmpl $0x63, %eax
jne 0x16a0
xorl %r15d, %r15d
movl %r15d, 0x5b59(%rip)     # 0x716c
movq %r12, 0x5b2e(%rip)      # 0x7148
movl %r15d, 0x5b4f(%rip)     # 0x7170
movq %r12, 0x5b28(%rip)      # 0x7150
jmp 0x1672
cmpl $0x71, %eax
jg 0x1641
cmpl $0x6c, %eax
jne 0x168d
callq 0x11f0
movl %eax, 0x5b2d(%rip)      # 0x716c
jmp 0x166f
cmpl $0x72, %eax
jne 0x1697
callq 0x11f0
movl %eax, 0x5b1f(%rip)      # 0x7170
jmp 0x166f
callq 0x1080
movsd %xmm0, 0x5ae8(%rip)     # 0x7148
jmp 0x166f
callq 0x1080
movsd %xmm0, 0x5ae1(%rip)     # 0x7150
movb $0x1, %r15b
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %ebx
incl %ebx
cmpl %r14d, %ebx
jl 0x15c1
jmp 0x16b3
cmpl $0x68, %eax
jne 0x16a0
jmp 0x19a5
cmpl $0x76, %eax
je 0x1984
xorl %r15d, %r15d
leaq 0x2a13(%rip), %rdi      # 0x40bd
xorl %eax, %eax
callq 0x1a68
jmp 0x1672
subl %ebx, %r14d
jne 0x16c4
movq 0x5919(%rip), %rax      # 0x6fd8
movq (%rax), %r15
jmp 0x16ee
cmpl $0x2, %r14d
je 0x16fa
cmpl $0x1, %r14d
jne 0x1a52
movslq %ebx, %rax
movq -0x38(%rbp), %rcx
movq (%rcx,%rax,8), %rdi
leaq 0x2fff(%rip), %rsi      # 0x46e5
callq 0x1b02
movq %rax, %r15
movq 0x58db(%rip), %rax      # 0x6fd0
movq (%rax), %rax
jmp 0x1725
movslq %ebx, %rbx
movq -0x38(%rbp), %r14
movq (%r14,%rbx,8), %rdi
leaq 0x2fd9(%rip), %rsi      # 0x46e5
callq 0x1b02
movq %rax, %r15
movq 0x8(%r14,%rbx,8), %rdi
leaq 0x2915(%rip), %rsi      # 0x4035
callq 0x1b02
movq %rax, -0x30(%rbp)
callq 0x1d7f
movq %rax, %rbx
xorl %r13d, %r13d
movq %r15, -0x50(%rbp)
movq %r15, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x218c
movq %rbx, -0x48(%rbp)
cmpl $0x1, (%rbx)
je 0x175c
leaq 0x28e2(%rip), %rdi      # 0x4037
xorl %eax, %eax
callq 0x1a68
movq -0x48(%rbp), %r14
movl $0x2, (%r14)
movl 0x8(%r14), %edi
decl %edi
movsd 0x2893(%rip), %xmm0     # 0x4008
callq 0x1050
movaps %xmm0, -0x70(%rbp)
movl 0x8(%r14), %edi
decl %edi
movsd 0x287c(%rip), %xmm0     # 0x4008
callq 0x1050
movsd %xmm0, -0x40(%rbp)
leaq 0x28b7(%rip), %rdx      # 0x4054
movq -0x30(%rbp), %rdi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x2bdd
xorps %xmm0, %xmm0
cvtsi2sdl 0x59b6(%rip), %xmm0 # 0x716c
cvtsi2sdl 0x4(%r14), %xmm1
divsd 0x284c(%rip), %xmm1     # 0x4010
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebx
xorps %xmm0, %xmm0
cvtsi2sdl 0x5999(%rip), %xmm0 # 0x7170
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %r15d
cmpl %r15d, %ebx
movl %r15d, %r12d
cmovgl %ebx, %r12d
movl 0xc(%r14), %edi
addl %r12d, %edi
shll $0x2, %edi
callq 0x1b95
movq %rax, -0x58(%rbp)
movl 0xc(%r14), %eax
movl %eax, %ecx
movq %r12, -0x90(%rbp)
addl %r12d, %ecx
jle 0x193f
movapd -0x70(%rbp), %xmm0
xorpd 0x2800(%rip), %xmm0     # 0x4020
cvttsd2si %xmm0, %ecx
movl %ecx, -0x70(%rbp)
cvttsd2si -0x40(%rbp), %r14d
movslq %r15d, %rsi
movslq %ebx, %rcx
movq %rcx, -0x88(%rbp)
leaq (,%rcx,4), %rcx
movq -0x58(%rbp), %rdx
movq %rdx, %rdi
subq %rcx, %rdi
movq %rdi, -0x80(%rbp)
movq %rsi, -0x40(%rbp)
leaq (,%rsi,4), %rcx
subq %rcx, %rdx
movq %rdx, -0x78(%rbp)
xorl %ebx, %ebx
xorl %r13d, %r13d
movslq %eax, %rcx
movl $0x0, %eax
cmpq %rcx, %rbx
jge 0x1890
movq -0x48(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0x161e(%rip), %rcx      # 0x2ea9
callq 0x2678
movq -0x58(%rbp), %rcx
movl %eax, (%rcx,%rbx,4)
xorl %r12d, %r12d
movl $0x0, %r15d
cmpq -0x88(%rbp), %rbx
jl 0x18b1
movq -0x80(%rbp), %rax
movl (%rax,%rbx,4), %r15d
cmpq -0x40(%rbp), %rbx
jl 0x18bf
movq -0x78(%rbp), %rax
movl (%rax,%rbx,4), %r12d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
mulsd 0x5879(%rip), %xmm0     # 0x7148
cvttsd2si %xmm0, %edx
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
mulsd 0x586d(%rip), %xmm0     # 0x7150
cvttsd2si %xmm0, %ecx
movq -0x30(%rbp), %rdi
leaq 0x2775(%rip), %rsi      # 0x4067
xorl %eax, %eax
callq 0x1140
cmpl %r14d, %r15d
setge %al
movl -0x70(%rbp), %esi
cmpl %esi, %r15d
setl %cl
cmpl %r14d, %r12d
setge %dl
orb %al, %dl
cmpl %esi, %r12d
setl %al
orb %cl, %al
orb %dl, %al
movzbl %al, %eax
addl %eax, %r13d
incq %rbx
movq -0x48(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x90(%rbp), %rcx
addl %eax, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rbx
jl 0x1868
movq -0x50(%rbp), %rdi
callq 0x1090
movq -0x30(%rbp), %rdi
callq 0x1090
movq 0x56a0(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
leaq 0x2705(%rip), %rsi      # 0x406e
movl %r13d, %ecx
xorl %eax, %eax
callq 0x1140
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x57ad(%rip), %rsi      # 0x7138
movq 0x57ae(%rip), %rdx      # 0x7140
leaq 0x26e3(%rip), %rdi      # 0x407c
xorl %eax, %eax
callq 0x10b0
jmp 0x1a4b
leaq 0x2772(%rip), %rdi      # 0x411e
callq 0x1070
leaq 0x2776(%rip), %rdi      # 0x412e
callq 0x1070
movl 0x57a9(%rip), %esi      # 0x716c
leaq 0x26c1(%rip), %rbx      # 0x408b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10b0
leaq 0x278a(%rip), %rdi      # 0x4165
callq 0x1070
movsd 0x5760(%rip), %xmm0     # 0x7148
leaq 0x26b5(%rip), %r14      # 0x40a4
movq %r14, %rdi
movb $0x1, %al
callq 0x10b0
leaq 0x279c(%rip), %rdi      # 0x419c
callq 0x1070
movl 0x5765(%rip), %esi      # 0x7170
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10b0
leaq 0x27b8(%rip), %rdi      # 0x41d4
callq 0x1070
movsd 0x5727(%rip), %xmm0     # 0x7150
movq %r14, %rdi
movb $0x1, %al
callq 0x10b0
leaq 0x27d2(%rip), %rdi      # 0x420c
callq 0x1070
leaq 0x27ec(%rip), %rdi      # 0x4232
callq 0x1070
xorl %edi, %edi
callq 0x1200
leaq 0x267e(%rip), %rdi      # 0x40d7
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1200