// File: /workspace/github_c_makefile_star2_O1/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 0x28b7(%rip), %rsi      # 0x4025
movq %r15, %rdi
callq 0x1130
testl %eax, %eax
jne 0x178b
movabsq $0x3fe8000000000000, %rax # imm = 0x3FE8000000000000
movq %rax, 0x59d5(%rip)      # 0x7160
leaq 0x289a(%rip), %rsi      # 0x402c
movq %r15, %rdi
callq 0x1130
testl %eax, %eax
jne 0x17af
movabsq $0x3ff4000000000000, %rax # imm = 0x3FF4000000000000
movq %rax, 0x59b1(%rip)      # 0x7160
movl $0x1, %r12d
cmpl $0x2, %ebx
jl 0x185c
movl $0x1, %r12d
movslq %r12d, %rax
movq (%r14,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x185c
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x17e3
leaq 0x2(%rsi), %rdi
jmp 0x17e8
movq 0x8(%r14,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x72, %eax
jg 0x180d
cmpl $0x53, %eax
je 0x181b
cmpl $0x61, %eax
jne 0x1830
callq 0x1090
movsd %xmm0, 0x5958(%rip)     # 0x7160
movb $0x1, %r15b
jmp 0x1841
cmpl $0x73, %eax
jne 0x1827
movb $0x0, 0x5963(%rip)      # 0x717c
jmp 0x1822
movb $0x1, 0x595a(%rip)      # 0x717c
xorl %r15d, %r15d
jmp 0x1841
cmpl $0x76, %eax
je 0x1a6a
xorl %r15d, %r15d
leaq 0x28b8(%rip), %rdi      # 0x40f2
xorl %eax, %eax
callq 0x1b14
testb %r13b, %r13b
sete %al
andb %r15b, %al
movzbl %al, %eax
addl %eax, %r12d
incl %r12d
cmpl %ebx, %r12d
jl 0x17c4
subl %r12d, %ebx
jne 0x1882
movq 0x5770(%rip), %rax      # 0x6fd8
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq 0x575a(%rip), %rax      # 0x6fd0
movq (%rax), %r14
leaq 0x27b3(%rip), %rbx      # 0x4033
jmp 0x18e6
cmpl $0x2, %ebx
je 0x18b7
cmpl $0x1, %ebx
jne 0x1a8d
movslq %r12d, %rbx
movq (%r14,%rbx,8), %rdi
leaq 0x2793(%rip), %rsi      # 0x4031
callq 0x1bae
movq %rax, -0x38(%rbp)
movq (%r14,%rbx,8), %rbx
movq 0x571e(%rip), %rax      # 0x6fd0
movq (%rax), %r14
jmp 0x18e6
movslq %r12d, %r15
movq (%r14,%r15,8), %rdi
leaq 0x276c(%rip), %rsi      # 0x4031
callq 0x1bae
movq %rax, -0x38(%rbp)
movq (%r14,%r15,8), %rbx
movq 0x8(%r14,%r15,8), %rdi
leaq 0x275b(%rip), %rsi      # 0x4039
callq 0x1bae
movq %rax, %r14
callq 0x1e2b
movq %rax, %r15
cmpb $0x1, 0x5887(%rip)      # 0x717c
jne 0x194f
leaq 0x273d(%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 0x1933
leaq 0x271d(%rip), %rdi      # 0x4049
xorl %eax, %eax
callq 0x1b14
leaq 0x26f7(%rip), %rsi      # 0x4031
leaq -0x440(%rbp), %rdi
callq 0x11d0
testq %rax, %rax
jne 0x1a56
xorl %r13d, %r13d
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x2238
leaq 0x2741(%rip), %rdx      # 0x40ab
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x2c89
movl $0x0, -0x2c(%rbp)
movq %rbx, %rdi
callq 0x1170
testl %eax, %eax
jne 0x1a08
leaq 0x28dc(%rip), %r12      # 0x426d
xorl %r13d, %r13d
movq %r13, -0x40(%rbp)
cmpl $0x0, (%r15)
jle 0x19f4
xorl %r13d, %r13d
cmpl -0x2c(%rbp), %ebx
jle 0x19a9
movl %ebx, -0x2c(%rbp)
negl %ebx
cmpl %ebx, -0x2c(%rbp)
jge 0x19b3
movl %ebx, -0x2c(%rbp)
movl 0x8(%r15), %edx
movq -0x38(%rbp), %rdi
movq %r14, %rsi
leaq 0xde(%rip), %rcx        # 0x1aa3
callq 0x2724
movl %eax, %ebx
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x5785(%rip), %xmm0     # 0x7160
cvttsd2si %xmm0, %edx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x1150
incl %r13d
cmpl (%r15), %r13d
jl 0x19a1
movq -0x40(%rbp), %r13
incl %r13d
movq -0x38(%rbp), %rdi
callq 0x1170
testl %eax, %eax
je 0x1994
movl 0xc(%r15), %ecx
leal 0x1(%rcx), %eax
cmpl %eax, %r13d
jne 0x1a39
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 0x55b8(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2671(%rip), %rsi      # 0x40bb
movl %r13d, %edx
xorl %eax, %eax
callq 0x1150
jmp 0x1a14
leaq -0x2c(%rbp), %rsi
movq %rax, %rdi
movq %r15, %rdx
callq 0x1290
jmp 0x194f
movq 0x56df(%rip), %rsi      # 0x7150
movq 0x56e0(%rip), %rdx      # 0x7158
leaq 0x2664(%rip), %rdi      # 0x40e3
xorl %eax, %eax
callq 0x10c0
xorl %edi, %edi
callq 0x1230
leaq 0x2678(%rip), %rdi      # 0x410c
callq 0x1080
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1230