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

    int i,j;
    int count;
    int max,amp;
    char *source,ampname[1024];
    FILE *in,*out,*fp;
    RRA *h;

    if (strcmp(argv[0],"softer") == 0) attenuation = 0.75;
    if (strcmp(argv[0],"louder") == 0) attenuation = 1.25;

    argIndex = processOptions(argc,argv);

    if (argc-argIndex == 0)
        {
        in = stdin;
        source = "stdin";
        out = stdout;
        }
    else if (argc-argIndex == 1)
        {
        in = OpenFile(argv[argIndex],"r");
        source = argv[argIndex];
        out = stdout;
        }
    else if (argc-argIndex == 2)
        {
        in = OpenFile(argv[argIndex],"r");
        source = argv[argIndex];
        out = OpenFile(argv[argIndex+1],"w");
        }
    else
        {
        printf("usage: amplify -aN [<input rra file> [<output rra file>]]\n");
        exit(-1);
        }

    h = newRRAHeader();
    
    if (smart)
        {
        sprintf(ampname,".amplitude_%s",source);

        if (strlen(source) + strlen(",amplitude_") + 1 >= sizeof(ampname))
            Fatal("amplify: file name is too long\n");

        fp = fopen(ampname,"r");
        if (fp != 0)
            {
            fscanf(fp," %d",&max);
            attenuation = (pow(2,h->bitsPerSample - 1) - 1) / max;
            fprintf(stderr,"amplify: old maximum is %d\n",max);
            fprintf(stderr,"amplify: smart attenuation is %f\n",attenuation);
            fclose(fp);
            }
        }

    readRRAHeader(in,h,0);
    writeRRAHeader(out,h,"modifiedBy: amp",0);

    max = 0;
    count = 0;
    for (i = 0; !feof(in); ++i)
        for (j = 0; j < h->channels; ++j)
            {
            if (amp > max) max = amp;
            if (-amp > max) max = -amp;
            amp = readRRAAmplitude(in,out,h->bitsPerSample,commentHandler);
            fprintf(out,"%d\n",(int) (amp * attenuation));
            ++count;
            }

    if (i != h->samples + 1)
        fprintf(stderr,"WARNING: %d samples found, %d expected\n",i,h->samples);

    fclose(in);
    fclose(out);

    #if 0
    fp = OpenFile(ampname,"w");
    fprintf(fp,"%d\n",max);
    fclose(fp);
    #endif

    return 0;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rsi, %r14
movl %edi, %ebx
movq (%rsi), %r15
leaq 0x2897(%rip), %rsi      # 0x4025
movq %r15, %rdi
callq 0x1130
testl %eax, %eax
jne 0x17ab
movabsq $0x3fe8000000000000, %rax # imm = 0x3FE8000000000000
movq %rax, 0x59b5(%rip)      # 0x7160
leaq 0x287a(%rip), %rsi      # 0x402c
movq %r15, %rdi
callq 0x1130
testl %eax, %eax
jne 0x17cf
movabsq $0x3ff4000000000000, %rax # imm = 0x3FF4000000000000
movq %rax, 0x5991(%rip)      # 0x7160
movl $0x1, %r12d
cmpl $0x2, %ebx
jl 0x187c
movl $0x1, %r12d
movslq %r12d, %rax
movq (%r14,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x187c
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x1803
leaq 0x2(%rsi), %rdi
jmp 0x1808
movq 0x8(%r14,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x72, %eax
jg 0x182d
cmpl $0x53, %eax
je 0x183b
cmpl $0x61, %eax
jne 0x1850
callq 0x1090
movsd %xmm0, 0x5938(%rip)     # 0x7160
movb $0x1, %r15b
jmp 0x1861
cmpl $0x73, %eax
jne 0x1847
movb $0x0, 0x5943(%rip)      # 0x717c
jmp 0x1842
movb $0x1, 0x593a(%rip)      # 0x717c
xorl %r15d, %r15d
jmp 0x1861
cmpl $0x76, %eax
je 0x1a9a
xorl %r15d, %r15d
leaq 0x2898(%rip), %rdi      # 0x40f2
xorl %eax, %eax
callq 0x1b44
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
cmpl %ebx, %r12d
jl 0x17e4
subl %r12d, %ebx
jne 0x18a2
movq 0x5750(%rip), %rax      # 0x6fd8
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq 0x573a(%rip), %rax      # 0x6fd0
movq (%rax), %r14
leaq 0x2793(%rip), %rbx      # 0x4033
jmp 0x1906
cmpl $0x2, %ebx
je 0x18d7
cmpl $0x1, %ebx
jne 0x1abd
movslq %r12d, %rbx
movq (%r14,%rbx,8), %rdi
leaq 0x2773(%rip), %rsi      # 0x4031
callq 0x1bde
movq %rax, -0x38(%rbp)
movq (%r14,%rbx,8), %rbx
movq 0x56fe(%rip), %rax      # 0x6fd0
movq (%rax), %r14
jmp 0x1906
movslq %r12d, %r15
movq (%r14,%r15,8), %rdi
leaq 0x274c(%rip), %rsi      # 0x4031
callq 0x1bde
movq %rax, -0x38(%rbp)
movq (%r14,%r15,8), %rbx
movq 0x8(%r14,%r15,8), %rdi
leaq 0x273b(%rip), %rsi      # 0x4039
callq 0x1bde
movq %rax, %r14
callq 0x1e4f
movq %rax, %r15
cmpb $0x1, 0x5867(%rip)      # 0x717c
jne 0x196f
leaq 0x271d(%rip), %rsi      # 0x403b
leaq -0x440(%rbp), %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1220
movq %rbx, %rdi
callq 0x10b0
addq $-0x3f4, %rax           # imm = 0xFC0C
cmpq $-0x401, %rax           # imm = 0xFBFF
ja 0x1953
leaq 0x26fd(%rip), %rdi      # 0x4049
xorl %eax, %eax
callq 0x1b44
leaq 0x26d7(%rip), %rsi      # 0x4031
leaq -0x440(%rbp), %rdi
callq 0x11d0
testq %rax, %rax
jne 0x1a86
xorl %r13d, %r13d
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x2275
leaq 0x2721(%rip), %rdx      # 0x40ab
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x2d10
movl $0x0, -0x2c(%rbp)
movq %rbx, %rdi
callq 0x1170
testl %eax, %eax
jne 0x1a38
leaq 0x28b8(%rip), %r12      # 0x426d
xorl %r13d, %r13d
movq %r13, -0x40(%rbp)
cmpl $0x0, (%r15)
jle 0x1a24
xorl %r13d, %r13d
movl -0x2c(%rbp), %eax
cmpl %eax, %ebx
setle %cl
cmovgl %ebx, %eax
negl %ebx
cmpl %ebx, %eax
setge %dl
testb %dl, %cl
jne 0x19e3
cmpl %ebx, %eax
cmovgl %eax, %ebx
movl %ebx, -0x2c(%rbp)
movl 0x8(%r15), %edx
movq -0x38(%rbp), %rdi
movq %r14, %rsi
leaq 0xde(%rip), %rcx        # 0x1ad3
callq 0x2778
movl %eax, %ebx
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x5755(%rip), %xmm0     # 0x7160
cvttsd2si %xmm0, %edx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x1150
incl %r13d
cmpl (%r15), %r13d
jl 0x19c5
movq -0x40(%rbp), %r13
incl %r13d
movq -0x38(%rbp), %rdi
callq 0x1170
testl %eax, %eax
je 0x19b8
movl 0xc(%r15), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r13d
jne 0x1a69
movq -0x38(%rbp), %rdi
callq 0x10a0
movq %r14, %rdi
callq 0x10a0
xorl %eax, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5588(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2641(%rip), %rsi      # 0x40bb
movl %r13d, %edx
xorl %eax, %eax
callq 0x1150
jmp 0x1a44
leaq -0x2c(%rbp), %rsi
movq %rax, %rdi
movq %r15, %rdx
callq 0x1290
jmp 0x196f
movq 0x56af(%rip), %rsi      # 0x7150
movq 0x56b0(%rip), %rdx      # 0x7158
leaq 0x2634(%rip), %rdi      # 0x40e3
xorl %eax, %eax
callq 0x10c0
xorl %edi, %edi
callq 0x1230
leaq 0x2648(%rip), %rdi      # 0x410c
callq 0x1080
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1230