// File: /workspace/github_c_makefile_star2_O0/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
subq $0x450, %rsp            # imm = 0x450
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x3cda(%rip), %rsi      # 0x50c8
callq 0x1100
cmpl $0x0, %eax
jne 0x1408
movsd 0x3c08(%rip), %xmm0     # 0x5008
movsd %xmm0, 0x6d38(%rip)     # 0x8140
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x3cb9(%rip), %rsi      # 0x50cf
callq 0x1100
cmpl $0x0, %eax
jne 0x1430
movsd 0x3be8(%rip), %xmm0     # 0x5010
movsd %xmm0, 0x6d10(%rip)     # 0x8140
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x17e0
movl %eax, -0x14(%rbp)
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x0, %eax
jne 0x147c
movq 0x6b87(%rip), %rax      # 0x7fd8
movq (%rax), %rax
movq %rax, -0x438(%rbp)
leaq 0x3c74(%rip), %rax      # 0x50d6
movq %rax, -0x30(%rbp)
movq 0x6b63(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x440(%rbp)
jmp 0x1545
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x1, %eax
jne 0x14c9
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3c3a(%rip), %rsi      # 0x50d4
callq 0x1be0
movq %rax, -0x438(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq 0x6b13(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x440(%rbp)
jmp 0x1543
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x2, %eax
jne 0x1529
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3bed(%rip), %rsi      # 0x50d4
callq 0x1be0
movq %rax, -0x438(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3bc1(%rip), %rsi      # 0x50dc
callq 0x1be0
movq %rax, -0x440(%rbp)
jmp 0x1541
leaq 0x3bae(%rip), %rdi      # 0x50de
movb $0x0, %al
callq 0x10a0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1200
jmp 0x1543
jmp 0x1545
callq 0x20c0
movq %rax, -0x450(%rbp)
cmpl $0x0, 0x6c04(%rip)      # 0x815c
je 0x1663
leaq -0x430(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x3ba9(%rip), %rsi      # 0x5119
movb $0x0, %al
callq 0x11f0
movq -0x30(%rbp), %rdi
callq 0x1090
addq $0xb, %rax
addq $0x1, %rax
cmpq $0x400, %rax            # imm = 0x400
jb 0x159e
leaq 0x3b90(%rip), %rdi      # 0x5127
movb $0x0, %al
callq 0x1a90
leaq -0x430(%rbp), %rdi
leaq 0x3b28(%rip), %rsi      # 0x50d4
callq 0x11a0
movq %rax, -0x448(%rbp)
cmpq $0x0, -0x448(%rbp)
je 0x1661
movq -0x448(%rbp), %rdi
leaq 0x3b73(%rip), %rsi      # 0x5147
leaq -0x24(%rbp), %rdx
movb $0x0, %al
callq 0x1050
movq -0x450(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
movsd 0x3a28(%rip), %xmm0     # 0x5020
callq 0x1070
movsd 0x3a13(%rip), %xmm1     # 0x5018
subsd %xmm1, %xmm0
cvtsi2sdl -0x24(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x6b26(%rip)     # 0x8140
movq 0x69d7(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movl -0x24(%rbp), %edx
leaq 0x3b1d(%rip), %rsi      # 0x514b
movb $0x0, %al
callq 0x1120
movq 0x69bc(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movsd 0x6af9(%rip), %xmm0     # 0x8140
leaq 0x3b19(%rip), %rsi      # 0x5167
movb $0x1, %al
callq 0x1120
movq -0x448(%rbp), %rdi
callq 0x1080
jmp 0x1663
movq -0x438(%rbp), %rdi
movq -0x450(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x25c0
movq -0x440(%rbp), %rdi
movq -0x450(%rbp), %rsi
leaq 0x3afa(%rip), %rdx      # 0x5189
xorl %eax, %eax
movl %eax, %ecx
callq 0x3560
movl $0x0, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x438(%rbp), %rdi
callq 0x1140
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x16ca
jmp 0x1777
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x450(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1767
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x16f1
movl -0x28(%rbp), %eax
movl %eax, -0x24(%rbp)
xorl %eax, %eax
subl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x1703
xorl %eax, %eax
subl -0x28(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x438(%rbp), %rdi
movq -0x440(%rbp), %rsi
movq -0x450(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0x22e(%rip), %rcx       # 0x1950
callq 0x2cf0
movl %eax, -0x28(%rbp)
movq -0x440(%rbp), %rdi
cvtsi2sdl -0x28(%rbp), %xmm0
mulsd 0x6a02(%rip), %xmm0     # 0x8140
cvttsd2si %xmm0, %edx
leaq 0x3b9c(%rip), %rsi      # 0x52e5
movb $0x0, %al
callq 0x1120
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x16d1
jmp 0x1769
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x16ad
movl -0x18(%rbp), %eax
movq -0x450(%rbp), %rcx
movl 0xc(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x17b0
movq 0x6866(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
movq -0x450(%rbp), %rax
movl 0xc(%rax), %ecx
leaq 0x39f0(%rip), %rsi      # 0x5199
movb $0x0, %al
callq 0x1120
movq -0x438(%rbp), %rdi
callq 0x1080
movq -0x440(%rbp), %rdi
callq 0x1080
xorl %eax, %eax
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq
nopw %cs:(%rax,%rax)