// File: /workspace/github_c_makefile_star2_O0/albertito[P]libfiu/libfiu/fiu.c
// Function: fiu_fail
int fiu_fail(const char *name)
{
	struct pf_info *pf;
	int failnum;

	rec_count++;

	/* We must do this before acquiring the lock and calling any
	 * (potentially wrapped) functions. */
	if (rec_count > 1) {
		rec_count--;
		return 0;
	}

	ef_rlock();

	/* It can happen that someone calls fiu_fail() before fiu_init(); we
	 * don't want to crash so we just exit. */
	if (enabled_fails == NULL) {
		goto exit;
	}

	pf = wtable_get(enabled_fails, name);

	/* None found. */
	if (pf == NULL) {
		goto exit;
	}

	if (pf->flags & FIU_ONETIME) {
		pthread_mutex_lock(&pf->lock);
		if (pf->failed_once) {
			pthread_mutex_unlock(&pf->lock);
			goto exit;
		}
		/* We leave it locked so we don't accidentally fail this
		 * point twice. */
	}

	switch (pf->method) {
	case PF_ALWAYS:
		goto exit_fail;
		break;
	case PF_PROB:
		if (pf->minfo.probability > randd())
			goto exit_fail;
		break;
	case PF_EXTERNAL:
		if (pf->minfo.external_cb(pf->name, &(pf->failnum),
		                          &(pf->failinfo), &(pf->flags)))
			goto exit_fail;
		break;
	case PF_STACK:
		if (should_stack_fail(pf))
			goto exit_fail;
		break;
	default:
		break;
	}

	if (pf->flags & FIU_ONETIME) {
		pthread_mutex_unlock(&pf->lock);
	}

exit:
	trace("FIU  Not failing %s\n", name);

	ef_runlock();
	rec_count--;
	return 0;

exit_fail:
	trace("FIU  Failing %s on %s\n", name, pf->name);

	pthread_setspecific(last_failinfo_key, pf->failinfo);
	failnum = pf->failnum;

	if (pf->flags & FIU_ONETIME) {
		pf->failed_once = true;
		pthread_mutex_unlock(&pf->lock);
	}

	ef_runlock();
	rec_count--;
	return failnum;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
leaq 0x59a7(%rip), %rdi      # 0x7fd8
callq 0x21f0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
leaq 0x5990(%rip), %rdi      # 0x7fd8
callq 0x21f0
cmpl $0x1, (%rax)
jle 0x2679
leaq 0x597b(%rip), %rdi      # 0x7fd8
callq 0x21f0
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movl $0x0, 0x34(%rsp)
jmp 0x2877
jmp 0x267b
leaq 0x5b56(%rip), %rdi      # 0x81d8
callq 0x21b0
leaq 0x5b3a(%rip), %rax      # 0x81c8
cmpq $0x0, (%rax)
jne 0x2699
jmp 0x27cc
leaq 0x5b28(%rip), %rax      # 0x81c8
movq (%rax), %rdi
movq 0x28(%rsp), %rsi
callq 0x3e30
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x26bf
jmp 0x27cc
movq 0x20(%rsp), %rax
movl 0x18(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x26fd
movq 0x20(%rsp), %rdi
addq $0x20, %rdi
callq 0x2340
movq 0x20(%rsp), %rax
testb $0x1, 0x48(%rax)
je 0x26fb
movq 0x20(%rsp), %rdi
addq $0x20, %rdi
callq 0x2240
jmp 0x27cc
jmp 0x26fd
movq 0x20(%rsp), %rax
movl 0x4c(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, 0x10(%rsp)
subl $0x3, %eax
ja 0x27aa
movq 0x10(%rsp), %rax
leaq 0x38dd(%rip), %rcx      # 0x6000
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x27ff
movq 0x20(%rsp), %rax
movss 0x50(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x2880
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x275e
jmp 0x27ff
jmp 0x27ac
movq 0x20(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x20(%rsp), %rcx
movq (%rcx), %rdi
movq 0x20(%rsp), %rsi
addq $0xc, %rsi
movq 0x20(%rsp), %rdx
addq $0x10, %rdx
movq 0x20(%rsp), %rcx
addq $0x18, %rcx
callq *%rax
cmpl $0x0, %eax
je 0x2795
jmp 0x27ff
jmp 0x27ac
movq 0x20(%rsp), %rdi
callq 0x28b0
cmpl $0x0, %eax
je 0x27a8
jmp 0x27ff
jmp 0x27ac
jmp 0x27ac
movq 0x20(%rsp), %rax
movl 0x18(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x27ca
movq 0x20(%rsp), %rdi
addq $0x20, %rdi
callq 0x2240
jmp 0x27cc
jmp 0x27ce
jmp 0x27d0
jmp 0x27d2
leaq 0x59ff(%rip), %rdi      # 0x81d8
callq 0x2270
leaq 0x57f2(%rip), %rdi      # 0x7fd8
callq 0x21f0
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movl $0x0, 0x34(%rsp)
jmp 0x2877
jmp 0x2801
jmp 0x2803
movl 0x5a07(%rip), %edi      # 0x8210
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x2350
movq 0x20(%rsp), %rax
movl 0xc(%rax), %eax
movl %eax, 0x1c(%rsp)
movq 0x20(%rsp), %rax
movl 0x18(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x284a
movq 0x20(%rsp), %rax
movb $0x1, 0x48(%rax)
movq 0x20(%rsp), %rdi
addq $0x20, %rdi
callq 0x2240
jmp 0x284c
leaq 0x5985(%rip), %rdi      # 0x81d8
callq 0x2270
leaq 0x5778(%rip), %rdi      # 0x7fd8
callq 0x21f0
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movl 0x1c(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq