// File: /workspace/github_c_makefile_star2_O2/JimKent[P]linearSat/lib/errabort.c
// Function: getThreadVars
static struct perThreadAbortVars *getThreadVars()
/* Return a pointer to the perThreadAbortVars for the current pthread. */
{
pthread_t pid = pthread_self(); //  can be a pointer or a number
// Don't safef, theoretically that could abort.
char pidStr[64];
snprintf(pidStr, sizeof(pidStr), "%lld",  ptrToLL(pid));
pidStr[ArraySize(pidStr)-1] = '\0';

static char pidInUse[64] = "";  // use a string since there is no known unused value for pthread_t variable
if (sameString(pidStr, pidInUse)) // avoid deadlock on self
    {  // this only happens when it has aborted already due to out of memory
       // which should be a rare occurrence.
    char *errMsg = "errAbort re-entered due to out-of-memory condition. Exiting.";
    write(STDERR_FILENO, errMsg, strlen(errMsg)); 
    exit(1);
    }

static pthread_mutex_t ptavMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock( &ptavMutex );
snprintf(pidInUse, sizeof(pidInUse), "%lld",  ptrToLL(pid));
pidInUse[ArraySize(pidInUse)-1] = '\0';

static struct hash *perThreadVars = NULL;
if (perThreadVars == NULL)
    perThreadVars = hashNew(0);
struct hashEl *hel = hashLookup(perThreadVars, pidStr);
if (hel == NULL)
    {
    // if it is the first time, initialization the perThreadAbortVars
    struct perThreadAbortVars *ptav;
    AllocVar(ptav);
    ptav->debugPushPopErr = FALSE;
    ptav->errAbortInProgress = FALSE;
    ptav->warnIx = 0;
    ptav->warnArray[0] = defaultVaWarn;
    ptav->abortIx = 0;
    ptav->abortArray[0] = defaultAbort;
    hel = hashAdd(perThreadVars, pidStr, ptav);
    }
pidInUse[0] = '\0';
pthread_mutex_unlock( &ptavMutex );
return (struct perThreadAbortVars *)(hel->val);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x48, %rsp
callq 0x3600
movq %rax, %rbx
leaq 0xcf58(%rip), %rdx      # 0x1788e
movq %rsp, %r14
pushq $0x40
popq %rsi
movq %r14, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x32a0
movb $0x0, 0x3f(%r14)
leaq 0x1bf0b(%rip), %rsi     # 0x26860
movq %r14, %rdi
callq 0x3440
testl %eax, %eax
je 0xaa2c
leaq 0x1bf34(%rip), %rdi     # 0x268a0
callq 0x3770
leaq 0x1bee8(%rip), %rdi     # 0x26860
leaq 0xcf0f(%rip), %rdx      # 0x1788e
pushq $0x40
popq %rsi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x32a0
movb $0x0, 0x1bf0c(%rip)     # 0x2689f
movq 0x1bf2e(%rip), %rdi     # 0x268c8
testq %rdi, %rdi
jne 0xa9b3
pushq $0x1
popq %rsi
xorl %edi, %edi
callq 0xb010
movq %rax, %rdi
movq %rax, 0x1bf15(%rip)     # 0x268c8
movq %rsp, %rsi
callq 0xaaa4
movq %rax, %rbx
testq %rax, %rax
jne 0xaa0d
movl $0x118, %edi            # imm = 0x118
callq 0xd87c
andq $0x0, (%rax)
andl $0x0, 0xa8(%rax)
leaq -0x104(%rip), %rcx      # 0xa8db
movq %rcx, 0x8(%rax)
andl $0x0, 0x110(%rax)
leaq 0x55(%rip), %rcx        # 0xaa46
movq %rcx, 0xb0(%rax)
movq 0x1bec9(%rip), %rdi     # 0x268c8
movq %rsp, %rsi
movq %rax, %rdx
callq 0xad17
movq %rax, %rbx
movb $0x0, 0x1be4c(%rip)     # 0x26860
leaq 0x1be85(%rip), %rdi     # 0x268a0
callq 0x3500
movq 0x10(%rbx), %rax
addq $0x48, %rsp
popq %rbx
popq %r14
retq
leaq 0xd0bb(%rip), %rsi      # 0x17aee
pushq $0x2
popq %rdi
pushq $0x3c
popq %rdx
callq 0x31a0
pushq $0x1
popq %rdi
callq 0x36e0