// File: /workspace/github_c_makefile_star2_O3/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       # 0x198f
movl $0xc, %edi
callq 0x10a0
leaq 0xbe8(%rip), %rdi       # 0x25a5
callq 0x1050
callq 0x121c
leaq 0x2722(%rip), %rdi      # 0x40f0
leaq -0xf0(%rip), %rsi       # 0x18e5
xorl %edx, %edx
callq 0x1528
movl %eax, %ebx
movq 0x270b(%rip), %rdi      # 0x40f0
leaq -0x10(%rbp), %rsi
callq 0x1677
orl %ebx, %eax
jne 0x1a01
cmpl $0x64, -0x10(%rbp)
jne 0x1a0f
leaq 0x6d6(%rip), %rdi       # 0x20d5
jmp 0x1a16
leaq 0xbf2(%rip), %rdi       # 0x25fa
callq 0x1050
jmp 0x1a1d
leaq 0x675(%rip), %rdi       # 0x208b
xorl %eax, %eax
callq 0x1080
leaq 0x26d4(%rip), %rdi      # 0x40f8
leaq -0x146(%rip), %rsi      # 0x18e5
xorl %edx, %edx
callq 0x1528
movl %eax, %ebx
leaq -0x10(%rbp), %rsi
movl $0x19, %edi
callq 0x1677
testl %ebx, %ebx
jne 0x1a62
cmpl $0x3, %eax
leaq 0x708(%rip), %rax       # 0x2158
leaq 0x6c8(%rip), %rdi       # 0x211f
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x26b7(%rip), %rdi      # 0x4120
leaq -0x180(%rip), %rsi      # 0x18f0
movl $0x4, %edx
callq 0x1528
movl %eax, %ebx
movq 0x269d(%rip), %rdi      # 0x4120
leaq -0x10(%rbp), %rsi
callq 0x1677
orl %ebx, %eax
jne 0x1aad
cmpl $0x10, -0x10(%rbp)
leaq 0x746(%rip), %rax       # 0x21e1
leaq 0x6ef(%rip), %rdi       # 0x2191
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
movq 0x263c(%rip), %rdi      # 0x40f0
xorl %esi, %esi
callq 0x1677
cmpl $0x16, %eax
leaq 0x7ac(%rip), %rax       # 0x2271
leaq 0x765(%rip), %rdi       # 0x2231
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x2622(%rip), %rdi      # 0x4100
leaq -0x1e9(%rip), %rsi      # 0x18fc
xorl %edx, %edx
callq 0x1528
leaq 0x2615(%rip), %rdi      # 0x4108
leaq -0x1c2(%rip), %rsi      # 0x1938
xorl %edx, %edx
callq 0x1528
movl %eax, %ebx
movq 0x25fe(%rip), %rdi      # 0x4108
leaq -0x10(%rbp), %rsi
callq 0x1677
testl %ebx, %ebx
jne 0x1b34
cmpl $0x64, -0x10(%rbp)
leaq 0x7c6(%rip), %rax       # 0x22e8
leaq 0x788(%rip), %rdi       # 0x22b1
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x25d5(%rip), %rdi      # 0x4110
leaq -0x1f8(%rip), %rsi      # 0x194a
xorl %edx, %edx
callq 0x1528
movl %eax, %ebx
movq 0x25be(%rip), %rdi      # 0x4110
leaq -0x10(%rbp), %rsi
callq 0x1677
testl %ebx, %ebx
jne 0x1b7f
cmpl $0x1, 0x25da(%rip)      # 0x4140
leaq 0x80c(%rip), %rax       # 0x2379
leaq 0x7ab(%rip), %rdi       # 0x231f
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x259a(%rip), %rdi      # 0x4120
leaq -0x222(%rip), %rsi      # 0x196b
xorl %edx, %edx
callq 0x1528
movl %eax, %ebx
movq 0x2583(%rip), %rdi      # 0x4120
movl $0xc, %esi
callq 0x16ff
movq 0x2572(%rip), %rdi      # 0x4120
leaq -0x10(%rbp), %rsi
callq 0x1677
testl %ebx, %ebx
jne 0x1bd8
cmpl $0x2a, -0x10(%rbp)
leaq 0x852(%rip), %rax       # 0x2418
leaq 0x806(%rip), %rdi       # 0x23d3
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
leaq 0x2539(%rip), %rdi      # 0x4118
leaq -0x281(%rip), %rsi      # 0x1965
xorl %edx, %edx
callq 0x1528
movl %eax, %ebx
movq 0x2522(%rip), %rdi      # 0x4118
movl $0xffffffec, %esi       # imm = 0xFFFFFFEC
callq 0x16ff
testl %ebx, %ebx
je 0x1c26
movl $0x22, %edi
movl $0xa, %esi
callq 0x16ff
movq 0x24fe(%rip), %rdi      # 0x4118
movl $0x9, %esi
callq 0x16ff
jmp 0x1c99
cmpl $0x16, %eax
leaq 0x85f(%rip), %rax       # 0x248f
leaq 0x826(%rip), %rdi       # 0x245d
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
movl $0x22, %edi
movl $0xa, %esi
callq 0x16ff
cmpl $0x3, %eax
leaq 0x8a3(%rip), %rax       # 0x24fe
leaq 0x85f(%rip), %rdi       # 0x24c1
cmoveq %rax, %rdi
xorl %eax, %eax
callq 0x1080
movq 0x24a4(%rip), %rdi      # 0x4118
movl $0x9, %esi
callq 0x16ff
testl %eax, %eax
je 0x1c8b
leaq 0x8b2(%rip), %rdi       # 0x253b
jmp 0x1c92
leaq 0x8de(%rip), %rdi       # 0x2570
xorl %eax, %eax
callq 0x1080
leaq 0x989(%rip), %rdi       # 0x2629
callq 0x1050
movq 0x246c(%rip), %rdi      # 0x4118
leaq -0x10(%rbp), %rsi
callq 0x1677
xorl %edi, %edi
callq 0x16de
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop