; LLVM IR from Morpho-lang/morpho :: src/support (lex)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.slexer = type { ptr, ptr, i32, i32, i8, i8, ptr, ptr, i32, i32, i32, i32, i32, i32, ptr, i32, %struct.varray_tokendefn }
%struct.varray_tokendefn = type { i32, i32, ptr }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @lex_recordtoken(ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @lex_advance(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @lex_isalpha(i8 noundef signext) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @lex_isdigit(i8 noundef signext) #1

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @lex_peek(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @lex_typeforsymboltoken(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @lex_symbol(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %18, %3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call signext i8 @lex_peek(ptr noundef %9)
  %11 = call zeroext i1 @lex_isalpha(i8 noundef signext %10)
  br i1 %11, label %16, label %12

12:                                               ; preds = %8
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call signext i8 @lex_peek(ptr noundef %13)
  %15 = call zeroext i1 @lex_isdigit(i8 noundef signext %14)
  br label %16

16:                                               ; preds = %12, %8
  %17 = phi i1 [ true, %8 ], [ %15, %12 ]
  br i1 %17, label %18, label %21

18:                                               ; preds = %16
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = call signext i8 @lex_advance(ptr noundef %19)
  br label %8, !llvm.loop !9

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.slexer, ptr %22, i32 0, i32 12
  %24 = load i32, ptr %23, align 8, !tbaa !11
  store i32 %24, ptr %7, align 4, !tbaa !16
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.slexer, ptr %25, i32 0, i32 4
  %27 = load i8, ptr %26, align 8, !tbaa !17, !range !18, !noundef !19
  %28 = trunc i8 %27 to i1
  br i1 %28, label %29, label %32

29:                                               ; preds = %21
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = call i32 @lex_typeforsymboltoken(ptr noundef %30)
  store i32 %31, ptr %7, align 4, !tbaa !16
  br label %32

32:                                               ; preds = %29, %21
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load i32, ptr %7, align 4, !tbaa !16
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  call void @lex_recordtoken(ptr noundef %33, i32 noundef %34, ptr noundef %35)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i1 true
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !13, i64 64}
!12 = !{!"slexer", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 20, !14, i64 24, !14, i64 25, !6, i64 32, !6, i64 40, !13, i64 48, !13, i64 52, !13, i64 56, !13, i64 60, !13, i64 64, !13, i64 68, !6, i64 72, !13, i64 80, !15, i64 88}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!"", !13, i64 0, !13, i64 4, !6, i64 8}
!16 = !{!13, !13, i64 0}
!17 = !{!12, !14, i64 24}
!18 = !{i8 0, i8 2}
!19 = !{}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
declare dso_local void @lex_recordtoken(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @lex_advance(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @lex_isalpha(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @lex_isdigit(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @lex_peek(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @lex_typeforsymboltoken(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @lex_symbol(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readnone %2) local_unnamed_addr #0 {
  br label %4

4:                                                ; preds = %.critedge, %3
  %5 = tail call signext i8 @lex_peek(ptr noundef %0)
  %6 = tail call zeroext i1 @lex_isalpha(i8 noundef signext %5)
  br i1 %6, label %.critedge, label %7

7:                                                ; preds = %4
  %8 = tail call signext i8 @lex_peek(ptr noundef %0)
  %9 = tail call zeroext i1 @lex_isdigit(i8 noundef signext %8)
  br i1 %9, label %.critedge, label %11

.critedge:                                        ; preds = %4, %7
  %10 = tail call signext i8 @lex_advance(ptr noundef %0)
  br label %4, !llvm.loop !5

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 64
  %13 = load i32, ptr %12, align 8, !tbaa !7
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = load i8, ptr %14, align 8, !tbaa !15, !range !16, !noundef !17
  %16 = trunc nuw i8 %15 to i1
  br i1 %16, label %17, label %19

17:                                               ; preds = %11
  %18 = tail call i32 @lex_typeforsymboltoken(ptr noundef nonnull %0)
  br label %19

19:                                               ; preds = %17, %11
  %.0 = phi i32 [ %18, %17 ], [ %13, %11 ]
  tail call void @lex_recordtoken(ptr noundef nonnull %0, i32 noundef %.0, ptr noundef %1)
  ret i1 true
}

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !12, i64 64}
!8 = !{!"slexer", !9, i64 0, !9, i64 8, !12, i64 16, !12, i64 20, !13, i64 24, !13, i64 25, !9, i64 32, !9, i64 40, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !9, i64 72, !12, i64 80, !14, i64 88}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"int", !10, i64 0}
!13 = !{!"_Bool", !10, i64 0}
!14 = !{!"", !12, i64 0, !12, i64 4, !9, i64 8}
!15 = !{!8, !13, i64 24}
!16 = !{i8 0, i8 2}
!17 = !{}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass