// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %r12
movslq %r12d, %r15
cmpl %r12d, %ebx
jle 0x1444
movq (%r14,%r15,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x1444
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x13d6
leaq 0x2(%rsi), %rdi
jmp 0x13db
movq 0x8(%r14,%r15,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x61, %eax
je 0x140e
cmpl $0x63, %eax
je 0x141f
cmpl $0x68, %eax
je 0x1598
cmpl $0x76, %eax
je 0x15f1
xorl %r15d, %r15d
leaq 0x1c6c(%rip), %rdi      # 0x3071
xorl %eax, %eax
callq 0x1628
jmp 0x142d
callq 0x1080
cvttsd2si %xmm0, %eax
movl %eax, 0x4d2f(%rip)      # 0x614c
jmp 0x142a
callq 0x11f0
movl %eax, 0x4d1e(%rip)      # 0x6148
movb $0x1, %r15b
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
jmp 0x13b2
subl %r12d, %ebx
jne 0x1455
movq 0x4b88(%rip), %rax      # 0x5fd8
movq (%rax), %rbx
jmp 0x1476
cmpl $0x2, %ebx
je 0x1482
cmpl $0x1, %ebx
jne 0x1614
movq (%r14,%r15,8), %rdi
leaq 0x214c(%rip), %rsi      # 0x35ba
callq 0x1758
movq %rax, %rbx
movq 0x4b53(%rip), %rax      # 0x5fd0
movq (%rax), %r14
jmp 0x14a9
movq (%r14,%r15,8), %rdi
leaq 0x212d(%rip), %rsi      # 0x35ba
callq 0x1758
movq %rax, %rbx
movq 0x8(%r14,%r15,8), %rdi
leaq 0x1b68(%rip), %rsi      # 0x3009
callq 0x1758
movq %rax, %r14
callq 0x19b4
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x1d19
leaq 0x1b46(%rip), %rdx      # 0x300b
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x2728
leaq 0x1d84(%rip), %r12      # 0x325d
xorl %r13d, %r13d
movq %rbx, %rdi
callq 0x1160
testl %eax, %eax
jne 0x154e
movl %r13d, -0x2c(%rbp)
xorl %r13d, %r13d
cmpl (%r15), %r13d
jge 0x1545
movl 0x8(%r15), %edx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x14b0(%rip), %rcx      # 0x29b5
callq 0x21ee
movl 0x4c38(%rip), %ecx      # 0x6148
movl %ecx, %edx
negl %edx
cmpl %edx, %eax
jge 0x1521
imull 0x4c2d(%rip), %edx      # 0x614c
jmp 0x1533
movl 0x4c25(%rip), %edx      # 0x614c
cmpl %ecx, %eax
jle 0x1530
imull %ecx, %edx
jmp 0x1533
imull %eax, %edx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x1140
incl %r13d
jmp 0x14ef
movl -0x2c(%rbp), %r13d
incl %r13d
jmp 0x14dc
movl 0xc(%r15), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r13d
jne 0x157b
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 0x4a76(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x1a90(%rip), %rsi      # 0x301c
movl %r13d, %edx
xorl %eax, %eax
callq 0x1140
jmp 0x155a
leaq 0x1b23(%rip), %rdi      # 0x30c2
callq 0x1070
leaq 0x1b25(%rip), %rdi      # 0x30d0
callq 0x1070
movl 0x4b96(%rip), %esi      # 0x614c
leaq 0x1a87(%rip), %rbx      # 0x3044
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10b0
leaq 0x1b28(%rip), %rdi      # 0x30f6
callq 0x1070
movl 0x4b6f(%rip), %esi      # 0x6148
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10b0
leaq 0x1b29(%rip), %rdi      # 0x3113
callq 0x1070
jmp 0x160d
movq 0x4b40(%rip), %rsi      # 0x6138
movq 0x4b41(%rip), %rdx      # 0x6140
leaq 0x1a5c(%rip), %rdi      # 0x3062
xorl %eax, %eax
callq 0x10b0
xorl %edi, %edi
callq 0x1200
leaq 0x1a70(%rip), %rdi      # 0x308b
callq 0x1070
pushq $-0x1
popq %rdi
callq 0x1200