// File: /workspace/github_c_makefile_star2_O0/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
subq $0x850, %rsp            # imm = 0x850
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x1630
movl %eax, -0x14(%rbp)
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x0, %eax
jne 0x13fb
movq 0x6bf7(%rip), %rax      # 0x7fd8
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq 0x6be1(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x1498
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x1, %eax
jne 0x1432
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x410c(%rip), %rsi      # 0x5525
callq 0x1a10
movq %rax, -0x30(%rbp)
movq 0x6ba7(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x1496
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x2, %eax
jne 0x147c
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x40d5(%rip), %rsi      # 0x5525
callq 0x1a10
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3ba3(%rip), %rsi      # 0x5014
callq 0x1a10
movq %rax, -0x38(%rbp)
jmp 0x1494
leaq 0x3b93(%rip), %rdi      # 0x5016
movb $0x0, %al
callq 0x1090
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x11e0
jmp 0x1496
jmp 0x1498
callq 0x1ef0
movq %rax, -0x848(%rbp)
movq -0x30(%rbp), %rdi
movq -0x848(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x23f0
movq -0x38(%rbp), %rdi
movq -0x848(%rbp), %rsi
leaq 0x3b87(%rip), %rdx      # 0x5051
xorl %eax, %eax
movl %eax, %ecx
callq 0x3390
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x848(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1502
movslq -0x18(%rbp), %rax
movl $0x0, -0x840(%rbp,%rax,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x14da
movl $0x0, -0x20(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x30(%rbp), %rdi
callq 0x1130
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x152a
jmp 0x15cd
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x848(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x15bd
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x848(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0x228(%rip), %rcx       # 0x1780
callq 0x2b20
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x1576
xorl %ecx, %ecx
subl -0x24(%rbp), %ecx
movslq -0x1c(%rbp), %rax
movl %ecx, -0x840(%rbp,%rax,4)
movq -0x38(%rbp), %rdi
movl -0x24(%rbp), %eax
movslq -0x1c(%rbp), %rcx
addl -0x840(%rbp,%rcx,4), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x6b9c(%rip), %xmm0     # 0x8130
cvttsd2si %xmm0, %edx
leaq 0x3c1e(%rip), %rsi      # 0x51bd
movb $0x0, %al
callq 0x1110
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1531
jmp 0x15bf
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1510
movl -0x18(%rbp), %eax
movq -0x848(%rbp), %rcx
movl 0xc(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x1606
movq 0x6a10(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
movq -0x848(%rbp), %rax
movl 0xc(%rax), %ecx
leaq 0x3a62(%rip), %rsi      # 0x5061
movb $0x0, %al
callq 0x1110
movq -0x30(%rbp), %rdi
callq 0x1070
movq -0x38(%rbp), %rdi
callq 0x1070
xorl %eax, %eax
addq $0x850, %rsp            # imm = 0x850
popq %rbp
retq
nopw %cs:(%rax,%rax)