// File: /workspace/github_cpp_makefile_star2_O3/ekg[P]tsvtools/samplelines.cpp
// Function: main
int main (int argc, char** argv) {

    if (argc < 2) {
        cerr << "usage: " << argv[0] << " -r sample_rate" << endl
             << "samples lines from stdin at sample_rate rate" << endl
             << "specify -H to always print header line" << endl;
        exit(1);
    }

    double sample_rate = 1.0;
    bool header = false;

    while (true) {
        static struct option long_options[] =
        {  
            {"header", no_argument, 0, 'H'},
            {"rate",   required_argument, 0, 'r'},

        };
        int option_index = 0;

        int c = getopt_long (argc, argv, "Hr:", long_options, &option_index);

          if (c == -1)
            break;

          switch (c) {
            case 0:
            /* If this option set a flag, do nothing else now. */
            if (long_options[option_index].flag != 0)
              break;
            printf ("option %s", long_options[option_index].name);
            if (optarg)
              printf (" with arg %s", optarg);
            printf ("\n");
            break;

          case 'H':
            header = true;
            break;

          case 'r':
            sample_rate = atof(optarg);
            break;

          default:
            abort();
            break;

        }
    }


    // seed prng with random bits from /dev/random
    fstream random;
    random.open("/dev/random", fstream::in);
    int seed;
    random.get((char*) &seed, sizeof(int));
    random.close();

    init_genrand(seed);

    string line;
    getline(cin, line);
    if (header) {
        cout << line << endl;
    }
    getline(cin, line);

    while (!line.empty()) {
        cout << line << endl;
        if (genrand_real1() < sample_rate) {
            cout << line << endl;
        }
        getline(cin, line);
    }

    return 0;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rsi, %rbx
cmpl $0x2, %edi
jl 0x19db
movl %edi, %ebp
movsd 0x9cc(%rip), %xmm0      # 0x2068
movsd %xmm0, 0x30(%rsp)
xorl %r13d, %r13d
leaq 0xa37(%rip), %r14       # 0x20e3
leaq 0x2a3d(%rip), %r15      # 0x40f0
leaq 0x38(%rsp), %r12
movl $0x0, 0x38(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x1160
cmpl $0x47, %eax
jle 0x16ff
movb $0x1, %cl
cmpl $0x48, %eax
je 0x1752
cmpl $0x72, %eax
jne 0x19d6
movq 0x28c9(%rip), %rax      # 0x3fb8
movq (%rax), %rdi
callq 0x1130
movsd %xmm0, 0x30(%rsp)
jmp 0x174f
testl %eax, %eax
jne 0x175a
movslq 0x38(%rsp), %rax
shlq $0x5, %rax
cmpq $0x0, 0x10(%rax,%r15)
jne 0x174f
addq %r15, %rax
movq (%rax), %rsi
leaq 0x9c6(%rip), %rdi       # 0x20e7
xorl %eax, %eax
callq 0x1040
movq 0x2889(%rip), %rax      # 0x3fb8
movq (%rax), %rsi
testq %rsi, %rsi
je 0x1745
leaq 0x9b3(%rip), %rdi       # 0x20f1
xorl %eax, %eax
callq 0x1040
movl $0xa, %edi
callq 0x1140
movl %r13d, %ecx
movl %ecx, %r13d
jmp 0x16b8
cmpl $-0x1, %eax
jne 0x19d6
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0x1110
leaq 0x987(%rip), %rsi       # 0x20fe
movq %rbx, %rdi
movl $0x8, %edx
callq 0x10c0
movq 0x38(%rsp), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %ecx
leaq 0x38(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movl $0x4, %edx
callq 0x10a0
leaq 0x38(%rsp), %rdi
callq 0x1050
movl 0xc(%rsp), %eax
movq %rax, 0x299a(%rip)      # 0x4160
movl $0x1, %ecx
leaq 0x298e(%rip), %rdx      # 0x4160
movq %rax, %rsi
shrq $0x1e, %rsi
xorl %eax, %esi
imull $0x6c078965, %esi, %eax # imm = 0x6C078965
addl %ecx, %eax
movq %rax, (%rdx,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0x17d2
movl $0x270, 0x28e3(%rip)    # imm = 0x270
leaq 0x20(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq $0x0, -0x8(%rbp)
movb $0x0, (%rbp)
movq 0x27bf(%rip), %rdi      # 0x3fd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %edx
movq 0x27a4(%rip), %rbx      # 0x3fd8
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x1180
testb $0x1, %r13b
je 0x1887
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x2770(%rip), %rdi      # 0x3fc8
callq 0x1100
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %edx
movq 0x2733(%rip), %rbx      # 0x3fd8
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x1180
movq 0x270f(%rip), %r14      # 0x3fc8
leaq 0x10(%rsp), %r15
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
testq %rdx, %rdx
je 0x19a0
movq %r14, %rdi
callq 0x1100
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
callq 0x1413
movq %rax, %xmm0
punpckldq 0x6fb(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x703(%rip), %xmm0      # 0x2020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x70f(%rip), %xmm1      # 0x2040
movsd 0x30(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1979
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x1100
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1180
jmp 0x18be
cmpq %rbp, %rsi
je 0x19b8
movq 0x20(%rsp), %rax
incq %rax
movq %rsi, %rdi
movq %rax, %rsi
callq 0x10f0
leaq 0x38(%rsp), %rdi
callq 0x1060
xorl %eax, %eax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1080
movq 0x260e(%rip), %rdi      # 0x3ff0
leaq 0x687(%rip), %rsi       # 0x2070
callq 0x10e0
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x10e0
leaq 0x678(%rip), %rsi       # 0x2078
movq %rax, %rdi
callq 0x10e0
movq %rax, %rdi
callq 0x1070
leaq 0x671(%rip), %rsi       # 0x2088
movq %rax, %rdi
callq 0x10e0
movq %rax, %rdi
callq 0x1070
leaq 0x687(%rip), %rsi       # 0x20b5
movq %rax, %rdi
callq 0x10e0
movq %rax, %rdi
callq 0x1070
movl $0x1, %edi
callq 0x1120
jmp 0x1a4a
movq %rax, %rbx
jmp 0x1a6b
jmp 0x1a51
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1a6b
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x10f0
leaq 0x38(%rsp), %rdi
callq 0x1060
movq %rbx, %rdi
callq 0x1170