// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
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 0x1610
movl %eax, -0x14(%rbp)
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x0, %eax
jne 0x13f8
movq 0x6bfa(%rip), %rax      # 0x7fd8
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq 0x6be4(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x1495
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x1, %eax
jne 0x142f
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x41dd(%rip), %rsi      # 0x55f3
callq 0x1940
movq %rax, -0x28(%rbp)
movq 0x6baa(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x1493
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x2, %eax
jne 0x1479
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x41a6(%rip), %rsi      # 0x55f3
callq 0x1940
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3bf8(%rip), %rsi      # 0x5066
callq 0x1940
movq %rax, -0x30(%rbp)
jmp 0x1491
leaq 0x3be8(%rip), %rdi      # 0x5068
movb $0x0, %al
callq 0x1090
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x11d0
jmp 0x1493
jmp 0x1495
callq 0x1e20
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2320
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq 0x3be2(%rip), %rdx      # 0x50a0
xorl %eax, %eax
movl %eax, %ecx
callq 0x32c0
movl $0x0, -0x18(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1130
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x14e8
jmp 0x15b8
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x15a8
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0x21ec(%rip), %rcx      # 0x3700
callq 0x2a50
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
xorl %ecx, %ecx
subl 0x6c01(%rip), %ecx      # 0x8128
cmpl %ecx, %eax
jge 0x154e
movq -0x30(%rbp), %rdi
xorl %edx, %edx
subl 0x6bf1(%rip), %edx      # 0x8128
imull 0x6bee(%rip), %edx      # 0x812c
leaq 0x3d48(%rip), %rsi      # 0x528d
movb $0x0, %al
callq 0x1110
jmp 0x1598
movl -0x20(%rbp), %eax
cmpl 0x6bd1(%rip), %eax      # 0x8128
jle 0x157a
movq -0x30(%rbp), %rdi
movl 0x6bc5(%rip), %edx      # 0x8128
imull 0x6bc2(%rip), %edx      # 0x812c
leaq 0x3d1c(%rip), %rsi      # 0x528d
movb $0x0, %al
callq 0x1110
jmp 0x1596
movq -0x30(%rbp), %rdi
movl -0x20(%rbp), %edx
imull 0x6ba4(%rip), %edx      # 0x812c
leaq 0x3cfe(%rip), %rsi      # 0x528d
movb $0x0, %al
callq 0x1110
jmp 0x1598
jmp 0x159a
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x14ef
jmp 0x15aa
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x14ce
movl -0x18(%rbp), %eax
movq -0x38(%rbp), %rcx
movl 0xc(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x15eb
movq 0x6a28(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
leaq 0x3acd(%rip), %rsi      # 0x50b1
movb $0x0, %al
callq 0x1110
movq -0x28(%rbp), %rdi
callq 0x1070
movq -0x30(%rbp), %rdi
callq 0x1070
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)