// File: /workspace/github_c_makefile_star2_O1/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 0x169d
movl $0x1, %r12d
movslq %r12d, %rax
movq (%r14,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x169d
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x1626
leaq 0x2(%rsi), %rdi
jmp 0x162b
movq 0x8(%r14,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x62, %eax
jle 0x1646
cmpl $0x63, %eax
jne 0x165f
callq 0x11f0
movl %eax, 0x5b04(%rip)      # 0x7148
jmp 0x165a
cmpl $0x61, %eax
jne 0x1671
callq 0x1080
cvttsd2si %xmm0, %eax
movl %eax, 0x5af2(%rip)      # 0x714c
movb $0x1, %r15b
jmp 0x1682
cmpl $0x68, %eax
je 0x182e
cmpl $0x76, %eax
je 0x1810
xorl %r15d, %r15d
leaq 0x29f6(%rip), %rdi      # 0x4071
xorl %eax, %eax
callq 0x18a4
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
cmpl %ebx, %r12d
jl 0x1607
subl %r12d, %ebx
jne 0x16ae
movq 0x592f(%rip), %rax      # 0x6fd8
movq (%rax), %rbx
jmp 0x16d2
cmpl $0x2, %ebx
je 0x16de
cmpl $0x1, %ebx
jne 0x188c
movslq %r12d, %rax
movq (%r14,%rax,8), %rdi
leaq 0x2ef3(%rip), %rsi      # 0x45bd
callq 0x193e
movq %rax, %rbx
movq 0x58f7(%rip), %rax      # 0x6fd0
movq (%rax), %r14
jmp 0x1708
movslq %r12d, %r15
movq (%r14,%r15,8), %rdi
leaq 0x2ed1(%rip), %rsi      # 0x45bd
callq 0x193e
movq %rax, %rbx
movq 0x8(%r14,%r15,8), %rdi
leaq 0x2909(%rip), %rsi      # 0x4009
callq 0x193e
movq %rax, %r14
callq 0x1bbb
movq %rax, %r12
xorl %r13d, %r13d
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x1fc8
leaq 0x28e4(%rip), %rdx      # 0x400b
movq %r14, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x2a19
movq %rbx, %rdi
callq 0x1160
testl %eax, %eax
jne 0x17c5
leaq 0x2b12(%rip), %r15      # 0x425d
xorl %r13d, %r13d
movq %r13, -0x30(%rbp)
cmpl $0x0, (%r12)
jle 0x17b2
xorl %r13d, %r13d
movl 0x8(%r12), %edx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x1577(%rip), %rcx      # 0x2ce5
callq 0x24b4
movl 0x59cf(%rip), %ecx      # 0x7148
movl %ecx, %edx
negl %edx
cmpl %edx, %eax
jge 0x178a
imull 0x59c4(%rip), %edx      # 0x714c
jmp 0x179c
movl 0x59bc(%rip), %edx      # 0x714c
cmpl %ecx, %eax
jle 0x1799
imull %ecx, %edx
jmp 0x179c
imull %eax, %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x1140
incl %r13d
cmpl (%r12), %r13d
jl 0x175c
movq -0x30(%rbp), %r13
incl %r13d
movq %rbx, %rdi
callq 0x1160
testl %eax, %eax
je 0x174e
movl 0xc(%r12), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r13d
jne 0x17f3
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 0x57fe(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2818(%rip), %rsi      # 0x401c
movl %r13d, %edx
xorl %eax, %eax
callq 0x1140
jmp 0x17d2
movq 0x5921(%rip), %rsi      # 0x7138
movq 0x5922(%rip), %rdx      # 0x7140
leaq 0x283d(%rip), %rdi      # 0x4062
xorl %eax, %eax
callq 0x10b0
jmp 0x1885
leaq 0x288d(%rip), %rdi      # 0x40c2
callq 0x1070
leaq 0x288f(%rip), %rdi      # 0x40d0
callq 0x1070
movl 0x5900(%rip), %esi      # 0x714c
leaq 0x27f1(%rip), %rbx      # 0x4044
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10b0
leaq 0x2892(%rip), %rdi      # 0x40f6
callq 0x1070
movl 0x58d9(%rip), %esi      # 0x7148
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10b0
leaq 0x2893(%rip), %rdi      # 0x4113
callq 0x1070
xorl %edi, %edi
callq 0x1200
leaq 0x27f8(%rip), %rdi      # 0x408b
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1200
nop