// File: /workspace/github_c_makefile_star2_O1/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 0x1721
movl $0x1, %r12d
movslq %r12d, %rax
movq (%r14,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x1721
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x16d0
leaq 0x2(%rsi), %rdi
jmp 0x16d5
movq 0x8(%r14,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x61, %eax
je 0x16fa
cmpl $0x76, %eax
je 0x18a6
xorl %r15d, %r15d
leaq 0x2969(%rip), %rdi      # 0x405a
xorl %eax, %eax
callq 0x1950
jmp 0x170a
callq 0x1080
movsd %xmm0, 0x5a49(%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 0x16b5
subl %r12d, %ebx
jne 0x1732
movq 0x58ab(%rip), %rax      # 0x6fd8
movq (%rax), %r13
jmp 0x1756
cmpl $0x2, %ebx
je 0x1762
cmpl $0x1, %ebx
jne 0x18c9
movslq %r12d, %rax
movq (%r14,%rax,8), %rdi
leaq 0x2def(%rip), %rsi      # 0x453d
callq 0x19ea
movq %rax, %r13
movq 0x5873(%rip), %rax      # 0x6fd0
movq (%rax), %r14
jmp 0x178c
movslq %r12d, %rbx
movq (%r14,%rbx,8), %rdi
leaq 0x2dcd(%rip), %rsi      # 0x453d
callq 0x19ea
movq %rax, %r13
movq 0x8(%r14,%rbx,8), %rdi
leaq 0x288d(%rip), %rsi      # 0x4011
callq 0x19ea
movq %rax, %r14
callq 0x1c67
movq %rax, %r12
xorl %r15d, %r15d
movq %r13, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x2074
leaq 0x2868(%rip), %rdx      # 0x4013
movq %r14, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x2ac5
movslq (%r12), %rdx
testq %rdx, %rdx
jle 0x17d3
shlq $0x2, %rdx
leaq -0x830(%rbp), %rdi
xorl %esi, %esi
callq 0x10d0
movq %r13, %rdi
callq 0x1160
testl %eax, %eax
jne 0x1858
xorl %r15d, %r15d
cmpl $0x0, (%r12)
jle 0x1849
xorl %ebx, %ebx
movl 0x8(%r12), %edx
movq %r13, %rdi
movq %r14, %rsi
leaq 0xe2(%rip), %rcx        # 0x18df
callq 0x2560
testl %r15d, %r15d
jne 0x1812
movl %eax, %ecx
negl %ecx
movl %ecx, -0x830(%rbp,%rbx,4)
addl -0x830(%rbp,%rbx,4), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x5928(%rip), %xmm0     # 0x7150
cvttsd2si %xmm0, %edx
movq %r14, %rdi
leaq 0x29a7(%rip), %rsi      # 0x41dd
xorl %eax, %eax
callq 0x1140
incq %rbx
movslq (%r12), %rax
cmpq %rax, %rbx
jl 0x17eb
incl %r15d
movq %r13, %rdi
callq 0x1160
testl %eax, %eax
je 0x17e2
movl 0xc(%r12), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r15d
jne 0x1889
movq %r13, %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 0x5768(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2789(%rip), %rsi      # 0x4023
movl %r15d, %edx
xorl %eax, %eax
callq 0x1140
jmp 0x1865
movq 0x5893(%rip), %rsi      # 0x7140
movq 0x5894(%rip), %rdx      # 0x7148
leaq 0x2790(%rip), %rdi      # 0x404b
xorl %eax, %eax
callq 0x10b0
xorl %edi, %edi
callq 0x1210
leaq 0x27a4(%rip), %rdi      # 0x4074
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1210