--- as/driver.c.orig	2019-05-25 16:26:59.000000000 +0100
+++ as/driver.c	2020-03-13 11:22:45.000000000 +0000
@@ -31,15 +31,15 @@
     const char *LOCALLIB = "../local/libexec/as/";
     const char *AS = "/as";
 
-    int i, j;
-    uint32_t count, verbose, run_clang;
-    char *p, c, *arch_name, *as, *as_local;
+    int i=0, j=0;
+    uint32_t count=0, verbose=0, run_clang=0;
+    char *p=NULL, c=NULL, *arch_name=NULL, *as=NULL, *as_local=NULL;
     char **new_argv;
     const char *CLANG = "clang";
-    char *prefix, buf[MAXPATHLEN], resolved_name[PATH_MAX];
-    uint32_t bufsize;
+    char *prefix=NULL, buf[MAXPATHLEN], resolved_name[PATH_MAX];
+    uint32_t bufsize=0;
     struct arch_flag arch_flag;
-    const struct arch_flag *arch_flags, *family_arch_flag;
+    const struct arch_flag *arch_flags=NULL, *family_arch_flag=NULL;
     enum bool oflag_specified, qflag, Qflag, some_input_files;
 
 	progname = argv[0];
@@ -295,11 +295,28 @@
 	    arch_flag.cputype == CPU_TYPE_ARM64 ||
 	    arch_flag.cputype == CPU_TYPE_ARM64_32 ||
 	    arch_flag.cputype == CPU_TYPE_ARM)){
-	    as = makestr(prefix, CLANG, NULL);
-	    if(access(as, F_OK) != 0){
-		printf("%s: assembler (%s) not installed\n", progname, as);
-		exit(1);
-	    }
+          if ( NULL == getenv("DISABLE_MACPORTS_AS_CLANG_SEARCH") ) {
+            const char * mp_comps[] = { __MP_CLANG_NAMES__ };
+            const size_t n_comps = sizeof(mp_comps) / sizeof(mp_comps[0]);
+            for ( size_t i = 0; i < n_comps; ++i ) {
+              as = makestr(prefix, mp_comps[i], NULL);
+              if(access(as, F_OK) == 0){
+                // found working compiler so break
+                break;
+              } else {
+                as = NULL;
+              }
+            }
+          }
+#if __TRY_SYSTEM_CLANG__
+          if ( NULL == as && NULL == getenv("DISABLE_XCODE_AS_CLANG_SEARCH") ) {
+            as = "/usr/bin/clang";
+            if(access(as, F_OK) != 0){
+              as = NULL;
+            }
+          }
+#endif
+          if (as != NULL) {
 	    new_argv = allocate((argc + 8) * sizeof(char *));
 	    new_argv[0] = as;
 	    j = 1;
@@ -360,6 +377,7 @@
 		exit(0);
 	    else
 		exit(1);
+        } /* as != NULL */
 	}
 
 	/*
