// File: /workspace/github_c_makefile_star2_O3/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, %r15
movl %edi, %ebx
movl $0x1, %r12d
cmpl $0x2, %edi
jl 0x1791
movl $0x1, %r12d
movslq %r12d, %rax
movq (%r15,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x1791
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x1715
leaq 0x2(%rsi), %rdi
jmp 0x171a
movq 0x8(%r15,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x67, %eax
jg 0x172f
cmpl $0x61, %eax
je 0x1741
cmpl $0x63, %eax
je 0x1734
jmp 0x1765
cmpl $0x74, %eax
jne 0x1753
callq 0x1200
movl %eax, 0x5a11(%rip)      # 0x7150
jmp 0x174e
callq 0x1080
movsd %xmm0, 0x5a0a(%rip)     # 0x7158
movb $0x1, %r14b
jmp 0x1776
cmpl $0x68, %eax
je 0x19e6
cmpl $0x76, %eax
je 0x19c5
xorl %r14d, %r14d
leaq 0x297a(%rip), %rdi      # 0x40e9
xorl %eax, %eax
callq 0x1afc
testb %r13b, %r13b
sete %al
andb %r14b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
cmpl %ebx, %r12d
jl 0x16f6
subl %r12d, %ebx
jne 0x17b3
movq 0x583b(%rip), %rax      # 0x6fd8
movq (%rax), %r14
movq 0x5829(%rip), %rax      # 0x6fd0
movq (%rax), %rbx
leaq 0x2858(%rip), %r13      # 0x4009
jmp 0x1811
cmpl $0x2, %ebx
je 0x17e3
cmpl $0x1, %ebx
jne 0x1a77
movslq %r12d, %rbx
movq (%r15,%rbx,8), %rdi
leaq 0x2f02(%rip), %rsi      # 0x46d1
callq 0x1b96
movq %rax, %r14
movq 0x57f2(%rip), %rax      # 0x6fd0
movq (%rax), %rax
jmp 0x180a
movslq %r12d, %rbx
movq (%r15,%rbx,8), %rdi
leaq 0x2ee0(%rip), %rsi      # 0x46d1
callq 0x1b96
movq %rax, %r14
movq 0x8(%r15,%rbx,8), %rdi
leaq 0x280a(%rip), %rsi      # 0x400f
callq 0x1b96
movq (%r15,%rbx,8), %r13
movq %rax, %rbx
callq 0x1e07
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x222d
movl (%r15), %r12d
cmpl $0x1, %r12d
movq %r15, -0x30(%rbp)
je 0x1972
movl 0x5913(%rip), %esi      # 0x7150
cmpl %r12d, %esi
jl 0x1857
leaq 0x27e4(%rip), %rdi      # 0x402d
xorl %eax, %eax
callq 0x1afc
movq -0x30(%rbp), %r15
movl (%r15), %r12d
movl %r12d, 0x58f6(%rip)     # 0x7154
movl $0x1, (%r15)
leaq 0x29ac(%rip), %rsi      # 0x4218
leaq 0x2794(%rip), %rdx      # 0x4007
movq %r15, %rdi
callq 0x26de
leaq 0x27c2(%rip), %rdx      # 0x4044
xorl %r13d, %r13d
movq %rbx, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x2cc8
movq %r14, %rdi
callq 0x1160
testl %eax, %eax
jne 0x1945
xorl %r13d, %r13d
movq %rbx, -0x38(%rbp)
testl %r12d, %r12d
jle 0x1911
movq %r13, -0x40(%rbp)
xorl %ebx, %ebx
movq %r14, %r13
xorl %r14d, %r14d
movl %r12d, %r15d
movq -0x30(%rbp), %r12
movl 0x8(%r12), %edx
movq %r13, %rdi
movq -0x38(%rbp), %rsi
leaq 0x1b9(%rip), %rcx       # 0x1a8d
callq 0x2730
movl 0x5871(%rip), %ecx      # 0x7150
cmpl $-0x1, %ecx
movl $0x0, %edx
cmovel %eax, %edx
cmpl %ecx, %r14d
cmovel %eax, %edx
addl %edx, %ebx
incl %r14d
cmpl %r14d, %r15d
jne 0x18c1
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movq %r13, %r14
movq -0x38(%rbp), %rbx
movl %r15d, %r12d
movq -0x40(%rbp), %r13
jmp 0x1915
xorpd %xmm0, %xmm0
mulsd 0x583b(%rip), %xmm0     # 0x7158
cvttsd2si %xmm0, %edx
movq %rbx, %rdi
leaq 0x2a52(%rip), %rsi      # 0x437d
xorl %eax, %eax
callq 0x1140
incl %r13d
movq %r14, %rdi
callq 0x1160
testl %eax, %eax
je 0x18a9
movq -0x30(%rbp), %rax
movl 0xc(%rax), %ecx
cmpl %ecx, %r13d
jne 0x19a8
movq %r14, %rdi
callq 0x1090
movq %rbx, %rdi
callq 0x1090
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x567f(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x268e(%rip), %rsi      # 0x4011
movq %r13, %rdx
xorl %eax, %eax
callq 0x1140
movq -0x30(%rbp), %r15
movl $0xffffffff, 0x57b5(%rip) # imm = 0xFFFFFFFF
movl (%r15), %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
jmp 0x183d
movq 0x5649(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x269c(%rip), %rsi      # 0x4055
movl %r13d, %edx
xorl %eax, %eax
callq 0x1140
jmp 0x1951
movq 0x5774(%rip), %rsi      # 0x7140
movq 0x5775(%rip), %rdx      # 0x7148
leaq 0x26d0(%rip), %rdi      # 0x40aa
xorl %eax, %eax
callq 0x10b0
jmp 0x1a70
leaq 0x2760(%rip), %rdi      # 0x414d
callq 0x1070
leaq 0x2762(%rip), %rdi      # 0x415b
callq 0x1070
leaq 0x2779(%rip), %rdi      # 0x417e
callq 0x1070
leaq 0x2793(%rip), %rdi      # 0x41a4
callq 0x1070
movsd 0x573a(%rip), %xmm0     # 0x7158
leaq 0x2694(%rip), %rdi      # 0x40b9
movb $0x1, %al
callq 0x10b0
leaq 0x2797(%rip), %rdi      # 0x41ca
callq 0x1070
leaq 0x27af(%rip), %rdi      # 0x41ee
callq 0x1070
movl 0x5706(%rip), %esi      # 0x7150
leaq 0x2680(%rip), %rdi      # 0x40d1
xorl %eax, %eax
callq 0x10b0
leaq 0x27c2(%rip), %rdi      # 0x4221
callq 0x1070
leaq 0x27ca(%rip), %rdi      # 0x4235
callq 0x1070
xorl %edi, %edi
callq 0x1210
leaq 0x2685(%rip), %rdi      # 0x4103
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1210