// File: /workspace/github_cpp_makefile_star2_O1/PrzemekWirkus[P]functional-workshop/src/bind.cpp
// Function: main
int main(int argc, char *argv[]) {

    // ### Task 1 ###
    // Create 'printf_complex' function which will print pair of integers as in was complex number.
    //
    //      int printf_complex(const char* format, int, int);
    //
    // Note: you can use std::printf function as stub to create your own printf version
    //
    //      int printf( const char* format, ... );
    //
    // Note: you can use auto feature to declare function type
    //
    // Example:
    //
    //      print_complex(-3, 3);   // prints: (-3, 3)
    //      print_complex(0, 0);    // prints: (0, 0)

    cout << "Task 1..." << endl;
    //std::function<int(int, int)> printf_complex = bind(printf, "(%d, %d)", _1, _2);
    /** UNCOMMENT TASK 1
    auto printf_complex = // TODO: bind(... ;
    printf_complex(-3, 3);
    printf_complex(0, 0);
    cout << endl;
    UNCOMMENT */


    // ############################################################################################


    // ### Task 2 ###
    // Create memset's specialization called 'strsetspace' which will replace all characters
    // in string with space character ' '.
    // Example:  "hello world!" -> strsetspace -> "            "
    //
    // Note: In your code developers were using this below simple code to do this task.
    //
    //      memset(str, ' ', strlen(str));  // void * memset ( void * ptr, int value, size_t num );
    //
    // we can replace with below equivalent:
    //
    // strsetspace(str);

    cout << "Task 2..." << endl;
    char str[] = "ARM Holdings plc (ARM) is a British multinational semiconductor and software design company.";
    cout << '[' << str << ']' << endl;

    /** UNCOMMENT TASK 2
    auto strsetspace = // TODO: bind(...
    strsetspace(str);   // Execute new function

    cout << '[' << str << ']' << endl;
    UNCOMMENT */

    CHECK_EQUAL("Task 2 : ",
        string(str),
        string("                                                                                            "));

    return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0xb0, %rsp
movq 0x2b7d(%rip), %rbx      # 0x3fd8
leaq 0xc2d(%rip), %rsi       # 0x208f
movl $0x9, %edx
movq %rbx, %rdi
callq 0x10c0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1050
leaq 0xbfc(%rip), %rsi       # 0x2099
movl $0x9, %edx
movq %rbx, %rdi
callq 0x10c0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1050
leaq 0xc18(%rip), %rsi       # 0x20f0
leaq 0x50(%rsp), %r14
movl $0xb, %ecx
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
movb $0x0, 0x5c(%r14)
movl $0x2e796e61, 0x58(%r14) # imm = 0x2E796E61
leaq 0xf(%rsp), %r15
movb $0x5b, (%r15)
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x10c0
movq %rax, %rbx
movq %r14, %rdi
callq 0x1040
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x10c0
movb $0x5d, (%r15)
leaq 0xf(%rsp), %rsi
movl $0x1, %edx
movq %rbx, %rdi
callq 0x10c0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1050
leaq 0x40(%rsp), %r15
movq %r15, -0x10(%r15)
movq %r14, %rdi
callq 0x1040
leaq (%rsp,%rax), %rdx
addq $0x50, %rdx
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x17d0
leaq 0x20(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xa95(%rip), %rsi       # 0x2032
leaq 0xaea(%rip), %rdx       # 0x208e
leaq 0x10(%rsp), %rdi
callq 0x17d0
leaq 0xaee(%rip), %rdi       # 0x20a3
leaq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x161f
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x15d3
callq 0x1090
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x15e2
callq 0x1090
xorl %eax, %eax
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x1608
callq 0x1090
jmp 0x1608
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x1617
callq 0x1090
movq %rbx, %rdi
callq 0x1100