// File: /workspace/github_c_makefile_star2_O0/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
subq $0x20, %rsp
movl $0x0, -0x4(%rbp)
movl $0xc, %edi
leaq -0x3b(%rip), %rsi       # 0x1e00
callq 0x1090
leaq 0x1244(%rip), %rdi      # 0x308b
movb $0x0, %al
callq 0x1070
callq 0x1220
leaq 0x3296(%rip), %rdi      # 0x50f0
leaq -0x1c1(%rip), %rsi      # 0x1ca0
xorl %eax, %eax
movl %eax, %edx
callq 0x1640
movl %eax, -0x14(%rbp)
movq 0x327c(%rip), %rdi      # 0x50f0
leaq -0x10(%rbp), %rsi
callq 0x1800
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x1ecb
cmpl $0x0, -0x18(%rbp)
jne 0x1ecb
movq -0x10(%rbp), %rax
movl %eax, %edi
movl $0x64, %esi
callq 0x1c70
movl %eax, 0x329e(%rip)      # 0x5140
cmpl $0x0, 0x3297(%rip)      # 0x5140
jne 0x1ebb
leaq 0x122f(%rip), %rdi      # 0x30e1
movb $0x0, %al
callq 0x1070
jmp 0x1ec9
leaq 0x1269(%rip), %rdi      # 0x312b
movb $0x0, %al
callq 0x1070
jmp 0x1ed9
leaq 0x12a3(%rip), %rdi      # 0x3175
movb $0x0, %al
callq 0x1070
leaq 0x3210(%rip), %rdi      # 0x50f0
addq $0x8, %rdi
leaq -0x24b(%rip), %rsi      # 0x1ca0
xorl %eax, %eax
movl %eax, %edx
callq 0x1640
movl %eax, -0x14(%rbp)
movl $0x19, %edi
leaq -0x10(%rbp), %rsi
callq 0x1800
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x1f4a
movl -0x18(%rbp), %edi
movl $0x3, %esi
callq 0x1c70
movl %eax, 0x321f(%rip)      # 0x5140
cmpl $0x0, 0x3218(%rip)      # 0x5140
jne 0x1f3a
leaq 0x1274(%rip), %rdi      # 0x31a5
movb $0x0, %al
callq 0x1070
jmp 0x1f48
leaq 0x129d(%rip), %rdi      # 0x31de
movb $0x0, %al
callq 0x1070
jmp 0x1f4a
leaq 0x319f(%rip), %rdi      # 0x50f0
addq $0x30, %rdi
leaq -0x29c(%rip), %rsi      # 0x1cc0
movl $0x4, %edx
callq 0x1640
movl %eax, -0x14(%rbp)
movq 0x31b0(%rip), %rdi      # 0x5120
leaq -0x10(%rbp), %rsi
callq 0x1800
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x1fc7
cmpl $0x0, -0x18(%rbp)
jne 0x1fc7
movq -0x10(%rbp), %rax
movl %eax, %edi
movl $0x10, %esi
callq 0x1c70
movl %eax, 0x31a2(%rip)      # 0x5140
cmpl $0x0, 0x319b(%rip)      # 0x5140
jne 0x1fb7
leaq 0x1269(%rip), %rdi      # 0x3217
movb $0x0, %al
callq 0x1070
jmp 0x1fc5
leaq 0x12a9(%rip), %rdi      # 0x3267
movb $0x0, %al
callq 0x1070
jmp 0x1fc7
movq 0x3122(%rip), %rdi      # 0x50f0
xorl %eax, %eax
movl %eax, %esi
callq 0x1800
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %edi
movl $0x16, %esi
callq 0x1c70
movl %eax, 0x3153(%rip)      # 0x5140
cmpl $0x0, 0x314c(%rip)      # 0x5140
jne 0x2006
leaq 0x12ba(%rip), %rdi      # 0x32b7
movb $0x0, %al
callq 0x1070
jmp 0x2014
leaq 0x12ea(%rip), %rdi      # 0x32f7
movb $0x0, %al
callq 0x1070
leaq 0x30d5(%rip), %rdi      # 0x50f0
addq $0x10, %rdi
leaq -0x346(%rip), %rsi      # 0x1ce0
xorl %eax, %eax
movl %eax, %edx
callq 0x1640
movl %eax, -0x14(%rbp)
leaq 0x30b7(%rip), %rdi      # 0x50f0
addq $0x18, %rdi
leaq -0x2f4(%rip), %rsi      # 0x1d50
xorl %eax, %eax
movl %eax, %edx
callq 0x1640
movl %eax, -0x14(%rbp)
movq 0x30b1(%rip), %rdi      # 0x5108
leaq -0x10(%rbp), %rsi
callq 0x1800
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x20a8
movq -0x10(%rbp), %rax
movl %eax, %edi
movl $0x64, %esi
callq 0x1c70
movl %eax, 0x30c1(%rip)      # 0x5140
cmpl $0x0, 0x30ba(%rip)      # 0x5140
jne 0x2098
leaq 0x12a8(%rip), %rdi      # 0x3337
movb $0x0, %al
callq 0x1070
jmp 0x20a6
leaq 0x12cf(%rip), %rdi      # 0x336e
movb $0x0, %al
callq 0x1070
jmp 0x20a8
leaq 0x3041(%rip), %rdi      # 0x50f0
addq $0x20, %rdi
leaq -0x34a(%rip), %rsi      # 0x1d70
xorl %eax, %eax
movl %eax, %edx
callq 0x1640
movl %eax, -0x14(%rbp)
movq 0x3043(%rip), %rdi      # 0x5110
leaq -0x10(%rbp), %rsi
callq 0x1800
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x211e
movl 0x305f(%rip), %edi      # 0x5144
movl $0x1, %esi
callq 0x1c70
movl %eax, 0x304b(%rip)      # 0x5140
cmpl $0x0, 0x3044(%rip)      # 0x5140
jne 0x210e
leaq 0x12a0(%rip), %rdi      # 0x33a5
movb $0x0, %al
callq 0x1070
jmp 0x211c
leaq 0x12ea(%rip), %rdi      # 0x33ff
movb $0x0, %al
callq 0x1070
jmp 0x211e
leaq 0x2fcb(%rip), %rdi      # 0x50f0
addq $0x30, %rdi
leaq -0x370(%rip), %rsi      # 0x1dc0
xorl %eax, %eax
movl %eax, %edx
callq 0x1640
movl %eax, -0x14(%rbp)
movq 0x2fdd(%rip), %rdi      # 0x5120
movl $0xc, %esi
callq 0x18e0
movl %eax, -0x1c(%rbp)
movq 0x2fc9(%rip), %rdi      # 0x5120
leaq -0x10(%rbp), %rsi
callq 0x1800
cmpl $0x0, -0x14(%rbp)
jne 0x21a5
movq -0x10(%rbp), %rax
movl %eax, %edi
movl $0x2a, %esi
callq 0x1c70
movl %eax, 0x2fc4(%rip)      # 0x5140
cmpl $0x0, 0x2fbd(%rip)      # 0x5140
jne 0x2195
leaq 0x12cd(%rip), %rdi      # 0x3459
movb $0x0, %al
callq 0x1070
jmp 0x21a3
leaq 0x1302(%rip), %rdi      # 0x349e
movb $0x0, %al
callq 0x1070
jmp 0x21a5
leaq 0x2f44(%rip), %rdi      # 0x50f0
addq $0x28, %rdi
leaq -0x407(%rip), %rsi      # 0x1db0
xorl %eax, %eax
movl %eax, %edx
callq 0x1640
movl %eax, -0x14(%rbp)
movq 0x2f4e(%rip), %rdi      # 0x5118
movl $0xffffffec, %esi       # imm = 0xFFFFFFEC
callq 0x18e0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x2219
movl -0x20(%rbp), %edi
movl $0x16, %esi
callq 0x1c70
movl %eax, 0x2f50(%rip)      # 0x5140
cmpl $0x0, 0x2f49(%rip)      # 0x5140
jne 0x2209
leaq 0x12e3(%rip), %rdi      # 0x34e3
movb $0x0, %al
callq 0x1070
jmp 0x2217
leaq 0x1305(%rip), %rdi      # 0x3515
movb $0x0, %al
callq 0x1070
jmp 0x2219
movl $0x22, %edi
movl $0xa, %esi
callq 0x18e0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x226d
movl -0x20(%rbp), %edi
movl $0x3, %esi
callq 0x1c70
movl %eax, 0x2efc(%rip)      # 0x5140
cmpl $0x0, 0x2ef5(%rip)      # 0x5140
jne 0x225d
leaq 0x12f3(%rip), %rdi      # 0x3547
movb $0x0, %al
callq 0x1070
jmp 0x226b
leaq 0x1320(%rip), %rdi      # 0x3584
movb $0x0, %al
callq 0x1070
jmp 0x226d
movq 0x2ea4(%rip), %rdi      # 0x5118
movl $0x9, %esi
callq 0x18e0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x22c0
movl -0x20(%rbp), %edi
xorl %esi, %esi
callq 0x1c70
movl %eax, 0x2ea9(%rip)      # 0x5140
cmpl $0x0, 0x2ea2(%rip)      # 0x5140
jne 0x22b0
leaq 0x131a(%rip), %rdi      # 0x35c1
movb $0x0, %al
callq 0x1070
jmp 0x22be
leaq 0x133f(%rip), %rdi      # 0x35f6
movb $0x0, %al
callq 0x1070
jmp 0x22c0
leaq 0x1364(%rip), %rdi      # 0x362b
movb $0x0, %al
callq 0x1070
movq 0x2e43(%rip), %rdi      # 0x5118
leaq -0x10(%rbp), %rsi
callq 0x1800
movl %eax, -0x18(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x18a0
xorl %eax, %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)