// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %r12
movslq %r12d, %r15
cmpl %r12d, %ebx
jle 0x1434
movq (%r14,%r15,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x1434
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x13e6
leaq 0x2(%rsi), %rdi
jmp 0x13eb
movq 0x8(%r14,%r15,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x61, %eax
je 0x1410
cmpl $0x76, %eax
je 0x15aa
xorl %r15d, %r15d
leaq 0x2c53(%rip), %rdi      # 0x405a
xorl %eax, %eax
callq 0x16dc
jmp 0x1420
callq 0x1080
movsd %xmm0, 0x5d33(%rip)     # 0x7150
movb $0x1, %r15b
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
jmp 0x13c6
subl %r12d, %ebx
jne 0x1445
movq 0x5b98(%rip), %rax      # 0x6fd8
movq (%rax), %rbx
jmp 0x1466
cmpl $0x2, %ebx
je 0x1472
cmpl $0x1, %ebx
jne 0x15cd
movq (%r14,%r15,8), %rdi
leaq 0x30dc(%rip), %rsi      # 0x453a
callq 0x180c
movq %rax, %rbx
movq 0x5b63(%rip), %rax      # 0x6fd0
movq (%rax), %r14
jmp 0x1499
movq (%r14,%r15,8), %rdi
leaq 0x30bd(%rip), %rsi      # 0x453a
callq 0x180c
movq %rax, %rbx
movq 0x8(%r14,%r15,8), %rdi
leaq 0x2b80(%rip), %rsi      # 0x4011
callq 0x180c
movq %rax, %r14
callq 0x1a68
movq %rax, %r15
xorl %r12d, %r12d
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x1dcd
leaq 0x2b5b(%rip), %rdx      # 0x4013
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x27dc
movl (%r15), %ecx
testl %ecx, %ecx
movl $0x0, %eax
cmovgl %ecx, %eax
cmpq %r12, %rax
je 0x14e5
andl $0x0, -0x830(%rbp,%r12,4)
incq %r12
jmp 0x14d2
xorl %r12d, %r12d
movq %rbx, %rdi
callq 0x1160
testl %eax, %eax
jne 0x155d
xorl %r13d, %r13d
movslq (%r15), %rax
cmpq %rax, %r13
jge 0x1558
movl 0x8(%r15), %edx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0xd1(%rip), %rcx        # 0x15e1
callq 0x22a2
testl %r12d, %r12d
je 0x1524
movl -0x830(%rbp,%r13,4), %ecx
jmp 0x1530
movl %eax, %ecx
negl %ecx
movl %ecx, -0x830(%rbp,%r13,4)
addl %eax, %ecx
cvtsi2sd %ecx, %xmm0
mulsd 0x5c12(%rip), %xmm0     # 0x7150
cvttsd2si %xmm0, %edx
movq %r14, %rdi
leaq 0x2c91(%rip), %rsi      # 0x41dd
xorl %eax, %eax
callq 0x1140
incq %r13
jmp 0x14f7
incl %r12d
jmp 0x14e8
movl 0xc(%r15), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r12d
jne 0x158d
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 0x5a64(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2a85(%rip), %rsi      # 0x4023
movl %r12d, %edx
xorl %eax, %eax
callq 0x1140
jmp 0x1569
movq 0x5b8f(%rip), %rsi      # 0x7140
movq 0x5b90(%rip), %rdx      # 0x7148
leaq 0x2a8c(%rip), %rdi      # 0x404b
xorl %eax, %eax
callq 0x10b0
xorl %edi, %edi
callq 0x1210
leaq 0x2aa0(%rip), %rdi      # 0x4074
callq 0x1070
pushq $-0x1
popq %rdi
callq 0x1210