// File: /workspace/github_c_makefile_star2_O0/oridb[P]mc/mi/flatten.c
// Function: rval
static Node *
rval(Flattenctx *s, Node *n)
{
	Node *t, *u, *v; /* temporary nodes */
	Node *r; /* expression result */
	Node **args;
	Type *ty;

	const Op fusedmap[Numops] = {
		[Oaddeq]	= Oadd,
		[Osubeq]	= Osub,
		[Omuleq]	= Omul,
		[Odiveq]	= Odiv,
		[Omodeq]	= Omod,
		[Oboreq]	= Obor,
		[Obandeq]	= Oband,
		[Obxoreq]	= Obxor,
		[Obsleq]	= Obsl,
		[Obsreq]	= Obsr,
	};

	r = NULL;
	args = n->expr.args;
	switch (exprop(n)) {
	case Oauto:
		t = temp(s, n);
		r = assign(s, t, n->expr.args[0]);
		lappend(&s->curst->autotmp, &s->curst->nautotmp, t);
		break;
	case Osize:
		r = n;	/* don't touch subexprs; they're a pseudo decl */
		break;
	case Olor: case Oland:
		r = flattenlazy(s, n);
		break;
	case Oidx:
		t = rval(s, n->expr.args[0]);
		u = rval(s, n->expr.args[1]);
		r = mkexpr(n->loc, Oidx, t, u, NULL);
		r->expr.type = n->expr.type;
		break;
		/* array.len slice.len are magic 'virtual' members.
		 * they need to be special cased. */
	case Omemb:
                ty = tybase(exprtype(args[0]));
		if (ty->type == Tyslice || ty->type == Tyarray) {
			r = seqlen(s, args[0], exprtype(n));
		} else {
	case Otupmemb:
			t = rval(s, args[0]);
			r = mkexpr(n->loc, exprop(n), t, args[1], NULL);
			r->expr.type = n->expr.type;
		}
		break;
	case Oucon:
		if (n->expr.nargs > 1)
			t = rval(s, args[1]);
		else
			t = NULL;
		r = mkexpr(n->loc, Oucon, args[0], t, NULL);
		r->expr.type = n->expr.type;
		break;
	/* fused ops:
	 * foo ?= blah
	 *    =>
	 *     foo = foo ? blah*/
	case Oaddeq: case Osubeq: case Omuleq: case Odiveq: case Omodeq:
	case Oboreq: case Obandeq: case Obxoreq: case Obsleq: case Obsreq:
		assert(fusedmap[exprop(n)] != Obad);
		u = lval(s, args[0]);
		v = rval(s, args[1]);
		v = mkexpr(n->loc, fusedmap[exprop(n)], u, v, NULL);
		v->expr.type = u->expr.type;
		r = asn(u, v);
		break;

	/* ++expr(x)
	 *  => args[0] = args[0] + 1
	 *     expr(x) */
	case Opreinc:
		t = lval(s, args[0]);
		v = asn(t, addk(t, 1));
		append(s, v);
		r = rval(s, t);
		break;
	case Opredec:
		t = lval(s, args[0]);
		v = asn(t, subk(t, 1));
		append(s, v);
		r = rval(s, t);
		break;

	/* expr(x++)
	 *   => expr
	 *      x = x + 1
	 */
	case Opostinc:
		r = lval(s, args[0]);
		t = asn(r, addk(r, 1));
		lappend(&s->incqueue, &s->nqueue, t);
		break;
	case Opostdec:
		r = lval(s, args[0]);
		t = asn(r, subk(r, 1));
		lappend(&s->incqueue, &s->nqueue, t);
		break;
	case Olit:
		switch (args[0]->lit.littype) {
		case Lvoid:
		case Lchr:
		case Lbool:
		case Llbl:
		case Lint:
		case Lstr:
		case Lflt:
		case Lfunc:
			r = n; //capture(s, n, dst);
			break;
		}
		break;
	case Ovar:
		r = n;
		break;;
	case Oret:
		v = rval(s, args[0]);
		if (!s->tret)
			s->tret = temp(s, v);
		flatten(s, asn(lval(s, s->tret), v));
		draininc(s);
		if (exitscope(s, NULL, Zloc, Xret))
			append(s, mkexpr(n->loc, Oret, s->tret, NULL));
		break;
	case Otern:
		r = flattentern(s, n);
		break;
	case Oasn:
		r = assign(s, args[0], args[1]);
		break;
	case Obreak:
		r = NULL;
		if (s->inloop == 0)
			fatal(n, "trying to break when not in loop");
		if (exitscope(s, s->loop.body, n->loc, Xbrk))
			jmp(s, s->loop.lbrk);
		break;
	case Ocontinue:
		r = NULL;
		if (s->inloop == 0)
			fatal(n, "trying to continue when not in loop");
		if (exitscope(s, s->loop.body, n->loc, Xcnt))
			jmp(s, s->loop.lcnt);
		break;
	case Oeq: case One:
		r = compare(s, n, 1);
		break;
	case Ogt: case Oge: case Olt: case Ole:
		r = compare(s, n, 0);
		break;
	default:
		if (istyfloat(exprtype(n))) {
			switch (exprop(n)) {
			case Oadd:	n->expr.op = Ofadd;	break;
			case Osub:	n->expr.op = Ofsub;	break;
			case Omul:	n->expr.op = Ofmul;	break;
			case Odiv:	n->expr.op = Ofdiv;	break;
			default:	break;
			}
		}
		r = visit(s, n);
		break;
	}
	if (r && n->expr.idx)
		r->expr.idx = n->expr.idx;
	return r;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x12e86(%rip), %rsi     # 0x548e0
leaq -0x1c0(%rbp), %rdi
movl $0x180, %edx            # imm = 0x180
callq 0x6260
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2f210
decl %eax
movl %eax, %ecx
movq %rcx, -0x1d0(%rbp)
subl $0x39, %eax
ja 0x42141
movq -0x1d0(%rbp), %rax
leaq 0x12ca2(%rip), %rcx     # 0x5474c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x43230
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq (%rax), %rdx
callq 0x43310
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rdi
addq $0x50, %rdi
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rsi
addq $0x58, %rsi
movq -0x18(%rbp), %rdx
callq 0x48290
jmp 0x421d1
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x421d1
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x433d0
movq %rax, -0x30(%rbp)
jmp 0x421d1
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq (%rax), %rsi
callq 0x41a40
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x41a40
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq (%rax), %rdi
movl $0x28, %esi
xorl %eax, %eax
movl %eax, %r8d
movb $0x0, %al
callq 0x2f400
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x421d1
movq -0x38(%rbp), %rax
movq (%rax), %rdi
callq 0x30340
movq %rax, %rdi
callq 0x36a30
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x14, (%rax)
je 0x41bbd
movq -0x40(%rbp), %rax
cmpl $0x15, (%rax)
jne 0x41bfb
movq -0x8(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1d8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x30340
movq -0x1e0(%rbp), %rdi
movq -0x1d8(%rbp), %rsi
movq %rax, %rdx
callq 0x42ff0
movq %rax, -0x30(%rbp)
jmp 0x41c5d
jmp 0x41bfd
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rsi
callq 0x41a40
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2f210
movl %eax, %esi
movq -0x1e8(%rbp), %rax
movq -0x18(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %r8d
movb $0x0, %al
callq 0x2f400
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x421d1
movq -0x10(%rbp), %rax
cmpq $0x1, 0x40(%rax)
jbe 0x41c84
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x41a40
movq %rax, -0x18(%rbp)
jmp 0x41c8c
movq $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rdx
movq -0x18(%rbp), %rcx
movq (%rax), %rdi
movl $0x36, %esi
xorl %eax, %eax
movl %eax, %r8d
movb $0x0, %al
callq 0x2f400
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x421d1
movq -0x10(%rbp), %rdi
callq 0x2f210
movl %eax, %eax
cmpl $0x0, -0x1c0(%rbp,%rax,4)
je 0x41cdf
jmp 0x41cfe
leaq 0x132b7(%rip), %rdi     # 0x54f9d
leaq 0x1322c(%rip), %rsi     # 0x54f19
movl $0x23d, %edx            # imm = 0x23D
leaq 0x132c0(%rip), %rcx     # 0x54fb9
callq 0x6160
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rsi
callq 0x43560
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x41a40
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2f210
movl %eax, %ecx
movq -0x1f0(%rbp), %rax
movl %ecx, %ecx
movl -0x1c0(%rbp,%rcx,4), %esi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %r8d
movb $0x0, %al
callq 0x2f400
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x42ef0
movq %rax, -0x30(%rbp)
jmp 0x421d1
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rsi
callq 0x43560
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1f8(%rbp)
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x42fa0
movq -0x1f8(%rbp), %rdi
movq %rax, %rsi
callq 0x42ef0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x419f0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x41a40
movq %rax, -0x30(%rbp)
jmp 0x421d1
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rsi
callq 0x43560
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x43690
movq -0x200(%rbp), %rdi
movq %rax, %rsi
callq 0x42ef0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x419f0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x41a40
movq %rax, -0x30(%rbp)
jmp 0x421d1
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rsi
callq 0x43560
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0x42fa0
movq -0x208(%rbp), %rdi
movq %rax, %rsi
callq 0x42ef0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
movq -0x8(%rbp), %rsi
addq $0x28, %rsi
movq -0x18(%rbp), %rdx
callq 0x48290
jmp 0x421d1
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rsi
callq 0x43560
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x210(%rbp)
movq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0x43690
movq -0x210(%rbp), %rdi
movq %rax, %rsi
callq 0x42ef0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
movq -0x8(%rbp), %rsi
addq $0x28, %rsi
movq -0x18(%rbp), %rdx
callq 0x48290
jmp 0x421d1
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl 0x18(%rax), %eax
subl $0x7, %eax
ja 0x41f29
jmp 0x41f21
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x421d1
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x421d1
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rsi
callq 0x41a40
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x41f72
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x43230
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0x218(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x43560
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x42ef0
movq -0x218(%rbp), %rdi
movq %rax, %rsi
callq 0x41220
movq -0x8(%rbp), %rdi
callq 0x426c0
movq -0x8(%rbp), %rdi
movl $0xffffffff, -0x1c8(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x1c4(%rbp)
movq -0x1c8(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %ecx
callq 0x42200
cmpl $0x0, %eax
je 0x4201d
movq -0x8(%rbp), %rax
movq %rax, -0x220(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rdx
movq (%rax), %rdi
movl $0x2f, %esi
xorl %eax, %eax
movl %eax, %ecx
movb $0x0, %al
callq 0x2f400
movq -0x220(%rbp), %rdi
movq %rax, %rsi
callq 0x419f0
jmp 0x421d1
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x436e0
movq %rax, -0x30(%rbp)
jmp 0x421d1
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rsi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x43310
movq %rax, -0x30(%rbp)
jmp 0x421d1
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x48(%rax)
jne 0x4207d
movq -0x10(%rbp), %rdi
leaq 0x12f64(%rip), %rsi     # 0x54fda
movb $0x0, %al
callq 0x1dfe0
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movl $0x1, %ecx
callq 0x42200
cmpl $0x0, %eax
je 0x420b0
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x42420
jmp 0x421d1
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x48(%rax)
jne 0x420d9
movq -0x10(%rbp), %rdi
leaq 0x12f29(%rip), %rsi     # 0x54ffb
movb $0x0, %al
callq 0x1dfe0
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
xorl %ecx, %ecx
callq 0x42200
cmpl $0x0, %eax
je 0x42109
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rsi
callq 0x42420
jmp 0x421d1
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x1, %edx
callq 0x43820
movq %rax, -0x30(%rbp)
jmp 0x421d1
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x43820
movq %rax, -0x30(%rbp)
jmp 0x421d1
movq -0x10(%rbp), %rdi
callq 0x30340
movq %rax, %rdi
callq 0x37930
cmpl $0x0, %eax
je 0x421c0
movq -0x10(%rbp), %rdi
callq 0x2f210
addl $-0x2, %eax
movl %eax, %ecx
movq %rcx, -0x228(%rbp)
subl $0x3, %eax
ja 0x421bc
movq -0x228(%rbp), %rax
leaq 0x126b5(%rip), %rcx     # 0x54834
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movl $0x4f, 0x18(%rax)
jmp 0x421be
movq -0x10(%rbp), %rax
movl $0x50, 0x18(%rax)
jmp 0x421be
movq -0x10(%rbp), %rax
movl $0x51, 0x18(%rax)
jmp 0x421be
movq -0x10(%rbp), %rax
movl $0x52, 0x18(%rax)
jmp 0x421be
jmp 0x421be
jmp 0x421c0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x43a90
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x421f3
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x421f3
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x30(%rbp), %rax
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq