// File: /workspace/github_c_makefile_star2_O2/haxlang[P]hax/haxCmdAH.c
// Function: Hax_CaseCmd
int
Hax_CaseCmd(
    ClientData dummy,			/* Not used. */
    Hax_Interp *interp,			/* Current interpreter. */
    int argc,				/* Number of arguments. */
    char **argv				/* Argument strings. */)
{
    Interp *iPtr = (Interp *) interp;
    Hax_Memoryp *memoryp = iPtr->memoryp;
    int i, result;
    int body;
    char *string;
    int caseArgc, splitArgs;
    char **caseArgv;

    if (argc < 3) {
	Hax_AppendResult(interp, "wrong # args: should be \"",
		argv[0], " string ?in? patList body ... ?default body?\"",
		(char *) NULL);
	return HAX_ERROR;
    }
    string = argv[1];
    body = -1;
    if (strcmp(argv[2], "in") == 0) {
	i = 3;
    } else {
	i = 2;
    }
    caseArgc = argc - i;
    caseArgv = argv + i;

    /*
     * If all of the pattern/command pairs are lumped into a single
     * argument, split them out again.
     */

    splitArgs = 0;
    if (caseArgc == 1) {
	result = Hax_SplitList(interp, caseArgv[0], &caseArgc, &caseArgv);
	if (result != HAX_OK) {
	    return result;
	}
	splitArgs = 1;
    }

    for (i = 0; i < caseArgc; i += 2) {
	int patArgc, j;
	char **patArgv;
	char *p;

	if (i == (caseArgc-1)) {
	    interp->result = (char *) "extra case pattern with no body";
	    result = HAX_ERROR;
	    goto cleanup;
	}

	/*
	 * Check for special case of single pattern (no list) with
	 * no backslash sequences.
	 */

	for (p = caseArgv[i]; *p != 0; p++) {
	    if (isspace(*p) || (*p == '\\')) {
		break;
	    }
	}
	if (*p == 0) {
	    if ((*caseArgv[i] == 'd')
		    && (strcmp(caseArgv[i], "default") == 0)) {
		body = i+1;
	    }
	    if (Hax_StringMatch(string, caseArgv[i])) {
		body = i+1;
		goto match;
	    }
	    continue;
	}

	/*
	 * Break up pattern lists, then check each of the patterns
	 * in the list.
	 */

	result = Hax_SplitList(interp, caseArgv[i], &patArgc, &patArgv);
	if (result != HAX_OK) {
	    goto cleanup;
	}
	for (j = 0; j < patArgc; j++) {
	    if (Hax_StringMatch(string, patArgv[j])) {
		body = i+1;
		break;
	    }
	}
	ckfree(memoryp, (char *) patArgv);
	if (j < patArgc) {
	    break;
	}
    }

    match:
    if (body != -1) {
	result = Hax_Eval(interp, NULL, caseArgv[body], 0, (char **) NULL);
	if (result == HAX_ERROR) {
	    char msg[100];
	    sprintf(msg, "\n    (\"%.50s\" arm line %d)", caseArgv[body-1],
		    interp->errorLine);
	    Hax_AddErrorInfo(interp, msg);
	}
	goto cleanup;
    }

    /*
     * Nothing matched:  return nothing.
     */

    result = HAX_OK;

    cleanup:
    if (splitArgs) {
	ckfree(memoryp, (char *) caseArgv);
    }
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r14
cmpl $0x2, %edx
jg 0x70d2
movq (%rcx), %rdx
leaq 0xc7aa(%rip), %rsi      # 0x13860
leaq 0xc7bd(%rip), %rcx      # 0x1387a
movq %r14, %rdi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4520
pushq $0x1
popq %rbp
jmp 0x72e3
movl %edx, %ebx
movq 0x10(%rcx), %rdx
pushq $0x2
popq %rax
cmpb $0x69, (%rdx)
jne 0x70ef
cmpb $0x6e, 0x1(%rdx)
jne 0x70ef
xorl %eax, %eax
cmpb $0x1, 0x2(%rdx)
adcl $0x2, %eax
movq 0x280(%r14), %rdx
movq %rdx, 0x28(%rsp)
movq 0x8(%rcx), %r12
subl %eax, %ebx
movl %ebx, 0x1c(%rsp)
movl %eax, %eax
leaq (%rcx,%rax,8), %rax
movq %rax, 0x10(%rsp)
cmpl $0x1, %ebx
jne 0x7134
movq (%rax), %rsi
leaq 0x1c(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r14, %rdi
callq 0x4540
movl %eax, %ebp
testl %eax, %eax
jne 0x72e3
movq %r14, 0x20(%rsp)
movl %ebx, 0xc(%rsp)
pushq $-0x1
popq %r13
xorl %r15d, %r15d
movslq 0x1c(%rsp), %rax
cmpq %rax, %r15
jge 0x7254
decl %eax
cmpq %rax, %r15
je 0x7239
movq 0x10(%rsp), %rax
movq (%rax,%r15,8), %r14
movq %r14, %rbp
movsbq (%rbp), %rbx
testq %rbx, %rbx
je 0x71d6
callq 0x4660
cmpb $0x5c, %bl
je 0x7191
movq (%rax), %rax
movzwl (%rax,%rbx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
incq %rbp
testw %ax, %ax
je 0x7169
movq 0x20(%rsp), %rdi
movq %r14, %rsi
leaq 0x18(%rsp), %rdx
leaq 0x30(%rsp), %rcx
callq 0x4540
testl %eax, %eax
jne 0x72bd
xorl %ebp, %ebp
movslq 0x18(%rsp), %rax
cmpq %rax, %rbp
jge 0x720f
movq 0x30(%rsp), %rax
movq (%rax,%rbp,8), %rsi
movq %r12, %rdi
callq 0x4480
testl %eax, %eax
jne 0x7208
incq %rbp
jmp 0x71b2
cmpb $0x64, (%r14)
jne 0x71f7
movq %r14, %rdi
leaq 0xc6e2(%rip), %rsi      # 0x138c8
callq 0x4330
movl %r15d, %ecx
orl $0x1, %ecx
testl %eax, %eax
cmovel %ecx, %r13d
movq %r12, %rdi
movq %r14, %rsi
callq 0x4480
testl %eax, %eax
je 0x7230
jmp 0x724d
movl %r15d, %r13d
orl $0x1, %r13d
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdi
leaq 0xc6b0(%rip), %rdx      # 0x138d0
movl $0xa9, %ecx
callq 0x4280
cmpl %ebp, 0x18(%rsp)
jg 0x7254
addq $0x2, %r15
jmp 0x7144
leaq 0xc668(%rip), %rax      # 0x138a8
movq 0x20(%rsp), %rcx
movq %rax, (%rcx)
pushq $0x1
popq %rbp
jmp 0x72bf
orl $0x1, %r15d
movl %r15d, %r13d
cmpl $-0x1, %r13d
je 0x72b9
movq 0x10(%rsp), %rax
movslq %r13d, %r14
movq (%rax,%r14,8), %rdx
movq 0x20(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45d0
movl %eax, %ebp
cmpl $0x1, %eax
movl 0xc(%rsp), %ebx
jne 0x72c3
movq 0x10(%rsp), %rax
movq -0x8(%rax,%r14,8), %rdx
movl 0x10(%r15), %ecx
leaq 0xc641(%rip), %rsi      # 0x138db
leaq 0x30(%rsp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x45f0
movq %r15, %rdi
movq %r12, %rsi
callq 0x4420
pushq $0x1
popq %rbp
jmp 0x72c3
xorl %ebp, %ebp
jmp 0x72bf
movl %eax, %ebp
movl 0xc(%rsp), %ebx
cmpl $0x1, %ebx
jne 0x72e3
movq 0x10(%rsp), %rsi
leaq 0xc5fc(%rip), %rdx      # 0x138d0
movq 0x28(%rsp), %rdi
movl $0xc3, %ecx
callq 0x4280
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq