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

    int i,j;
    int amp;
    FILE *in,*out;
    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: clip -cN [<input rra file> [<output rra file>]]\n");
        exit(-1);
        }

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

    for (i = 0; !feof(in); ++i)
        for (j = 0; j < h->channels; ++j)
            {
            amp = readRRAAmplitude(in,out,h->bitsPerSample,outputComment);
            if (amp < - clip)
                fprintf(out,"%d\n",- clip * amplify);
            else if (amp > clip)
                fprintf(out,"%d\n",clip * amplify);
            else
                fprintf(out,"%d\n",amp * amplify);
            }

    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
pushq %rax
movq %rsi, %r14
movl %edi, %ebx
movl $0x1, %r12d
cmpl $0x2, %edi
jl 0x16cd
movl $0x1, %r12d
movslq %r12d, %rax
movq (%r14,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x16cd
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x1656
leaq 0x2(%rsi), %rdi
jmp 0x165b
movq 0x8(%r14,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x62, %eax
jle 0x1676
cmpl $0x63, %eax
jne 0x168f
callq 0x11f0
movl %eax, 0x5ad4(%rip)      # 0x7148
jmp 0x168a
cmpl $0x61, %eax
jne 0x16a1
callq 0x1080
cvttsd2si %xmm0, %eax
movl %eax, 0x5ac2(%rip)      # 0x714c
movb $0x1, %r15b
jmp 0x16b2
cmpl $0x68, %eax
je 0x185e
cmpl $0x76, %eax
je 0x1840
xorl %r15d, %r15d
leaq 0x29c6(%rip), %rdi      # 0x4071
xorl %eax, %eax
callq 0x18d4
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
cmpl %ebx, %r12d
jl 0x1637
subl %r12d, %ebx
jne 0x16de
movq 0x58ff(%rip), %rax      # 0x6fd8
movq (%rax), %rbx
jmp 0x1702
cmpl $0x2, %ebx
je 0x170e
cmpl $0x1, %ebx
jne 0x18bc
movslq %r12d, %rax
movq (%r14,%rax,8), %rdi
leaq 0x2ec0(%rip), %rsi      # 0x45ba
callq 0x196e
movq %rax, %rbx
movq 0x58c7(%rip), %rax      # 0x6fd0
movq (%rax), %r14
jmp 0x1738
movslq %r12d, %r15
movq (%r14,%r15,8), %rdi
leaq 0x2e9e(%rip), %rsi      # 0x45ba
callq 0x196e
movq %rax, %rbx
movq 0x8(%r14,%r15,8), %rdi
leaq 0x28d9(%rip), %rsi      # 0x4009
callq 0x196e
movq %rax, %r14
callq 0x1bdf
movq %rax, %r12
xorl %r13d, %r13d
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x2005
leaq 0x28b4(%rip), %rdx      # 0x400b
movq %r14, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x2aa0
movq %rbx, %rdi
callq 0x1160
testl %eax, %eax
jne 0x17f5
leaq 0x2ae2(%rip), %r15      # 0x425d
xorl %r13d, %r13d
movq %r13, -0x30(%rbp)
cmpl $0x0, (%r12)
jle 0x17e2
xorl %r13d, %r13d
movl 0x8(%r12), %edx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x15cd(%rip), %rcx      # 0x2d6b
callq 0x2508
movl 0x599f(%rip), %ecx      # 0x7148
movl %ecx, %edx
negl %edx
cmpl %edx, %eax
jge 0x17ba
imull 0x5994(%rip), %edx      # 0x714c
jmp 0x17cc
movl 0x598c(%rip), %edx      # 0x714c
cmpl %ecx, %eax
jle 0x17c9
imull %ecx, %edx
jmp 0x17cc
imull %eax, %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x1140
incl %r13d
cmpl (%r12), %r13d
jl 0x178c
movq -0x30(%rbp), %r13
incl %r13d
movq %rbx, %rdi
callq 0x1160
testl %eax, %eax
je 0x177e
movl 0xc(%r12), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r13d
jne 0x1823
movq %rbx, %rdi
callq 0x1090
movq %r14, %rdi
callq 0x1090
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x57ce(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x27e8(%rip), %rsi      # 0x401c
movl %r13d, %edx
xorl %eax, %eax
callq 0x1140
jmp 0x1802
movq 0x58f1(%rip), %rsi      # 0x7138
movq 0x58f2(%rip), %rdx      # 0x7140
leaq 0x280d(%rip), %rdi      # 0x4062
xorl %eax, %eax
callq 0x10b0
jmp 0x18b5
leaq 0x285d(%rip), %rdi      # 0x40c2
callq 0x1070
leaq 0x285f(%rip), %rdi      # 0x40d0
callq 0x1070
movl 0x58d0(%rip), %esi      # 0x714c
leaq 0x27c1(%rip), %rbx      # 0x4044
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10b0
leaq 0x2862(%rip), %rdi      # 0x40f6
callq 0x1070
movl 0x58a9(%rip), %esi      # 0x7148
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10b0
leaq 0x2863(%rip), %rdi      # 0x4113
callq 0x1070
xorl %edi, %edi
callq 0x1200
leaq 0x27c8(%rip), %rdi      # 0x408b
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1200
nop