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

    int i,j,channels;
    char *inFile;
    FILE *in,*out;
    RRA *track;

    argIndex = processOptions(argc,argv);

    if (argc-argIndex == 0)
        {
        in = stdin;
        out = stdout;
        inFile = "stdin";
        }
    else if (argc-argIndex == 1)
        {
        in = OpenFile(argv[argIndex],"r");
        out = stdout;
        inFile = argv[argIndex];
        }
    else if (argc-argIndex == 2)
        {
        in = OpenFile(argv[argIndex],"r");
        out = OpenFile(argv[argIndex+1],"w");
        inFile = argv[argIndex];
        }
    else
        {
        printf("usage: rramono [-aNN.N] [-dNN.N] [-l] [-r] "
            "[<input wave> [<output wave>]]\n");
        exit(-1);
        }

    track = newRRAHeader();
    readRRAHeader(in,track,0);

    if (track->channels == 1)
        {
        fprintf(stderr, "%s is already a mono track\n", inFile);
        Channel = -1;
        }

    if (Channel >= track->channels)
        Fatal("mono: bad channel: %d\n",Channel);

    channels = track->channels;
    trackChannel = track->channels;
    track->channels = 1;
    setAttributeRRA(track,"channels","1");

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

    for (i = 0; !feof(in); ++i)
        {
        int total = 0;
        for (j = 0; j < channels; ++j)
            {

            int amp =
                readRRAAmplitude(in,out,track->bitsPerSample,commentHandler);

            if (j == Channel || Channel == -1)
                total += amp;
            }
        fprintf(out,"%d\n",(int)(total * AmpFactor));
        }

    if (i != track->samples)
        fprintf(stderr,"WARNING: %d samples found, %d expected\n",
            i,track->samples);

    fclose(in);
    fclose(out);

    return 0;

    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movl %edi, %ebx
pushq $0x1
popq %r12
movslq %r12d, %r15
cmpl %r12d, %ebx
jle 0x145c
movq (%r14,%r15,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x145c
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x13eb
leaq 0x2(%rsi), %rdi
jmp 0x13f0
movq 0x8(%r14,%r15,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x61, %eax
je 0x1435
cmpl $0x63, %eax
je 0x1428
cmpl $0x74, %eax
je 0x1428
cmpl $0x68, %eax
je 0x1653
cmpl $0x76, %eax
je 0x16df
xorl %r15d, %r15d
leaq 0x2cca(%rip), %rdi      # 0x40e9
xorl %eax, %eax
callq 0x1828
jmp 0x1445
callq 0x1200
movl %eax, 0x5d1d(%rip)      # 0x7150
jmp 0x1442
callq 0x1080
movsd %xmm0, 0x5d16(%rip)     # 0x7158
movb $0x1, %r15b
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
jmp 0x13c3
subl %r12d, %ebx
jne 0x1482
movq 0x5b70(%rip), %rax      # 0x6fd8
movq (%rax), %r14
movq 0x5b5e(%rip), %rax      # 0x6fd0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
leaq 0x2b89(%rip), %r13      # 0x4009
jmp 0x14e1
cmpl $0x2, %ebx
je 0x14b2
cmpl $0x1, %ebx
jne 0x1702
movq %r14, %rbx
movq (%r14,%r15,8), %rdi
leaq 0x3233(%rip), %rsi      # 0x46d1
callq 0x1958
movq %rax, %r14
movq 0x5b23(%rip), %rax      # 0x6fd0
movq (%rax), %rax
jmp 0x14d9
movq %r14, %rbx
movq (%r14,%r15,8), %rdi
leaq 0x3211(%rip), %rsi      # 0x46d1
callq 0x1958
movq %rax, %r14
movq 0x8(%rbx,%r15,8), %rdi
leaq 0x2b3b(%rip), %rsi      # 0x400f
callq 0x1958
movq %rax, -0x30(%rbp)
movq (%rbx,%r15,8), %r13
callq 0x1bb4
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x1f19
movl (%r15), %r12d
cmpl $0x1, %r12d
je 0x160a
movl 0x5c47(%rip), %esi      # 0x7150
cmpl %r12d, %esi
jl 0x151f
leaq 0x2b18(%rip), %rdi      # 0x402d
xorl %eax, %eax
callq 0x1828
movl (%r15), %r12d
movl %r12d, 0x5c2e(%rip)     # 0x7154
movl $0x1, (%r15)
leaq 0x2ce4(%rip), %rsi      # 0x4218
leaq 0x2acc(%rip), %rdx      # 0x4007
movq %r15, %rdi
callq 0x23a3
leaq 0x2afa(%rip), %rdx      # 0x4044
xorl %ebx, %ebx
movq -0x30(%rbp), %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x2928
testl %r12d, %r12d
cmovlel %ebx, %r12d
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x1160
testl %eax, %eax
jne 0x15e0
movl %ebx, -0x34(%rbp)
movq %r14, %r13
xorl %ebx, %ebx
xorl %r14d, %r14d
cmpl %ebx, %r12d
je 0x15b3
movl 0x8(%r15), %edx
movq %r13, %rdi
movq -0x30(%rbp), %rsi
leaq 0x185(%rip), %rcx       # 0x1716
callq 0x23ee
movl 0x5bb4(%rip), %ecx      # 0x7150
cmpl $-0x1, %ecx
movl $0x0, %edx
cmovel %eax, %edx
cmpl %ecx, %ebx
cmovel %eax, %edx
addl %edx, %r14d
incl %ebx
jmp 0x157a
cvtsi2sd %r14d, %xmm0
mulsd 0x5b98(%rip), %xmm0     # 0x7158
cvttsd2si %xmm0, %edx
movq -0x30(%rbp), %rdi
leaq 0x2dae(%rip), %rsi      # 0x437d
xorl %eax, %eax
callq 0x1140
movl -0x34(%rbp), %ebx
incl %ebx
movq %r13, %r14
jmp 0x1563
movl 0xc(%r15), %ecx
cmpl %ecx, %ebx
jne 0x1637
movq %r14, %rdi
callq 0x1090
movq -0x30(%rbp), %rdi
callq 0x1090
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x59e7(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x29f6(%rip), %rsi      # 0x4011
movq %r13, %rdx
xorl %eax, %eax
callq 0x1140
orl $-0x1, 0x5b24(%rip)     # 0x7150
movl (%r15), %r12d
pushq $-0x1
popq %rsi
jmp 0x1509
movq 0x59ba(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2a0d(%rip), %rsi      # 0x4055
movl %ebx, %edx
xorl %eax, %eax
callq 0x1140
jmp 0x15e8
leaq 0x2af3(%rip), %rdi      # 0x414d
callq 0x1070
leaq 0x2af5(%rip), %rdi      # 0x415b
callq 0x1070
leaq 0x2b0c(%rip), %rdi      # 0x417e
callq 0x1070
leaq 0x2b26(%rip), %rdi      # 0x41a4
callq 0x1070
movsd 0x5acd(%rip), %xmm0     # 0x7158
leaq 0x2a27(%rip), %rdi      # 0x40b9
movb $0x1, %al
callq 0x10b0
leaq 0x2b2a(%rip), %rdi      # 0x41ca
callq 0x1070
leaq 0x2b42(%rip), %rdi      # 0x41ee
callq 0x1070
movl 0x5a99(%rip), %esi      # 0x7150
leaq 0x2a13(%rip), %rdi      # 0x40d1
xorl %eax, %eax
callq 0x10b0
leaq 0x2b55(%rip), %rdi      # 0x4221
callq 0x1070
leaq 0x2b5d(%rip), %rdi      # 0x4235
callq 0x1070
jmp 0x16fb
movq 0x5a5a(%rip), %rsi      # 0x7140
movq 0x5a5b(%rip), %rdx      # 0x7148
leaq 0x29b6(%rip), %rdi      # 0x40aa
xorl %eax, %eax
callq 0x10b0
xorl %edi, %edi
callq 0x1210
leaq 0x29fa(%rip), %rdi      # 0x4103
callq 0x1070
pushq $-0x1
popq %rdi
callq 0x1210