// File: /workspace/github_c_makefile_star2_O3/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 0x16e3
movl $0x1, %ebx
movabsq $0x3ff0000000000000, %r12 # imm = 0x3FF0000000000000
movslq %ebx, %rax
movq -0x38(%rbp), %rcx
movq (%rcx,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x16e3
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x1614
leaq 0x2(%rsi), %rdi
jmp 0x161d
movq -0x38(%rbp), %rcx
movq 0x8(%rcx,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x67, %eax
jg 0x165a
cmpl $0x4c, %eax
je 0x1683
cmpl $0x52, %eax
je 0x1692
cmpl $0x63, %eax
jne 0x16d0
xorl %r15d, %r15d
movl %r15d, 0x5b29(%rip)     # 0x716c
movq %r12, 0x5afe(%rip)      # 0x7148
movl %r15d, 0x5b1f(%rip)     # 0x7170
movq %r12, 0x5af8(%rip)      # 0x7150
jmp 0x16a2
cmpl $0x71, %eax
jg 0x1671
cmpl $0x6c, %eax
jne 0x16bd
callq 0x11f0
movl %eax, 0x5afd(%rip)      # 0x716c
jmp 0x169f
cmpl $0x72, %eax
jne 0x16c7
callq 0x11f0
movl %eax, 0x5aef(%rip)      # 0x7170
jmp 0x169f
callq 0x1080
movsd %xmm0, 0x5ab8(%rip)     # 0x7148
jmp 0x169f
callq 0x1080
movsd %xmm0, 0x5ab1(%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 0x15f1
jmp 0x16e3
cmpl $0x68, %eax
jne 0x16d0
jmp 0x19d5
cmpl $0x76, %eax
je 0x19b4
xorl %r15d, %r15d
leaq 0x29e3(%rip), %rdi      # 0x40bd
xorl %eax, %eax
callq 0x1a98
jmp 0x16a2
subl %ebx, %r14d
jne 0x16f4
movq 0x58e9(%rip), %rax      # 0x6fd8
movq (%rax), %r15
jmp 0x171e
cmpl $0x2, %r14d
je 0x172a
cmpl $0x1, %r14d
jne 0x1a82
movslq %ebx, %rax
movq -0x38(%rbp), %rcx
movq (%rcx,%rax,8), %rdi
leaq 0x2fcc(%rip), %rsi      # 0x46e2
callq 0x1b32
movq %rax, %r15
movq 0x58ab(%rip), %rax      # 0x6fd0
movq (%rax), %rax
jmp 0x1755
movslq %ebx, %rbx
movq -0x38(%rbp), %r14
movq (%r14,%rbx,8), %rdi
leaq 0x2fa6(%rip), %rsi      # 0x46e2
callq 0x1b32
movq %rax, %r15
movq 0x8(%r14,%rbx,8), %rdi
leaq 0x28e5(%rip), %rsi      # 0x4035
callq 0x1b32
movq %rax, -0x30(%rbp)
callq 0x1da3
movq %rax, %rbx
xorl %r13d, %r13d
movq %r15, -0x50(%rbp)
movq %r15, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x21c9
movq %rbx, -0x48(%rbp)
cmpl $0x1, (%rbx)
je 0x178c
leaq 0x28b2(%rip), %rdi      # 0x4037
xorl %eax, %eax
callq 0x1a98
movq -0x48(%rbp), %r14
movl $0x2, (%r14)
movl 0x8(%r14), %edi
decl %edi
movsd 0x2863(%rip), %xmm0     # 0x4008
callq 0x1050
movaps %xmm0, -0x70(%rbp)
movl 0x8(%r14), %edi
decl %edi
movsd 0x284c(%rip), %xmm0     # 0x4008
callq 0x1050
movsd %xmm0, -0x40(%rbp)
leaq 0x2887(%rip), %rdx      # 0x4054
movq -0x30(%rbp), %rdi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x2c64
xorps %xmm0, %xmm0
cvtsi2sdl 0x5986(%rip), %xmm0 # 0x716c
cvtsi2sdl 0x4(%r14), %xmm1
divsd 0x281c(%rip), %xmm1     # 0x4010
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ebx
xorps %xmm0, %xmm0
cvtsi2sdl 0x5969(%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 0x1bb7
movq %rax, -0x58(%rbp)
movl 0xc(%r14), %eax
movl %eax, %ecx
movq %r12, -0x90(%rbp)
addl %r12d, %ecx
jle 0x196f
movapd -0x70(%rbp), %xmm0
xorpd 0x27d0(%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 0x18c0
movq -0x48(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0x1674(%rip), %rcx      # 0x2f2f
callq 0x26cc
movq -0x58(%rbp), %rcx
movl %eax, (%rcx,%rbx,4)
xorl %r12d, %r12d
movl $0x0, %r15d
cmpq -0x88(%rbp), %rbx
jl 0x18e1
movq -0x80(%rbp), %rax
movl (%rax,%rbx,4), %r15d
cmpq -0x40(%rbp), %rbx
jl 0x18ef
movq -0x78(%rbp), %rax
movl (%rax,%rbx,4), %r12d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
mulsd 0x5849(%rip), %xmm0     # 0x7148
cvttsd2si %xmm0, %edx
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
mulsd 0x583d(%rip), %xmm0     # 0x7150
cvttsd2si %xmm0, %ecx
movq -0x30(%rbp), %rdi
leaq 0x2745(%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 0x1898
movq -0x50(%rbp), %rdi
callq 0x1090
movq -0x30(%rbp), %rdi
callq 0x1090
movq 0x5670(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
leaq 0x26d5(%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 0x577d(%rip), %rsi      # 0x7138
movq 0x577e(%rip), %rdx      # 0x7140
leaq 0x26b3(%rip), %rdi      # 0x407c
xorl %eax, %eax
callq 0x10b0
jmp 0x1a7b
leaq 0x2742(%rip), %rdi      # 0x411e
callq 0x1070
leaq 0x2746(%rip), %rdi      # 0x412e
callq 0x1070
movl 0x5779(%rip), %esi      # 0x716c
leaq 0x2691(%rip), %rbx      # 0x408b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10b0
leaq 0x275a(%rip), %rdi      # 0x4165
callq 0x1070
movsd 0x5730(%rip), %xmm0     # 0x7148
leaq 0x2685(%rip), %r14      # 0x40a4
movq %r14, %rdi
movb $0x1, %al
callq 0x10b0
leaq 0x276c(%rip), %rdi      # 0x419c
callq 0x1070
movl 0x5735(%rip), %esi      # 0x7170
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10b0
leaq 0x2788(%rip), %rdi      # 0x41d4
callq 0x1070
movsd 0x56f7(%rip), %xmm0     # 0x7150
movq %r14, %rdi
movb $0x1, %al
callq 0x10b0
leaq 0x27a2(%rip), %rdi      # 0x420c
callq 0x1070
leaq 0x27bc(%rip), %rdi      # 0x4232
callq 0x1070
xorl %edi, %edi
callq 0x1200
leaq 0x264e(%rip), %rdi      # 0x40d7
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1200