// File: /workspace/github_c_makefile_star2_O1/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 -0x1d(%rip), %rsi       # 0x1987
movl $0xc, %edi
callq 0x10a0
leaq 0xbf0(%rip), %rdi       # 0x25a5
callq 0x1050
callq 0x121c
leaq 0x272a(%rip), %rdi      # 0x40f0
leaq -0xf0(%rip), %rsi       # 0x18dd
xorl %edx, %edx
callq 0x1525
movl %eax, %ebx
movq 0x2713(%rip), %rdi      # 0x40f0
leaq -0x10(%rbp), %rsi
callq 0x166e
orl %ebx, %eax
jne 0x19f9
cmpl $0x64, -0x10(%rbp)
jne 0x1a07
leaq 0x6de(%rip), %rdi       # 0x20d5
jmp 0x1a0e
leaq 0xbfa(%rip), %rdi       # 0x25fa
callq 0x1050
jmp 0x1a15
leaq 0x67d(%rip), %rdi       # 0x208b
xorl %eax, %eax
callq 0x1080
leaq 0x26dc(%rip), %rdi      # 0x40f8
leaq -0x146(%rip), %rsi      # 0x18dd
xorl %edx, %edx
callq 0x1525
movl %eax, %ebx
leaq -0x10(%rbp), %rsi
movl $0x19, %edi
callq 0x166e
testl %ebx, %ebx
jne 0x1a5a
cmpl $0x3, %eax
leaq 0x710(%rip), %rax       # 0x2158
leaq 0x6d0(%rip), %rdi       # 0x211f
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x26bf(%rip), %rdi      # 0x4120
leaq -0x180(%rip), %rsi      # 0x18e8
movl $0x4, %edx
callq 0x1525
movl %eax, %ebx
movq 0x26a5(%rip), %rdi      # 0x4120
leaq -0x10(%rbp), %rsi
callq 0x166e
orl %ebx, %eax
jne 0x1aa5
cmpl $0x10, -0x10(%rbp)
leaq 0x74e(%rip), %rax       # 0x21e1
leaq 0x6f7(%rip), %rdi       # 0x2191
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
movq 0x2644(%rip), %rdi      # 0x40f0
xorl %esi, %esi
callq 0x166e
cmpl $0x16, %eax
leaq 0x7b4(%rip), %rax       # 0x2271
leaq 0x76d(%rip), %rdi       # 0x2231
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x262a(%rip), %rdi      # 0x4100
leaq -0x1e9(%rip), %rsi      # 0x18f4
xorl %edx, %edx
callq 0x1525
leaq 0x261d(%rip), %rdi      # 0x4108
leaq -0x1c2(%rip), %rsi      # 0x1930
xorl %edx, %edx
callq 0x1525
movl %eax, %ebx
movq 0x2606(%rip), %rdi      # 0x4108
leaq -0x10(%rbp), %rsi
callq 0x166e
testl %ebx, %ebx
jne 0x1b2c
cmpl $0x64, -0x10(%rbp)
leaq 0x7ce(%rip), %rax       # 0x22e8
leaq 0x790(%rip), %rdi       # 0x22b1
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x25dd(%rip), %rdi      # 0x4110
leaq -0x1f8(%rip), %rsi      # 0x1942
xorl %edx, %edx
callq 0x1525
movl %eax, %ebx
movq 0x25c6(%rip), %rdi      # 0x4110
leaq -0x10(%rbp), %rsi
callq 0x166e
testl %ebx, %ebx
jne 0x1b77
cmpl $0x1, 0x25e2(%rip)      # 0x4140
leaq 0x814(%rip), %rax       # 0x2379
leaq 0x7b3(%rip), %rdi       # 0x231f
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x25a2(%rip), %rdi      # 0x4120
leaq -0x222(%rip), %rsi      # 0x1963
xorl %edx, %edx
callq 0x1525
movl %eax, %ebx
movq 0x258b(%rip), %rdi      # 0x4120
movl $0xc, %esi
callq 0x16f6
movq 0x257a(%rip), %rdi      # 0x4120
leaq -0x10(%rbp), %rsi
callq 0x166e
testl %ebx, %ebx
jne 0x1bd0
cmpl $0x2a, -0x10(%rbp)
leaq 0x85a(%rip), %rax       # 0x2418
leaq 0x80e(%rip), %rdi       # 0x23d3
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x2541(%rip), %rdi      # 0x4118
leaq -0x281(%rip), %rsi      # 0x195d
xorl %edx, %edx
callq 0x1525
movl %eax, %ebx
movq 0x252a(%rip), %rdi      # 0x4118
movl $0xffffffec, %esi       # imm = 0xFFFFFFEC
callq 0x16f6
testl %ebx, %ebx
jne 0x1c18
cmpl $0x16, %eax
leaq 0x889(%rip), %rax       # 0x248f
leaq 0x850(%rip), %rdi       # 0x245d
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
movl $0x22, %edi
movl $0xa, %esi
callq 0x16f6
testl %ebx, %ebx
jne 0x1c47
cmpl $0x3, %eax
leaq 0x8c9(%rip), %rax       # 0x24fe
leaq 0x885(%rip), %rdi       # 0x24c1
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
movq 0x24ca(%rip), %rdi      # 0x4118
movl $0x9, %esi
callq 0x16f6
testl %ebx, %ebx
jne 0x1c77
testl %eax, %eax
leaq 0x90b(%rip), %rax       # 0x2570
leaq 0x8cf(%rip), %rdi       # 0x253b
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x9ab(%rip), %rdi       # 0x2629
callq 0x1050
movq 0x248e(%rip), %rdi      # 0x4118
leaq -0x10(%rbp), %rsi
callq 0x166e
xorl %edi, %edi
callq 0x16d5
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)