// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0xb8, %rsp
movq 0x2cdd(%rip), %r14      # 0x3fd8
leaq 0xd8d(%rip), %rsi       # 0x208f
movq %r14, %rdi
callq 0x1060
movq %rax, %rdi
callq 0x1040
leaq 0xd80(%rip), %rsi       # 0x2099
movq %r14, %rdi
callq 0x1060
movq %rax, %rdi
callq 0x1040
leaq 0xd90(%rip), %rsi       # 0x20c0
pushq $0x5d
popq %rcx
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
rep  movsb (%rsi), %es:(%rdi)
pushq $0x5b
popq %rsi
movq %r14, %rdi
callq 0x1080
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1060
pushq $0x5d
popq %rsi
movq %rax, %rdi
callq 0x1080
movq %rax, %rdi
callq 0x1040
leaq 0x30(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %rbx, %rsi
callq 0x1030
leaq 0xcb3(%rip), %rsi       # 0x2032
leaq 0x10(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x1030
leaq 0xd0e(%rip), %rdi       # 0x20a3
leaq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x13e9
leaq 0x10(%rsp), %rdi
callq 0x10c8
leaq 0x30(%rsp), %rdi
callq 0x10c8
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r14
retq
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x10c8
jmp 0x13d7
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x10c8
movq %rbx, %rdi
callq 0x10b0