// File: /workspace/github_c_makefile_star2_O2/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 0x2c39(%rip), %rsi      # 0x4025
movq %r15, %rdi
callq 0x1130
testl %eax, %eax
jne 0x1409
movabsq $0x3fe8000000000000, %rax # imm = 0x3FE8000000000000
movq %rax, 0x5d57(%rip)      # 0x7160
leaq 0x2c1c(%rip), %rsi      # 0x402c
movq %r15, %rdi
callq 0x1130
testl %eax, %eax
jne 0x142d
movabsq $0x3ff4000000000000, %rax # imm = 0x3FF4000000000000
movq %rax, 0x5d33(%rip)      # 0x7160
pushq $0x1
popq %r12
movslq %r12d, %r15
cmpl %r12d, %ebx
jle 0x14c5
movq (%r14,%r15,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x14c5
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x1455
leaq 0x2(%rsi), %rdi
jmp 0x145a
movq 0x8(%r14,%r15,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x53, %eax
je 0x1492
cmpl $0x61, %eax
je 0x149e
cmpl $0x73, %eax
je 0x1489
cmpl $0x76, %eax
je 0x1735
xorl %r15d, %r15d
leaq 0x2c72(%rip), %rdi      # 0x40f2
xorl %eax, %eax
callq 0x1868
jmp 0x14ae
movb $0x0, 0x5cec(%rip)      # 0x717c
jmp 0x1499
movb $0x1, 0x5ce3(%rip)      # 0x717c
xorl %r15d, %r15d
jmp 0x14ae
callq 0x1090
movsd %xmm0, 0x5cb5(%rip)     # 0x7160
movb $0x1, %r15b
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
jmp 0x1431
subl %r12d, %ebx
jne 0x14eb
movq 0x5b07(%rip), %rax      # 0x6fd8
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq 0x5af1(%rip), %rax      # 0x6fd0
movq (%rax), %r14
leaq 0x2b4a(%rip), %rbx      # 0x4033
jmp 0x1549
cmpl $0x2, %ebx
je 0x151d
cmpl $0x1, %ebx
jne 0x1758
movq (%r14,%r15,8), %rdi
leaq 0x2b2d(%rip), %rsi      # 0x4031
callq 0x1998
movq %rax, -0x38(%rbp)
movq (%r14,%r15,8), %rbx
movq 0x5ab8(%rip), %rax      # 0x6fd0
movq (%rax), %r14
jmp 0x1549
movq (%r14,%r15,8), %rdi
leaq 0x2b09(%rip), %rsi      # 0x4031
callq 0x1998
movq %rax, -0x38(%rbp)
movq (%r14,%r15,8), %rbx
movq 0x8(%r14,%r15,8), %rdi
leaq 0x2af8(%rip), %rsi      # 0x4039
callq 0x1998
movq %rax, %r14
callq 0x1bf4
movq %rax, %r15
cmpb $0x1, 0x5c24(%rip)      # 0x717c
jne 0x15b2
leaq 0x2ada(%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 0x1596
leaq 0x2aba(%rip), %rdi      # 0x4049
xorl %eax, %eax
callq 0x1868
leaq 0x2a94(%rip), %rsi      # 0x4031
leaq -0x440(%rbp), %rdi
callq 0x11d0
testq %rax, %rax
jne 0x16ab
movq -0x38(%rbp), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x1f59
leaq 0x2ae4(%rip), %rdx      # 0x40ab
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x2968
andl $0x0, -0x2c(%rbp)
leaq 0x2c8e(%rip), %r12      # 0x426d
xorl %r13d, %r13d
movq -0x38(%rbp), %rdi
callq 0x1170
testl %eax, %eax
jne 0x165d
movl %r13d, -0x3c(%rbp)
xorl %r13d, %r13d
cmpl (%r15), %r13d
jge 0x1654
movl -0x2c(%rbp), %eax
cmpl %eax, %ebx
setle %cl
cmovgl %ebx, %eax
negl %ebx
cmpl %ebx, %eax
setge %dl
testb %dl, %cl
jne 0x1619
cmpl %ebx, %eax
cmovgl %eax, %ebx
movl %ebx, -0x2c(%rbp)
movl 0x8(%r15), %edx
movq -0x38(%rbp), %rdi
movq %r14, %rsi
leaq 0x141(%rip), %rcx       # 0x176c
callq 0x242e
movl %eax, %ebx
cvtsi2sd %eax, %xmm0
mulsd 0x5b22(%rip), %xmm0     # 0x7160
cvttsd2si %xmm0, %edx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x1150
incl %r13d
jmp 0x15f6
movl -0x3c(%rbp), %r13d
incl %r13d
jmp 0x15e2
movl 0xc(%r15), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r13d
jne 0x168e
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 0x5963(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2a1c(%rip), %rsi      # 0x40bb
movl %r13d, %edx
xorl %eax, %eax
callq 0x1150
jmp 0x1669
movq %rax, %rbx
leaq 0x29b4(%rip), %rsi      # 0x4069
leaq -0x2c(%rbp), %r12
movq %rax, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x1070
movl 0x8(%r15), %edi
decl %edi
movsd 0x2934(%rip), %xmm0     # 0x4008
callq 0x1050
addsd 0x292f(%rip), %xmm0     # 0x4010
movl (%r12), %edx
cvtsi2sd %edx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x5a6b(%rip)     # 0x7160
movq 0x58fc(%rip), %r12      # 0x6ff8
movq (%r12), %rdi
leaq 0x2966(%rip), %rsi      # 0x406d
xorl %eax, %eax
callq 0x1150
movq (%r12), %rdi
movsd 0x5a46(%rip), %xmm0     # 0x7160
leaq 0x2968(%rip), %rsi      # 0x4089
movb $0x1, %al
callq 0x1150
movq %rbx, %rdi
callq 0x10a0
jmp 0x15b2
movq 0x5a14(%rip), %rsi      # 0x7150
movq 0x5a15(%rip), %rdx      # 0x7158
leaq 0x2999(%rip), %rdi      # 0x40e3
xorl %eax, %eax
callq 0x10c0
xorl %edi, %edi
callq 0x1230
leaq 0x29ad(%rip), %rdi      # 0x410c
callq 0x1080
pushq $-0x1
popq %rdi
callq 0x1230