// File: /workspace/github_cpp_makefile_star2_O2/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 0x17e7
movl %edi, %ebp
movsd 0xa5e(%rip), %xmm0      # 0x2068
movsd %xmm0, 0x10(%rsp)
movl $0x0, 0x8(%rsp)
leaq 0xac4(%rip), %r14       # 0x20e3
leaq 0x2aaa(%rip), %r15      # 0x40d0
leaq 0x38(%rsp), %r12
movq 0x2986(%rip), %r13      # 0x3fb8
andl $0x0, 0x38(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x1140
testl %eax, %eax
je 0x1671
cmpl $0x48, %eax
je 0x1669
cmpl $0x72, %eax
jne 0x16ba
movq (%r13), %rdi
callq 0x1110
movsd %xmm0, 0x10(%rsp)
jmp 0x1632
movb $0x1, %al
movl %eax, 0x8(%rsp)
jmp 0x1632
movslq 0x38(%rsp), %rax
shlq $0x5, %rax
cmpq $0x0, 0x10(%rax,%r15)
jne 0x1632
addq %r15, %rax
movq (%rax), %rsi
leaq 0xa58(%rip), %rdi       # 0x20e7
xorl %eax, %eax
callq 0x1030
movq (%r13), %rsi
testq %rsi, %rsi
je 0x16ad
leaq 0xa4b(%rip), %rdi       # 0x20f1
xorl %eax, %eax
callq 0x1030
pushq $0xa
popq %rdi
callq 0x1120
jmp 0x1632
cmpl $-0x1, %eax
jne 0x17e2
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0x10f0
leaq 0xa27(%rip), %rsi       # 0x20fe
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x10d0
leaq 0x38(%rsp), %rdi
leaq 0xc(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x10a0
leaq 0x38(%rsp), %rdi
callq 0x1040
movslq 0xc(%rsp), %rdi
callq 0x128c
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x28b8(%rip), %rdi      # 0x3fd8
leaq 0x18(%rsp), %rsi
callq 0x1050
testb $0x1, 0x8(%rsp)
je 0x174a
movq 0x2890(%rip), %rdi      # 0x3fc8
leaq 0x18(%rsp), %rsi
callq 0x10c0
movq %rax, %rdi
callq 0x1080
movq 0x2887(%rip), %rdi      # 0x3fd8
leaq 0x18(%rsp), %rsi
callq 0x1050
movq 0x2866(%rip), %rbx      # 0x3fc8
leaq 0x18(%rsp), %r14
movq 0x286a(%rip), %r15      # 0x3fd8
cmpq $0x0, 0x20(%rsp)
je 0x17ba
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10c0
movq %rax, %rdi
callq 0x1080
callq 0x1512
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x17ad
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10c0
movq %rax, %rdi
callq 0x1080
movq %r15, %rdi
movq %r14, %rsi
callq 0x1050
jmp 0x176e
leaq 0x18(%rsp), %rdi
callq 0x1070
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 0x1090
movq 0x2802(%rip), %rdi      # 0x3ff0
leaq 0x87b(%rip), %rsi       # 0x2070
callq 0x10e0
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x10e0
leaq 0x86c(%rip), %rsi       # 0x2078
movq %rax, %rdi
callq 0x10e0
movq %rax, %rdi
callq 0x1080
leaq 0x865(%rip), %rsi       # 0x2088
movq %rax, %rdi
callq 0x10e0
movq %rax, %rdi
callq 0x1080
leaq 0x87b(%rip), %rsi       # 0x20b5
movq %rax, %rdi
callq 0x10e0
movq %rax, %rdi
callq 0x1080
pushq $0x1
popq %rdi
callq 0x1100
jmp 0x1854
movq %rax, %rbx
jmp 0x1868
jmp 0x185b
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x1070
leaq 0x38(%rsp), %rdi
callq 0x1060
movq %rbx, %rdi
callq 0x1150