// File: /workspace/github_cpp_makefile_star2_O3/rossy[P]crossc/SPIRV-Cross/spirv_hlsl.cpp
// Function: spirv_cross::CompilerHLSL::emit_atomic(unsigned int const*, unsigned int, spv::Op)
void CompilerHLSL::emit_atomic(const uint32_t *ops, uint32_t length, spv::Op op)
{
	const char *atomic_op = nullptr;

	string value_expr;
	if (op != OpAtomicIDecrement && op != OpAtomicIIncrement)
		value_expr = to_expression(ops[op == OpAtomicCompareExchange ? 6 : 5]);

	switch (op)
	{
	case OpAtomicIIncrement:
		atomic_op = "InterlockedAdd";
		value_expr = "1";
		break;

	case OpAtomicIDecrement:
		atomic_op = "InterlockedAdd";
		value_expr = "-1";
		break;

	case OpAtomicISub:
		atomic_op = "InterlockedAdd";
		value_expr = join("-", enclose_expression(value_expr));
		break;

	case OpAtomicSMin:
	case OpAtomicUMin:
		atomic_op = "InterlockedMin";
		break;

	case OpAtomicSMax:
	case OpAtomicUMax:
		atomic_op = "InterlockedMax";
		break;

	case OpAtomicAnd:
		atomic_op = "InterlockedAnd";
		break;

	case OpAtomicOr:
		atomic_op = "InterlockedOr";
		break;

	case OpAtomicXor:
		atomic_op = "InterlockedXor";
		break;

	case OpAtomicIAdd:
		atomic_op = "InterlockedAdd";
		break;

	case OpAtomicExchange:
		atomic_op = "InterlockedExchange";
		break;

	case OpAtomicCompareExchange:
		if (length < 8)
			SPIRV_CROSS_THROW("Not enough data for opcode.");
		atomic_op = "InterlockedCompareExchange";
		value_expr = join(to_expression(ops[7]), ", ", value_expr);
		break;

	default:
		SPIRV_CROSS_THROW("Unknown atomic opcode.");
	}

	uint32_t result_type = ops[0];
	uint32_t id = ops[1];
	forced_temporaries.insert(ops[1]);

	auto &type = get<SPIRType>(result_type);
	statement(variable_decl(type, to_name(id)), ";");

	auto &data_type = expression_type(ops[2]);
	auto *chain = maybe_get<SPIRAccessChain>(ops[2]);
	SPIRType::BaseType expr_type;
	if (data_type.storage == StorageClassImage || !chain)
	{
		statement(atomic_op, "(", to_expression(ops[2]), ", ", value_expr, ", ", to_name(id), ");");
		expr_type = data_type.basetype;
	}
	else
	{
		// RWByteAddress buffer is always uint in its underlying type.
		expr_type = SPIRType::UInt;
		statement(chain->base, ".", atomic_op, "(", chain->dynamic_index, chain->static_index, ", ", value_expr, ", ",
		          to_name(id), ");");
	}

	auto expr = bitcast_expression(type, expr_type, to_name(id));
	set<SPIRExpression>(id, expr, result_type, true);
	flush_all_atomic_capable_variables();
	register_read(ops[1], ops[2], should_forward(ops[2]));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %ecx, %r15d
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
xorl %eax, %eax
movq %rax, (%rsp)
leaq 0x60(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
leal -0xea(%r15), %eax
cmpl $-0x3, %eax
ja 0x6ed9c
xorl %eax, %eax
cmpl $0xe6, %r15d
sete %al
movl 0x14(%r14,%rax,4), %edx
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x33f8a
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %r12
movq %r12, %rsi
callq 0x6310
movq (%r12), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x6ed9c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
addl $0xffffff1b, %r15d      # imm = 0xFFFFFF1B
cmpl $0xd, %r15d
ja 0x6f251
leaq 0x4c4f4(%rip), %rax     # 0xbb2a8
movslq (%rax,%r15,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x4f72e(%rip), %rax     # 0xbe4f2
jmp 0x6ee7a
leaq 0x4f731(%rip), %rax     # 0xbe501
jmp 0x6ee7a
leaq 0x4f743(%rip), %rax     # 0xbe51f
jmp 0x6ee7a
leaq 0x4f6fb(%rip), %rax     # 0xbe4e3
jmp 0x6ee7a
leaq 0x4f739(%rip), %rax     # 0xbe52d
jmp 0x6ee7a
leaq 0x4f710(%rip), %rax     # 0xbe510
jmp 0x6ee7a
leaq 0x4f6da(%rip), %rax     # 0xbe4e3
movq %rax, (%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movq %rbx, %rsi
callq 0x32b66
leaq 0x4b052(%rip), %rsi     # 0xb9e78
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x57dbe
jmp 0x6f19b
movl $0x1, %r8d
leaq 0x4b02d(%rip), %rcx     # 0xb9e74
jmp 0x6ee56
movl $0x2, %r8d
leaq 0x4b01d(%rip), %rcx     # 0xb9e73
leaq 0x4f686(%rip), %rax     # 0xbe4e3
movq %rax, (%rsp)
leaq 0x50(%rsp), %rdi
movq 0x8(%rdi), %rdx
xorl %esi, %esi
callq 0x63f0
jmp 0x6ee7e
leaq 0x4f6c2(%rip), %rax     # 0xbe53c
movq %rax, (%rsp)
movl (%r14), %r15d
movl %r15d, 0x4c(%rsp)
leaq 0x4(%r14), %rsi
movl 0x4(%r14), %ebp
leaq 0x228(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movq %rdi, (%rdx)
callq 0x1f510
movq %rbx, %rdi
movl %r15d, %esi
callq 0xa3ea
movq %rax, %r12
movq (%rbx), %rax
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %edx
movl $0x1, %ecx
callq *0x38(%rax)
movq (%rbx), %rax
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rcx
movq %rbx, %rsi
movq %r12, %rdx
xorl %r8d, %r8d
callq *0xc8(%rax)
leaq 0x4fc09(%rip), %rdx     # 0xbeaf1
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0xaa14
leaq 0x18(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %r15, %rdi
je 0x6ef10
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movq %r12, 0x70(%rsp)
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6ef30
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6260
movl 0x8(%r14), %esi
movq %rbx, %rdi
callq 0x12a72
movq %rax, %r12
movl 0x8(%r14), %esi
movq %rbx, %rdi
callq 0x1b3f0
movq %rax, %r13
testq %rax, %rax
je 0x6efec
cmpl $0xb, 0x64(%r12)
je 0x6efec
movq (%rbx), %rax
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl %ebp, %edx
movl $0x1, %ecx
callq *0x38(%rax)
leaq 0x58(%r13), %rax
leaq 0x38(%r13), %r9
addq $0x18, %r13
leaq 0x4fb62(%rip), %r10     # 0xbeaf0
leaq 0x4b116(%rip), %r11     # 0xba0ab
leaq 0x50(%rsp), %r15
leaq 0x4b8a8(%rip), %rdx     # 0xba849
leaq 0x53cc9(%rip), %r8      # 0xc2c71
movq %rsp, %rcx
movq %rbx, %rdi
movq %r13, %rsi
pushq %r10
pushq %r12
pushq %r11
pushq %r15
pushq %r11
pushq %rax
callq 0x7b734
addq $0x30, %rsp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %r15
cmpq %r15, %rdi
je 0x6efe1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movl $0x5, %r12d
jmp 0x6f086
movl 0x8(%r14), %edx
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x33f8a
movq (%rbx), %rax
leaq 0x28(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
movl %ebp, %edx
movl $0x1, %ecx
callq *0x38(%rax)
subq $0x8, %rsp
leaq 0x4fad0(%rip), %rax     # 0xbeaf0
leaq 0x4b084(%rip), %r8      # 0xba0ab
leaq 0x53c43(%rip), %rdx     # 0xc2c71
leaq 0x8(%rsp), %rsi
leaq 0x10(%rsp), %rcx
leaq 0x58(%rsp), %r9
movq %rbx, %rdi
pushq %rax
pushq %r13
pushq %r8
callq 0x7b596
addq $0x20, %rsp
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x6f06a
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x6f081
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movl 0xc(%r12), %r12d
movq (%rbx), %rax
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %edx
movl $0x1, %ecx
callq *0x38(%rax)
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %r8
movq %rbx, %rsi
movq 0x70(%rsp), %rdx
movl %r12d, %ecx
callq 0x3db74
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x6f0d1
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x28(%rsp), %r8
movb $0x1, (%r8)
leaq 0x8(%rsp), %rdx
leaq 0x4c(%rsp), %rcx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7b8d0
movq %rbx, %rdi
callq 0x12f6c
movl 0x4(%r14), %ebp
movl 0x8(%r14), %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x39684
movzbl %al, %ecx
movq %rbx, %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x12cf8
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x6f130
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x6f14c
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x7, %ebp
jbe 0x6f1eb
leaq 0x4f401(%rip), %rax     # 0xbe56c
movq %rax, (%rsp)
movl 0x1c(%r14), %edx
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x33f8a
leaq 0x4af24(%rip), %rdx     # 0xba0ab
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x50(%rsp), %rcx
callq 0x7b4ea
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0x6310
movq (%r15), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x6f1c7
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6ee7e
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x6ee7e
movl $0x10, %edi
callq 0x6140
movq %rax, %r14
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x4f348(%rip), %rsi     # 0xbe550
leaq 0x4f35c(%rip), %rdx     # 0xbe56b
leaq 0x8(%rsp), %rdi
callq 0x7be0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x6320
leaq 0x8cb98(%rip), %rax     # 0xfbdc8
addq $0x10, %rax
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0x8cb70(%rip), %rsi     # 0xfbdb0
movq 0x8dd91(%rip), %rdx     # 0xfcfd8
movq %r14, %rdi
callq 0x6470
jmp 0x6f2b5
movl $0x10, %edi
callq 0x6140
movq %rax, %r14
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x4f319(%rip), %rsi     # 0xbe587
leaq 0x4f328(%rip), %rdx     # 0xbe59d
leaq 0x8(%rsp), %rdi
callq 0x7be0
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x6320
leaq 0x8cb32(%rip), %rax     # 0xfbdc8
addq $0x10, %rax
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0x8cb0a(%rip), %rsi     # 0xfbdb0
movq 0x8dd2b(%rip), %rdx     # 0xfcfd8
movq %r14, %rdi
callq 0x6470
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x6f2cf
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
testb %bpl, %bpl
je 0x6f3df
jmp 0x6f306
movq %rax, %rbx
jmp 0x6f306
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x6f2f9
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
testb %bpl, %bpl
jne 0x6f306
jmp 0x6f3df
movq %rax, %rbx
movq %r14, %rdi
callq 0x6200
jmp 0x6f3df
jmp 0x6f3a4
jmp 0x6f3c0
jmp 0x6f3a4
jmp 0x6f3c0
jmp 0x6f3c0
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x6f3c8
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x6f3c8
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
jne 0x6f3d2
jmp 0x6f3df
jmp 0x6f3c5
jmp 0x6f3c0
jmp 0x6f3c0
jmp 0x6f3c0
jmp 0x6f3c5
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
jmp 0x6f3b0
jmp 0x6f3c0
jmp 0x6f3c0
jmp 0x6f3c0
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6f3a7
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x6f3a7
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6f3df
movq 0x38(%rsp), %rsi
jmp 0x6f3d7
jmp 0x6f3c0
jmp 0x6f3c0
movq %rax, %rbx
jmp 0x6f3df
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x6f3df
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x6f3fb
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
movq %rbx, %rdi
callq 0x64a0
nop