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

    int i,j;
    int count;
    int amp;
    FILE *in,*out;
    int shift[512];
    RRA *h;

    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: dcshift -aN [<input rra file> [<output rra file>]]\n");
        exit(-1);
        }

    h = newRRAHeader();
    
    readRRAHeader(in,h,0);
    writeRRAHeader(out,h,"modifiedBy: amp",0);

    for (i = 0; i < h->channels; ++i)
        shift[i] = 0;

    count = 0;
    for (i = 0; !feof(in); ++i)
        for (j = 0; j < h->channels; ++j)
            {
            amp = readRRAAmplitude(in,out,h->bitsPerSample,commentHandler);
            if (i == 0) shift[j] = -amp;
            fprintf(out,"%d\n",(int) ((amp + shift[j]) * attenuation));
            ++count;
            }

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

    fclose(in);
    fclose(out);

    return 0;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x808, %rsp            # imm = 0x808
movq %rsi, %r14
movl %edi, %ebx
movl $0x1, %r12d
cmpl $0x2, %edi
jl 0x1751
movl $0x1, %r12d
movslq %r12d, %rax
movq (%r14,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x1751
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x1700
leaq 0x2(%rsi), %rdi
jmp 0x1705
movq 0x8(%r14,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x61, %eax
je 0x172a
cmpl $0x76, %eax
je 0x18e1
xorl %r15d, %r15d
leaq 0x2939(%rip), %rdi      # 0x405a
xorl %eax, %eax
callq 0x198c
jmp 0x173a
callq 0x1080
movsd %xmm0, 0x5a19(%rip)     # 0x7150
movb $0x1, %r15b
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
cmpl %ebx, %r12d
jl 0x16e5
subl %r12d, %ebx
jne 0x1762
movq 0x587b(%rip), %rax      # 0x6fd8
movq (%rax), %rbx
jmp 0x1786
cmpl $0x2, %ebx
je 0x1792
cmpl $0x1, %ebx
jne 0x1904
movslq %r12d, %rax
movq (%r14,%rax,8), %rdi
leaq 0x2dbc(%rip), %rsi      # 0x453a
callq 0x1a26
movq %rax, %rbx
movq 0x5843(%rip), %rax      # 0x6fd0
movq (%rax), %r14
jmp 0x17bc
movslq %r12d, %r15
movq (%r14,%r15,8), %rdi
leaq 0x2d9a(%rip), %rsi      # 0x453a
callq 0x1a26
movq %rax, %rbx
movq 0x8(%r14,%r15,8), %rdi
leaq 0x285d(%rip), %rsi      # 0x4011
callq 0x1a26
movq %rax, %r14
callq 0x1c97
movq %rax, %r12
xorl %r15d, %r15d
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x20bd
leaq 0x2838(%rip), %rdx      # 0x4013
movq %r14, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x2b58
movslq (%r12), %rdx
testq %rdx, %rdx
jle 0x1803
shlq $0x2, %rdx
leaq -0x830(%rbp), %rdi
xorl %esi, %esi
callq 0x10d0
movq %rbx, %rdi
callq 0x1160
testl %eax, %eax
jne 0x1893
xorl %r15d, %r15d
cmpl $0x0, (%r12)
jle 0x1884
xorl %r13d, %r13d
movl 0x8(%r12), %edx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0xe8(%rip), %rcx        # 0x191a
callq 0x25c0
testl %r15d, %r15d
je 0x1846
movl -0x830(%rbp,%r13,4), %ecx
jmp 0x1852
movl %eax, %ecx
negl %ecx
movl %ecx, -0x830(%rbp,%r13,4)
addl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd 0x58ed(%rip), %xmm0     # 0x7150
cvttsd2si %xmm0, %edx
movq %r14, %rdi
leaq 0x296c(%rip), %rsi      # 0x41dd
xorl %eax, %eax
callq 0x1140
incq %r13
movslq (%r12), %rax
cmpq %rax, %r13
jl 0x1820
incl %r15d
movq %rbx, %rdi
callq 0x1160
testl %eax, %eax
je 0x1816
movl 0xc(%r12), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r15d
jne 0x18c4
movq %rbx, %rdi
callq 0x1090
movq %r14, %rdi
callq 0x1090
xorl %eax, %eax
addq $0x808, %rsp            # imm = 0x808
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x572d(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x274e(%rip), %rsi      # 0x4023
movl %r15d, %edx
xorl %eax, %eax
callq 0x1140
jmp 0x18a0
movq 0x5858(%rip), %rsi      # 0x7140
movq 0x5859(%rip), %rdx      # 0x7148
leaq 0x2755(%rip), %rdi      # 0x404b
xorl %eax, %eax
callq 0x10b0
xorl %edi, %edi
callq 0x1210
leaq 0x2769(%rip), %rdi      # 0x4074
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1210