// File: 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 %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x2c08(%rip), %rdi      # 0x3fd8
movq %rdi, -0xf0(%rbp)
leaq 0xcb1(%rip), %rsi       # 0x208f
callq 0x1070
movq %rax, %rdi
movq 0x2bd3(%rip), %rsi      # 0x3fc0
movq %rsi, -0xe8(%rbp)
callq 0x1080
movq -0xf0(%rbp), %rdi
leaq 0xc92(%rip), %rsi       # 0x2099
callq 0x1070
movq -0xe8(%rbp), %rsi
movq %rax, %rdi
callq 0x1080
movq -0xf0(%rbp), %rdi
movups 0xce4(%rip), %xmm0      # 0x210d
movups %xmm0, -0x23(%rbp)
movaps 0xccc(%rip), %xmm0      # 0x2100
movaps %xmm0, -0x30(%rbp)
movaps 0xcb1(%rip), %xmm0      # 0x20f0
movaps %xmm0, -0x40(%rbp)
movaps 0xc96(%rip), %xmm0      # 0x20e0
movaps %xmm0, -0x50(%rbp)
movaps 0xc7b(%rip), %xmm0      # 0x20d0
movaps %xmm0, -0x60(%rbp)
movaps 0xc60(%rip), %xmm0      # 0x20c0
movaps %xmm0, -0x70(%rbp)
movl $0x5b, %esi
callq 0x10a0
movq %rax, %rdi
leaq -0x70(%rbp), %rsi
movq %rsi, -0xe0(%rbp)
callq 0x1070
movq %rax, %rdi
movl $0x5d, %esi
callq 0x10a0
movq -0xe8(%rbp), %rsi
movq %rax, %rdi
callq 0x1080
leaq -0x91(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x10f0
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
leaq -0x90(%rbp), %rdi
callq 0x10b0
jmp 0x14cc
leaq -0xc9(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x10f0
movq -0xf8(%rbp), %rdx
leaq 0xb45(%rip), %rsi       # 0x2032
leaq -0xc8(%rbp), %rdi
callq 0x10b0
jmp 0x14fb
leaq 0xba1(%rip), %rdi       # 0x20a3
leaq -0x90(%rbp), %rsi
leaq -0xc8(%rbp), %rdx
callq 0x15d0
jmp 0x1517
leaq -0xc8(%rbp), %rdi
callq 0x1108
leaq -0xc9(%rbp), %rdi
callq 0x1090
leaq -0x90(%rbp), %rdi
callq 0x1108
leaq -0x91(%rbp), %rdi
callq 0x1090
xorl %eax, %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x15b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x1598
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x1108
leaq -0xc9(%rbp), %rdi
callq 0x1090
leaq -0x90(%rbp), %rdi
callq 0x1108
leaq -0x91(%rbp), %rdi
callq 0x1090
movq -0xa0(%rbp), %rdi
callq 0x10e0
nopl (%rax,%rax)