// File: /workspace/github_c_makefile_star2_O1/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 0x19b3
cmpl $0x76, %eax
je 0x1992
xorl %r14d, %r14d
leaq 0x297a(%rip), %rdi      # 0x40e9
xorl %eax, %eax
callq 0x1acc
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), %r13
leaq 0x2858(%rip), %r12      # 0x4009
jmp 0x1811
cmpl $0x2, %ebx
je 0x17e3
cmpl $0x1, %ebx
jne 0x1a44
movslq %r12d, %rbx
movq (%r15,%rbx,8), %rdi
leaq 0x2f05(%rip), %rsi      # 0x46d4
callq 0x1b66
movq %rax, %r14
movq 0x57f2(%rip), %rax      # 0x6fd0
movq (%rax), %r13
jmp 0x180d
movslq %r12d, %rbx
movq (%r15,%rbx,8), %rdi
leaq 0x2ee3(%rip), %rsi      # 0x46d4
callq 0x1b66
movq %rax, %r14
movq 0x8(%r15,%rbx,8), %rdi
leaq 0x280a(%rip), %rsi      # 0x400f
callq 0x1b66
movq %rax, %r13
movq (%r15,%rbx,8), %r12
callq 0x1de3
movq %rax, %rbx
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x21f0
cmpl $0x1, (%rbx)
je 0x1968
movl 0x591b(%rip), %esi      # 0x7150
cmpl (%rbx), %esi
jl 0x1847
leaq 0x27ed(%rip), %rdi      # 0x402d
xorl %eax, %eax
callq 0x1acc
movl (%rbx), %r15d
movl %r15d, 0x5903(%rip)     # 0x7154
movl $0x1, (%rbx)
leaq 0x29ba(%rip), %rsi      # 0x4218
leaq 0x27a2(%rip), %rdx      # 0x4007
movq %rbx, %rdi
callq 0x268a
leaq 0x27d0(%rip), %rdx      # 0x4044
xorl %r12d, %r12d
movq %r13, %rdi
movq %rbx, -0x38(%rbp)
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x2c41
movq %r14, %rdi
callq 0x1160
testl %eax, %eax
jne 0x193b
xorl %r12d, %r12d
movl %r15d, -0x2c(%rbp)
testl %r15d, %r15d
jle 0x1907
movq %r12, -0x40(%rbp)
xorl %ebx, %ebx
movq %r13, %r15
movq %r14, %r13
xorl %r14d, %r14d
movq -0x38(%rbp), %r12
movl 0x8(%r12), %edx
movq %r13, %rdi
movq %r15, %rsi
leaq 0x191(%rip), %rcx       # 0x1a5a
callq 0x26dc
movl 0x587c(%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, -0x2c(%rbp)
jne 0x18b7
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movq %r13, %r14
movq %r15, %r13
movl -0x2c(%rbp), %r15d
movq -0x40(%rbp), %r12
jmp 0x190b
xorpd %xmm0, %xmm0
mulsd 0x5845(%rip), %xmm0     # 0x7158
cvttsd2si %xmm0, %edx
movq %r13, %rdi
leaq 0x2a5c(%rip), %rsi      # 0x437d
xorl %eax, %eax
callq 0x1140
incl %r12d
movq %r14, %rdi
callq 0x1160
testl %eax, %eax
je 0x189f
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
cmpl %ecx, %r12d
jne 0x1975
movq %r14, %rdi
callq 0x1090
movq %r13, %rdi
callq 0x1090
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
callq 0x1270
jmp 0x182f
movq 0x567c(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x26cf(%rip), %rsi      # 0x4055
movl %r12d, %edx
xorl %eax, %eax
callq 0x1140
jmp 0x1947
movq 0x57a7(%rip), %rsi      # 0x7140
movq 0x57a8(%rip), %rdx      # 0x7148
leaq 0x2703(%rip), %rdi      # 0x40aa
xorl %eax, %eax
callq 0x10b0
jmp 0x1a3d
leaq 0x2793(%rip), %rdi      # 0x414d
callq 0x1070
leaq 0x2795(%rip), %rdi      # 0x415b
callq 0x1070
leaq 0x27ac(%rip), %rdi      # 0x417e
callq 0x1070
leaq 0x27c6(%rip), %rdi      # 0x41a4
callq 0x1070
movsd 0x576d(%rip), %xmm0     # 0x7158
leaq 0x26c7(%rip), %rdi      # 0x40b9
movb $0x1, %al
callq 0x10b0
leaq 0x27ca(%rip), %rdi      # 0x41ca
callq 0x1070
leaq 0x27e2(%rip), %rdi      # 0x41ee
callq 0x1070
movl 0x5739(%rip), %esi      # 0x7150
leaq 0x26b3(%rip), %rdi      # 0x40d1
xorl %eax, %eax
callq 0x10b0
leaq 0x27f5(%rip), %rdi      # 0x4221
callq 0x1070
leaq 0x27fd(%rip), %rdi      # 0x4235
callq 0x1070
xorl %edi, %edi
callq 0x1210
leaq 0x26b8(%rip), %rdi      # 0x4103
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1210