// File: /workspace/github_c_makefile_star2_O2/deepika9294[P]Threading-Library/many-one/test/methods.c
// Function: main
int main() {

    //for getting return values
    void *tret;
    signal(SIGUSR2, signal_handler);
    printf("\n\n-----------------ALL THE METHODS TESTING (CREATE, JOIN, EXIT, KILL)--------------\n\n");
	dthread_init();

	int c1 = dthread_create( &t1[0], add , NULL);
    int j1 = dthread_join(t1[0], &tret);
    if( c1 == 0 && j1 == 0 ) {
        check = testing((intptr_t)tret, 100);
        if(check == 0) {
            printf(RED "**FAILED**: Addition test with create and join return value\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Addition test with create and join return value\n" NONE);
        }
    }
    else {
        printf("*****Issue in creating or joining thread *****\n");
    }

    c1 = dthread_create( &t1[1], add , NULL);
    j1 = dthread_join(25, &tret);
    if(c1 == 0) {
       check = testing(j1,ESRCH);
       if(check == 0) {
            printf(RED "**FAILED**: Joining an invalid thread test\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Joining an invalid thread test\n" NONE);
        }
    }
    c1 = dthread_create( &t1[6], square, (void *)(intptr_t)(4));
    j1 = dthread_join(t1[6], &tret);
    if(c1 == 0 && j1 == 0) {
        check = testing((intptr_t)tret, 16);
        if(check == 0) {
            printf(RED "**FAILED**: Creating threads with args and join return value test\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Creating threads with args and join return value test\n" NONE);
        }
    }

    j1 = dthread_join(t1[0], NULL);
    check = testing(j1, EINVAL);
    if(check == 0) {
        printf(RED "**FAILED**: Joining on already joined thread test\n" NONE);
    }
    else {
        printf(GREEN "**PASSED**: Joining on already joined thread test\n" NONE);
    }

    c1 = dthread_create( &t1[2], deadlock , NULL);

    
    c1 = dthread_create( &t1[3], exit_test, NULL);
    j1 = dthread_join(t1[3], &tret);

    if(c1 == 0) {
        check = testing((intptr_t)tret, 100);
        if(check == 0) {
            printf(RED "**FAILED**: Thread exit test with retval\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Thread exit test with retval\n" NONE);
        }
    }
    
    c1 = dthread_create( &t1[4], exit_control, NULL);
    j1 = dthread_join(t1[4], &tret);
    if(c1 == 0) {
        check = testing(counter, 1);
        if(check == 0) {
            printf(RED "**FAILED**: Thread exit test, i.e rest of the instructions are not executed\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Thread exit test, i.e rest of the instructions are not executed\n" NONE);
        }
    }

    c1 = dthread_create( &t1[6], sig_loop, NULL);
    int s = dthread_kill(t1[6], SIGUSR2);
    dthread_join(t1[6],&tret);

    if(c1 == 0) {
        check = testing((intptr_t)tret, 42);
        if(check == 0) {
            printf(RED "**FAILED**: Signal Handler test case for infinite loop\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Signal Handler test case for infinite loop\n" NONE);
        }
    }


    c1 = dthread_create( &t1[5], looping, NULL);
    int k = dthread_kill(t1[5], -20);
    if(c1 == 0) {
        check = testing(k, EINVAL);
        if(check == 0) {
            printf(RED "**FAILED**: Invalid Signal No. Test\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Invalid Signal No. Test\n" NONE);
        }
    }
    k = dthread_kill(34, SIGUSR1);
    if(c1 == 0) {
        check = testing(k, ESRCH);
        if(check == 0) {
            printf(RED "**FAILED**: Thread kill test on invalid thread\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Thread kill test on invalid thread\n" NONE);
        }
    }
    k = dthread_kill(t1[5], SIGKILL);
    if(c1 == 0) {
        check = testing(k, 0);
        if(check == 0) {
            printf(RED "**FAILED**: Valid Signal Test: SIGKILL\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Valid Signal Test: SIGKILL\n" NONE);
        }
    }
    printf("\n--------------------------------EXITING METHODS TEST--------------------------------\n\n");

    j1 = dthread_join(t1[5], &tret);

    
    dthread_exit(NULL);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
leaq -0x1a(%rip), %rsi       # 0x18f7
pushq $0xc
popq %rdi
callq 0x10a0
leaq 0xc85(%rip), %rdi       # 0x25a5
callq 0x1050
callq 0x121c
leaq 0x27bf(%rip), %rdi      # 0x40f0
leaq -0xf3(%rip), %rsi       # 0x1845
xorl %edx, %edx
callq 0x14ca
movl %eax, %ebx
movq 0x27a8(%rip), %rdi      # 0x40f0
leaq -0x10(%rbp), %rsi
callq 0x15e3
orl %ebx, %eax
jne 0x1964
cmpl $0x64, -0x10(%rbp)
jne 0x1972
leaq 0x773(%rip), %rdi       # 0x20d5
jmp 0x1979
leaq 0xc8f(%rip), %rdi       # 0x25fa
callq 0x1050
jmp 0x1980
leaq 0x712(%rip), %rdi       # 0x208b
xorl %eax, %eax
callq 0x1080
leaq 0x2771(%rip), %rdi      # 0x40f8
leaq -0x149(%rip), %rsi      # 0x1845
xorl %edx, %edx
callq 0x14ca
movl %eax, %ebx
pushq $0x19
popq %rdi
leaq -0x10(%rbp), %rsi
callq 0x15e3
testl %ebx, %ebx
jne 0x19c3
cmpl $0x3, %eax
leaq 0x7a7(%rip), %rax       # 0x2158
leaq 0x767(%rip), %rdi       # 0x211f
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x2756(%rip), %rdi      # 0x4120
leaq -0x17c(%rip), %rsi      # 0x1855
pushq $0x4
popq %rdx
callq 0x14ca
movl %eax, %ebx
movq 0x273e(%rip), %rdi      # 0x4120
leaq -0x10(%rbp), %rsi
callq 0x15e3
orl %ebx, %eax
jne 0x1a0c
cmpl $0x10, -0x10(%rbp)
leaq 0x7e7(%rip), %rax       # 0x21e1
leaq 0x790(%rip), %rdi       # 0x2191
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
movq 0x26dd(%rip), %rdi      # 0x40f0
xorl %esi, %esi
callq 0x15e3
cmpl $0x16, %eax
leaq 0x84d(%rip), %rax       # 0x2271
leaq 0x806(%rip), %rdi       # 0x2231
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x26c3(%rip), %rdi      # 0x4100
leaq -0x1e3(%rip), %rsi      # 0x1861
xorl %edx, %edx
callq 0x14ca
leaq 0x26b6(%rip), %rdi      # 0x4108
leaq -0x1bc(%rip), %rsi      # 0x189d
xorl %edx, %edx
callq 0x14ca
movl %eax, %ebx
movq 0x269f(%rip), %rdi      # 0x4108
leaq -0x10(%rbp), %rsi
callq 0x15e3
testl %ebx, %ebx
jne 0x1a93
cmpl $0x64, -0x10(%rbp)
leaq 0x867(%rip), %rax       # 0x22e8
leaq 0x829(%rip), %rdi       # 0x22b1
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x2676(%rip), %rdi      # 0x4110
leaq -0x1f4(%rip), %rsi      # 0x18ad
xorl %edx, %edx
callq 0x14ca
movl %eax, %ebx
movq 0x265f(%rip), %rdi      # 0x4110
leaq -0x10(%rbp), %rsi
callq 0x15e3
testl %ebx, %ebx
jne 0x1ade
cmpl $0x1, 0x267b(%rip)      # 0x4140
leaq 0x8ad(%rip), %rax       # 0x2379
leaq 0x84c(%rip), %rdi       # 0x231f
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x263b(%rip), %rdi      # 0x4120
leaq -0x21e(%rip), %rsi      # 0x18ce
xorl %edx, %edx
callq 0x14ca
movl %eax, %ebx
movq 0x2624(%rip), %rdi      # 0x4120
pushq $0xc
popq %rsi
callq 0x1667
movq 0x2615(%rip), %rdi      # 0x4120
leaq -0x10(%rbp), %rsi
callq 0x15e3
testl %ebx, %ebx
jne 0x1b35
cmpl $0x2a, -0x10(%rbp)
leaq 0x8f5(%rip), %rax       # 0x2418
leaq 0x8a9(%rip), %rdi       # 0x23d3
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x25dc(%rip), %rdi      # 0x4118
leaq -0x27b(%rip), %rsi      # 0x18c8
xorl %edx, %edx
callq 0x14ca
movl %eax, %ebx
movq 0x25c5(%rip), %rdi      # 0x4118
pushq $-0x14
popq %rsi
callq 0x1667
testl %ebx, %ebx
jne 0x1b7b
cmpl $0x16, %eax
leaq 0x926(%rip), %rax       # 0x248f
leaq 0x8ed(%rip), %rdi       # 0x245d
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
pushq $0x22
popq %rdi
pushq $0xa
popq %rsi
callq 0x1667
testl %ebx, %ebx
jne 0x1ba6
cmpl $0x3, %eax
leaq 0x96a(%rip), %rax       # 0x24fe
leaq 0x926(%rip), %rdi       # 0x24c1
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
movq 0x256b(%rip), %rdi      # 0x4118
pushq $0x9
popq %rsi
callq 0x1667
testl %ebx, %ebx
jne 0x1bd4
testl %eax, %eax
leaq 0x9ae(%rip), %rax       # 0x2570
leaq 0x972(%rip), %rdi       # 0x253b
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0xa4e(%rip), %rdi       # 0x2629
callq 0x1050
movq 0x2531(%rip), %rdi      # 0x4118
leaq -0x10(%rbp), %rsi
callq 0x15e3
xorl %edi, %edi
callq 0x1646
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq