// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/extracters/rawcopy/RawCopy.c
// Function: main
int main(int argc, char **argv)
{
FILE *fin, *fout;
size_t bytesread, readsize = sizeof(buf), totalbytes = 0;

if (argc < 3)
    {
    fprintf(stderr, "Usage: RawCopy <infile> <outfile>\n");
    fprintf(stderr, "On Win32 environments, RAW devices have names for the format:\n");
    fprintf(stderr,"      CD Drives    \\\\.\\CdRom0\n");
    fprintf(stderr,"      Hard Drives  \\\\.\\PhysicalDrive0\n");
    exit(0);
    }
if (NULL == (fin = fopen(argv[1], "rb")))
    {
    fprintf(stderr, "Error Opening '%s' for input: %s\n", argv[1], strerror(errno));
    exit(errno);
    }
if (NULL == (fout = fopen(argv[2], "wb")))
    {
    fprintf(stderr, "Error Opening '%s' for output: %s\n", argv[2], strerror(errno));
    exit(errno);
    }
fprintf(stderr, "Copying '%s' to '%s'\n", argv[1], argv[2]);
while (0 != (bytesread = fread(buf, 1, readsize, fin)))
    {
    if (bytesread != fwrite(buf, 1, bytesread, fout))
        {
            fprintf(stderr, "Error Writing '%s': %s\n", argv[2], strerror(errno));
        break;
        }
    else
       totalbytes += bytesread;
    if (0 == (totalbytes%(1024*1024)))
        fprintf(stderr, "%6dMB Copied...\r", totalbytes/(1024*1024));
    }
fprintf(stderr, "\n");
fprintf(stderr, "Total Data: %6.2f MBytes (%d bytes)\n", totalbytes/(1024.0*1024.0), totalbytes);
fclose(fin);
fclose(fout);
 exit(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpl $0x2, %edi
jle 0x133b
movq %rsi, %r12
movq 0x8(%rsi), %rdi
leaq 0xf02(%rip), %rsi       # 0x20e0
callq 0x1080
testq %rax, %rax
je 0x139b
movq %rax, %rbx
movq 0x10(%r12), %rdi
leaq 0xf0a(%rip), %rsi       # 0x2105
callq 0x1080
movq %rax, %r14
movq 0x2dee(%rip), %rax      # 0x3ff8
movq (%rax), %r15
testq %r14, %r14
je 0x13d8
movq 0x8(%r12), %rdx
movq %r12, (%rsp)
movq 0x10(%r12), %rcx
leaq 0xf00(%rip), %rsi       # 0x212b
movq %r15, %rdi
xorl %eax, %eax
callq 0x1070
leaq 0x2e44(%rip), %r13      # 0x4080
pushq $0x1
popq %rbp
xorl %r12d, %r12d
movl $0x100000, %edx         # imm = 0x100000
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %rcx
callq 0x1040
testq %rax, %rax
je 0x12d5
movq %rax, %r15
movq %r13, %rdi
movq %rbp, %rsi
movq %rax, %rdx
movq %r14, %rcx
callq 0x10a0
cmpq %rax, %r15
jne 0x12a0
addq %r15, %r12
testl $0xfffff, %r12d         # imm = 0xFFFFF
jne 0x1242
movq 0x2d72(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq %r12, %rdx
shrq $0x14, %rdx
leaq 0xec2(%rip), %rsi       # 0x2159
xorl %eax, %eax
callq 0x1070
jmp 0x1242
movq 0x2d51(%rip), %rax      # 0x3ff8
movq (%rax), %r15
movq (%rsp), %rax
movq 0x10(%rax), %r13
callq 0x1030
movl (%rax), %edi
callq 0x10b0
leaq 0xe7c(%rip), %rsi       # 0x2141
movq %r15, %rdi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1070
movq 0x2d1c(%rip), %r15      # 0x3ff8
movq (%r15), %rsi
pushq $0xa
popq %rdi
callq 0x1060
movq %r12, %xmm1
punpckldq 0xd1c(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
movq (%r15), %rdi
subpd 0xd21(%rip), %xmm1      # 0x2020
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0xd1d(%rip), %xmm0      # 0x2030
leaq 0xe50(%rip), %rsi       # 0x216a
movq %r12, %rdx
movb $0x1, %al
callq 0x1070
movq %rbx, %rdi
callq 0x1050
movq %r14, %rdi
callq 0x1050
xorl %edi, %edi
callq 0x1090
movq 0x2cb6(%rip), %r14      # 0x3ff8
movq (%r14), %rcx
leaq 0xcec(%rip), %rdi       # 0x2038
pushq $0x22
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x10a0
movq (%r14), %rcx
leaq 0xcf7(%rip), %rdi       # 0x205b
pushq $0x3e
popq %rsi
movq %rbx, %rdx
callq 0x10a0
movq (%r14), %rcx
leaq 0xd21(%rip), %rdi       # 0x209a
pushq $0x1e
popq %rsi
movq %rbx, %rdx
callq 0x10a0
movq (%r14), %rcx
leaq 0xd2b(%rip), %rdi       # 0x20b9
pushq $0x26
popq %rsi
movq %rbx, %rdx
callq 0x10a0
jmp 0x1334
movq 0x2c56(%rip), %rax      # 0x3ff8
movq (%rax), %rbx
movq 0x8(%r12), %r14
callq 0x1030
movq %rax, %r15
movl (%rax), %edi
callq 0x10b0
leaq 0xd23(%rip), %rsi       # 0x20e3
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1070
movl (%r15), %edi
callq 0x1090
movq 0x10(%r12), %rbx
callq 0x1030
movq %rax, %r14
movl (%rax), %edi
callq 0x10b0
leaq 0xd15(%rip), %rsi       # 0x2108
movq %r15, %rdi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1070
movl (%r14), %edi
callq 0x1090