code: def uops_to_asmstyle(lang, function_name: str, uops: List[UOp]):
      # TODO: Do not use clear()
      lang.ins.clear()
      lang.tor.clear()
      lang.cnts.clear()
      buf_to_dtype = {
          args: dtype
          for uop, dtype, _, args, _ in uops
          if uop == UOps.DEFINE_GLOBAL
      }
      global_size, local_size = [], []
      skipload_branch = 0
      lang.ins += [
          AssemblyInstruction(
              UOps.SPECIAL,
              lang.newreg(buf, dtype=dtypes.uint64, scalar=True),
              [],
              buf,
          )
          for buf in buf_to_dtype
      ]
      for u in uops:
          uop, dtype, vin, args, _ = u
          if uop == UOps.DEFINE_LOCAL:
              lang.ins.append(
                  AssemblyInstruction(UOps.DEFINE_LOCAL, None, [], args)
              )
              lang.ins.append(
                  AssemblyInstruction(
                      UOps.ALU,
                      lang.newreg(args[0], dtype=dtypes.uint64),
                      [args[0]],
                      UnaryOps.NOOP,
                  )
              )
          elif uop == UOps.LOOP:
              if args[1] == "global":
                  for i, var in enumerate(args[0]):
                      global_size.append(var.max + 1)
                      lang.ins.append(
                          AssemblyInstruction(
                              UOps.SPECIAL,
                              lang.newreg(var, dtype=dtypes.int32),
                              [],
                              f"gid{len(args[0])-1-i}",
                          )
                      )
              elif args[1] == "local":
                  for i, var in enumerate(args[0]):
                      local_size.append(var.max + 1)
                      lang.ins.append(
                          AssemblyInstruction(
                              UOps.SPECIAL,
                              lang.newreg(var, dtype=dtypes.int32),
                              [],
                              f"lid{len(args[0])-1-i}",
                          )
                      )
              else:
                  for var in args[0]:
                      if not isinstance(
                          var, NumNode
                      ):  # TODO: why is this coming through?
                          lang.ins.append(
                              AssemblyInstruction(
                                  UOps.LOAD,
                                  lang.newreg(
                                      var,
                                      dtype=dtypes.int32,
                                      scalar=True,
                                  ),
                                  [],
                                  0,
                              )
                          )
                          lang.ins.append(
                              AssemblyInstruction(
                                  UOps.LABEL,
                                  None,
                                  [],
                                  "$loop_" + var.expr,
                              )
                          )
          elif uop == UOps.ENDLOOP:
              if args[1] not in ["global", "local", "global+local"]:
                  for var in reversed(args[0]):
                      if not isinstance(
                          var, NumNode
                      ):  # TODO: why is this coming through?
                          lang.ins.append(
                              AssemblyInstruction(
                                  UOps.ALU,
                                  lang.tor[var],
                                  [lang.tor[var], 1],
                                  BinaryOps.ADD,
                              )
                          )
                          pred = lang.render_alu(
                              BinaryOps.CMPLT,
                              lang.tor[var],
                              var.max + 1,
                              dtypes.bool,
                          )
                          lang.ins.append(
                              AssemblyInstruction(
                                  UOps.COND_BRANCH,
                                  None,
                                  [pred],
                                  ("$loop_" + var.expr, True),
                              )
                          )
              elif args[1] == "global+local":
                  for i, var in enumerate(reversed(args[0])):
                      lang.ins.append(
                          AssemblyInstruction(
                              UOps.ENDLOOP,
                              None,
                              [lang.tor[var]],
                              (var.max + 1, f"gid{i}"),
                          )
                      )
              elif args[1] == "local":
                  for i, var in enumerate(reversed(args[0])):
                      lang.ins.append(
                          AssemblyInstruction(
                              UOps.ENDLOOP,
                              None,
                              [lang.tor[var]],
                              (var.max + 1, f"lid{i}"),
                          )
                      )
          elif uop == UOps.CAST:
              # TODO: we should reconsider outputting CAST in the linearizer. these are needless copies
              out = lang.newreg(u, dtype)
              for i, sr in enumerate(out.subregs()):
                  lang.ins.append(
                      AssemblyInstruction(
                          UOps.ALU,
                          sr,
                          [lang.tor[vin[i]]],
                          UnaryOps.NOOP,
                      )
                  )
          elif uop == UOps.ALU:
              out = (
                  lang.newreg(u, dtype)
                  if u not in lang.tor
                  else lang.tor[u]
              )
              # this is the only thing that can violate SSA
              if args in [BinaryOps.CMPLT]:
                  pred_reg = lang.newreg((u, "pred"), dtype=dtypes.bool)
                  lang.ins.append(
                      AssemblyInstruction(
                          UOps.ALU,
                          pred_reg,
                          [lang.tor[x] for x in vin],
                          args,
                      )
                  )
                  lang.ins.append(
                      AssemblyInstruction(
                          UOps.CAST, out, [pred_reg], args
                      )
                  )
              elif args == BinaryOps.DIV and lang.no_div:
                  tmp = lang.newreg((u, "rcp"))
                  lang.ins.append(
                      AssemblyInstruction(
                          UOps.ALU,
                          tmp,
                          [lang.tor[vin[1]]],
                          UnaryOps.RECIP,
                      )
                  )
                  lang.ins.append(
                      AssemblyInstruction(
                          UOps.ALU,
                          out,
                          [lang.tor[vin[0]], tmp],
                          BinaryOps.MUL,
                      )
                  )
              elif args == UnaryOps.SIN and lang.sin_is_sin2pi:
                  tmp = lang.newreg((u, "2pi"))
                  lang.ins.append(
                      AssemblyInstruction(
                          UOps.ALU,
                          tmp,
                          [lang.tor[vin[0]], 1 / (math.pi * 2)],
                          BinaryOps.MUL,
                      )
                  )
                  lang.ins.append(
                      AssemblyInstruction(UOps.ALU, out, [tmp], args)
                  )
              else:
                  lang.ins.append(
                      AssemblyInstruction(
                          UOps.ALU,
                          out,
                          [lang.tor[x] for x in vin],
                          args,
                      )
                  )
          elif uop == UOps.DEFINE_ACC:
              reg = lang.newreg(u, dtype=dtype)
              lang.ins.append(
                  AssemblyInstruction(UOps.LOAD, reg, [], args)
              )
          elif uop == UOps.SPECIAL:
              lang.tor[u] = lang.tor[args]
          elif uop == UOps.CONST:
              lang.ins.append(
                  AssemblyInstruction(
                      UOps.LOAD, lang.newreg(u, dtype=dtype), [], args
                  )
              )
          elif uop == UOps.LOAD:
              idx, treg, off = lang.addr_w_offset(args)
              reg = lang.newreg(
                  u,
                  dtype=dtype,
                  scalar=(
                      idx.scalar
                      and (
                          not isinstance(treg, Register) or treg.scalar
                      )
                  ),
              )
              if args.valid.min == 0:
                  lang.ins.append(
                      AssemblyInstruction(UOps.LOAD, reg, [], 0)
                  )
                  if args.valid.max == 1:
                      pred = args.valid.render(lang.render_ops, lang)
                      lang.ins.append(
                          AssemblyInstruction(
                              UOps.COND_BRANCH,
                              None,
                              [pred],
                              (f"$skipload_{skipload_branch}", False),
                          )
                      )
              if args.valid.max == 1:
                  # NOTE: you can't compute the index in here, because it assumes it's all available later
                  lang.ins.append(
                      AssemblyInstruction(
                          UOps.LOAD,
                          reg,
                          [idx] + ([treg] if treg is not None else []),
                          (
                              off,
                              "global" if not args.local else "shared",
                              args.memory_dtype
                              if args.memory_dtype != dtypes.float
                              else None,
                          ),
                      )
                  )
              if args.valid.min == 0 and args.valid.max == 1:
                  lang.ins.append(
                      AssemblyInstruction(
                          UOps.LABEL,
                          None,
                          [],
                          f"$skipload_{skipload_branch}",
                      )
                  )
                  skipload_branch += 1
          elif uop == UOps.STORE:
              if args is None:
                  lang.ins.append(
                      AssemblyInstruction(
                          UOps.ALU,
                          lang.tor[vin[0]],
                          [lang.tor[vin[1]]],
                          UnaryOps.NOOP,
                      )
                  )
              else:
                  idx, treg, off = lang.addr_w_offset(args)
                  lang.ins.append(
                      AssemblyInstruction(
                          UOps.STORE,
                          None,
                          [idx, lang.tor[vin[0]]]
                          + ([treg] if treg is not None else []),
                          (
                              off,
                              "global" if not args.local else "shared",
                              args.memory_dtype
                              if args.memory_dtype != dtypes.float
                              else None,
                          ),
                      )
                  )
  
      if DEBUG >= 4:
          for tins in lang.ins:
              print(tins)
      return global_size, local_size
  
imports: from typing import Tuple, List, NamedTuple, Any, Dict, Optional, Union, DefaultDict, cast
  from tinygrad.codegen.linearizer import UOps, MemOp, UOp
  from tinygrad.ops import BinaryOps, UnaryOps
  from tinygrad.dtype import DType, dtypes
  from tinygrad.helpers import DEBUG
  from tinygrad.shape.symbolic import Variable, NumNode, MulNode, DivNode, ModNode, LtNode, SumNode, AndNode
  import functools
  import math
  from collections import defaultdict
label_desc: Use image node_id 1 for calling a global function with example usage: uops_to_asmstyle(lang, function_name, uops) and returns: global_size,  local_size