// File: /workspace/github_c_makefile_star2_O0/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
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x16a0
movl %eax, -0x14(%rbp)
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x0, %eax
jne 0x136f
movq 0x6c83(%rip), %rax      # 0x7fd8
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq 0x6c6d(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x140c
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x1, %eax
jne 0x13a6
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x43e3(%rip), %rsi      # 0x5770
callq 0x1aa0
movq %rax, -0x40(%rbp)
movq 0x6c33(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x140a
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x2, %eax
jne 0x13f0
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x43ac(%rip), %rsi      # 0x5770
callq 0x1aa0
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3cec(%rip), %rsi      # 0x50d1
callq 0x1aa0
movq %rax, -0x48(%rbp)
jmp 0x1408
leaq 0x3cdc(%rip), %rdi      # 0x50d3
movb $0x0, %al
callq 0x1090
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x11d0
jmp 0x140a
jmp 0x140c
callq 0x1f80
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2480
movq -0x50(%rbp), %rax
cmpl $0x1, (%rax)
je 0x143d
leaq 0x3ce5(%rip), %rdi      # 0x511b
movb $0x0, %al
callq 0x1950
movq -0x50(%rbp), %rax
movl $0x2, (%rax)
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
movsd 0x3bb3(%rip), %xmm0     # 0x5010
callq 0x1060
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x28(%rbp)
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
movsd 0x3b7a(%rip), %xmm0     # 0x5010
callq 0x1060
cvttsd2si %xmm0, %eax
subl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq 0x3c84(%rip), %rdx      # 0x5138
xorl %eax, %eax
movl %eax, %ecx
callq 0x3420
cvtsi2sdl 0x6c87(%rip), %xmm0 # 0x814c
movq -0x50(%rbp), %rax
cvtsi2sdl 0x4(%rax), %xmm1
movsd 0x3b32(%rip), %xmm2     # 0x5008
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x1c(%rbp)
cvtsi2sdl 0x6c63(%rip), %xmm0 # 0x8150
movq -0x50(%rbp), %rax
cvtsi2sdl 0x4(%rax), %xmm1
movsd 0x3b0a(%rip), %xmm2     # 0x5008
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jle 0x151d
movl -0x1c(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x1523
movl -0x20(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x50(%rbp), %rax
movl 0xc(%rax), %eax
addl -0x24(%rbp), %eax
cltq
shlq $0x2, %rax
movl %eax, %edi
callq 0x1ba0
movq %rax, -0x38(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x50(%rbp), %rcx
movl 0xc(%rcx), %ecx
addl -0x24(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1656
movl -0x18(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jl 0x1575
movl $0x0, -0x5c(%rbp)
jmp 0x1593
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0x22d5(%rip), %rcx      # 0x3860
callq 0x2bb0
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %edx
movq -0x38(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x15b2
movl $0x0, -0x54(%rbp)
jmp 0x15c5
movq -0x38(%rbp), %rax
movl -0x18(%rbp), %ecx
subl -0x1c(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x15d6
movl $0x0, -0x58(%rbp)
jmp 0x15e9
movq -0x38(%rbp), %rax
movl -0x18(%rbp), %ecx
subl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
cvtsi2sdl -0x54(%rbp), %xmm0
mulsd 0x6b2e(%rip), %xmm0     # 0x8128
cvttsd2si %xmm0, %edx
cvtsi2sdl -0x58(%rbp), %xmm0
mulsd 0x6b25(%rip), %xmm0     # 0x8130
cvttsd2si %xmm0, %ecx
leaq 0x3b35(%rip), %rsi      # 0x514b
movb $0x0, %al
callq 0x1110
movl -0x54(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jg 0x163d
movl -0x54(%rbp), %eax
cmpl -0x28(%rbp), %eax
jl 0x163d
movl -0x58(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jg 0x163d
movl -0x58(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x1646
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1648
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x154b
movq -0x40(%rbp), %rdi
callq 0x1070
movq -0x48(%rbp), %rdi
callq 0x1070
movq 0x6989(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movl -0x30(%rbp), %ecx
leaq 0x3acf(%rip), %rsi      # 0x5152
movb $0x0, %al
callq 0x1110
xorl %eax, %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)