// File: TwilioDevEd[P]twilio_cpp_demo/src/cpp_demo.cc
// Function: main
int main(int argc, char * argv[])
{
        int cmd;
        std::string account_sid;
        std::string auth_token;
        std::string message;
        std::string from_number;
        std::string to_number;
        std::string picture_url;
        bool verbose = false;

        opterr = 0;

        while ((cmd = getopt(argc, argv, "a:s:m:f:t:p:vh?")) != -1) {
                switch (cmd) {
                        case '?':
                        case 'h':
                                printf("Twilio C++ Example Help:\n");
                                printf("-a: Account\t\t"
                                       "(ex: -a \"ACXXXXX\")\n");
                                printf("-s: Auth Token\t\t"
                                       "(ex: -s \"your_token\")\n");
                                printf("-f: From Number\t\t"
                                       "(ex: -f \"+18005551212\")\n");
                                printf("-t: To Number\t\t"
                                       "(ex: -t \"+18005551212\")\n");
                                printf("-m: Message to send\t"
                                       "(ex: -m \"Hello, Twilio!\")\n");
                                printf("-p: (Opt.) URL to Image\t"
                                       "(ex: -p \"Hello, Twilio!\")\n");
                                printf("-v: Verbose Mode\n");
                                printf("-h: This help dialog\n");
                                return 0;
                        case 'a':
                                account_sid = optarg;
                                break;
                        case 's':
                                auth_token = optarg;
                                break;
                        case 'm':
                                message = optarg;
                                break;
                        case 'f':
                                from_number = optarg;
                                break;
                        case 't':
                                to_number = optarg;
                                break;
                        case 'p':
                                picture_url = optarg;
                                break;
                        case 'v':
                                verbose = true;
                                break;
                        default:
                                abort();
                }
        }

        if ( account_sid.empty() or auth_token.empty() or from_number.empty()
                or to_number.empty() or message.empty() ) {
                std::cout<< "You didn't include all necessary inputs!\n"
                        "Call using -h for help.\n" << std::endl;
                return -1;
        }

        // Instantiate a twilio object and call send_message
        std::string response;
        auto twilio = std::make_shared<twilio::Twilio>(
            account_sid, 
            auth_token
        );
        
        bool message_success = twilio->send_message(
                to_number, 
                from_number, 
                message,
                response,
                picture_url,
                verbose
        );

        // Report success or failure
        if (!message_success) {
                if (verbose) {
                        std::cout << "Message send failed." << std::endl;
                        if (!response.empty()) {
                                std::cout << "Response:" << std::endl 
                                        << response << std::endl;
                        }
                }
                return -1;
        } else if (verbose) {
                std::cout << "SMS sent successfully!" << std::endl;
                std::cout << "Response:" << std::endl << response
                        << std::endl;
        }

        return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3160
leaq -0x58(%rbp), %rdi
callq 0x3160
leaq -0x78(%rbp), %rdi
callq 0x3160
leaq -0x98(%rbp), %rdi
callq 0x3160
leaq -0xb8(%rbp), %rdi
callq 0x3160
leaq -0xd8(%rbp), %rdi
callq 0x3160
movb $0x0, -0xd9(%rbp)
movq 0x8ab2(%rip), %rax      # 0xbfc8
movl $0x0, (%rax)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x4bba(%rip), %rdx      # 0x80e4
callq 0x32f0
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0x36d0
movl -0x14(%rbp), %eax
addl $-0x3f, %eax
movl %eax, %ecx
movq %rcx, -0x130(%rbp)
subl $0x37, %eax
ja 0x36c6
movq -0x130(%rbp), %rax
leaq 0x4aa3(%rip), %rcx      # 0x8004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x4b83(%rip), %rdi      # 0x80f4
xorl %eax, %eax
callq 0x3060
jmp 0x357a
leaq 0x4b8d(%rip), %rdi      # 0x810e
xorl %eax, %eax
callq 0x3060
jmp 0x358a
leaq 0x4b9e(%rip), %rdi      # 0x812f
xorl %eax, %eax
callq 0x3060
jmp 0x359a
leaq 0x4bb5(%rip), %rdi      # 0x8156
xorl %eax, %eax
callq 0x3060
jmp 0x35aa
leaq 0x4bcf(%rip), %rdi      # 0x8180
xorl %eax, %eax
callq 0x3060
jmp 0x35ba
leaq 0x4be7(%rip), %rdi      # 0x81a8
xorl %eax, %eax
callq 0x3060
jmp 0x35ca
leaq 0x4c06(%rip), %rdi      # 0x81d7
xorl %eax, %eax
callq 0x3060
jmp 0x35da
leaq 0x4c29(%rip), %rdi      # 0x820a
xorl %eax, %eax
callq 0x3060
jmp 0x35ea
leaq 0x4c2b(%rip), %rdi      # 0x821c
xorl %eax, %eax
callq 0x3060
jmp 0x35fa
movl $0x0, -0x4(%rbp)
movl $0x1, -0xf0(%rbp)
jmp 0x39db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x3a26
movq 0x8982(%rip), %rax      # 0xbfb0
movq (%rax), %rsi
leaq -0x38(%rbp), %rdi
callq 0x3190
jmp 0x363c
jmp 0x36cb
movq 0x8968(%rip), %rax      # 0xbfb0
movq (%rax), %rsi
leaq -0x58(%rbp), %rdi
callq 0x3190
jmp 0x3656
jmp 0x36cb
movq 0x8951(%rip), %rax      # 0xbfb0
movq (%rax), %rsi
leaq -0x78(%rbp), %rdi
callq 0x3190
jmp 0x366d
jmp 0x36cb
movq 0x893a(%rip), %rax      # 0xbfb0
movq (%rax), %rsi
leaq -0x98(%rbp), %rdi
callq 0x3190
jmp 0x3687
jmp 0x36cb
movq 0x8920(%rip), %rax      # 0xbfb0
movq (%rax), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x3190
jmp 0x36a1
jmp 0x36cb
movq 0x8906(%rip), %rax      # 0xbfb0
movq (%rax), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x3190
jmp 0x36bb
jmp 0x36cb
movb $0x1, -0xd9(%rbp)
jmp 0x36cb
callq 0x3260
jmp 0x351c
leaq -0x38(%rbp), %rdi
callq 0x3110
testb $0x1, %al
jne 0x3719
leaq -0x58(%rbp), %rdi
callq 0x3110
testb $0x1, %al
jne 0x3719
leaq -0x98(%rbp), %rdi
callq 0x3110
testb $0x1, %al
jne 0x3719
leaq -0xb8(%rbp), %rdi
callq 0x3110
testb $0x1, %al
jne 0x3719
leaq -0x78(%rbp), %rdi
callq 0x3110
testb $0x1, %al
jne 0x3719
jmp 0x3760
movq 0x8898(%rip), %rdi      # 0xbfb8
leaq 0x4b0b(%rip), %rsi      # 0x8232
callq 0x31f0
movq %rax, -0x138(%rbp)
jmp 0x3735
movq -0x138(%rbp), %rdi
movq 0x8895(%rip), %rsi      # 0xbfd8
callq 0x3330
jmp 0x374a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0xf0(%rbp)
jmp 0x39db
leaq -0x110(%rbp), %rdi
callq 0x3160
leaq -0x120(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x3a80
jmp 0x3782
leaq -0x120(%rbp), %rdi
callq 0x3b00
movq %rax, %rdi
movzbl -0xd9(%rbp), %ecx
andl $0x1, %ecx
movq %rsp, %rax
movl %ecx, (%rax)
leaq -0xb8(%rbp), %rsi
leaq -0x98(%rbp), %rdx
leaq -0x78(%rbp), %rcx
leaq -0x110(%rbp), %r8
leaq -0xd8(%rbp), %r9
callq 0x48c0
movb %al, -0x139(%rbp)
jmp 0x37cd
movb -0x139(%rbp), %al
andb $0x1, %al
movb %al, -0x121(%rbp)
testb $0x1, -0x121(%rbp)
jne 0x38f7
testb $0x1, -0xd9(%rbp)
je 0x38e1
movq 0x87bc(%rip), %rdi      # 0xbfb8
leaq 0x4a71(%rip), %rsi      # 0x8274
callq 0x31f0
movq %rax, -0x148(%rbp)
jmp 0x3811
movq -0x148(%rbp), %rdi
movq 0x87b9(%rip), %rsi      # 0xbfd8
callq 0x3330
jmp 0x3826
leaq -0x110(%rbp), %rdi
callq 0x3110
testb $0x1, %al
jne 0x38df
movq 0x8777(%rip), %rdi      # 0xbfb8
leaq 0x4a41(%rip), %rsi      # 0x8289
callq 0x31f0
movq %rax, -0x150(%rbp)
jmp 0x3856
movq -0x150(%rbp), %rdi
movq 0x8774(%rip), %rsi      # 0xbfd8
callq 0x3330
movq %rax, -0x158(%rbp)
jmp 0x3872
movq -0x158(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x3130
movq %rax, -0x160(%rbp)
jmp 0x388e
movq -0x160(%rbp), %rdi
movq 0x873c(%rip), %rsi      # 0xbfd8
callq 0x3330
jmp 0x38a3
jmp 0x38df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x39cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x3b20
jmp 0x39cd
jmp 0x38e1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0xf0(%rbp)
jmp 0x39b3
testb $0x1, -0xd9(%rbp)
je 0x39a0
movq 0x86ad(%rip), %rdi      # 0xbfb8
leaq 0x4981(%rip), %rsi      # 0x8293
callq 0x31f0
movq %rax, -0x168(%rbp)
jmp 0x3920
movq -0x168(%rbp), %rdi
movq 0x86aa(%rip), %rsi      # 0xbfd8
callq 0x3330
jmp 0x3935
movq 0x867c(%rip), %rdi      # 0xbfb8
leaq 0x4946(%rip), %rsi      # 0x8289
callq 0x31f0
movq %rax, -0x170(%rbp)
jmp 0x3951
movq -0x170(%rbp), %rdi
movq 0x8679(%rip), %rsi      # 0xbfd8
callq 0x3330
movq %rax, -0x178(%rbp)
jmp 0x396d
movq -0x178(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x3130
movq %rax, -0x180(%rbp)
jmp 0x3989
movq -0x180(%rbp), %rdi
movq 0x8641(%rip), %rsi      # 0xbfd8
callq 0x3330
jmp 0x399e
jmp 0x39a0
jmp 0x39a2
movl $0x0, -0x4(%rbp)
movl $0x1, -0xf0(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x3b20
leaq -0x110(%rbp), %rdi
callq 0x3270
jmp 0x39db
leaq -0x110(%rbp), %rdi
callq 0x3270
jmp 0x3a26
leaq -0xd8(%rbp), %rdi
callq 0x3270
leaq -0xb8(%rbp), %rdi
callq 0x3270
leaq -0x98(%rbp), %rdi
callq 0x3270
leaq -0x78(%rbp), %rdi
callq 0x3270
leaq -0x58(%rbp), %rdi
callq 0x3270
leaq -0x38(%rbp), %rdi
callq 0x3270
movl -0x4(%rbp), %eax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
leaq -0xd8(%rbp), %rdi
callq 0x3270
leaq -0xb8(%rbp), %rdi
callq 0x3270
leaq -0x98(%rbp), %rdi
callq 0x3270
leaq -0x78(%rbp), %rdi
callq 0x3270
leaq -0x58(%rbp), %rdi
callq 0x3270
leaq -0x38(%rbp), %rdi
callq 0x3270
movq -0xe8(%rbp), %rdi
callq 0x3220
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)