; 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 }
%struct.error = type { i32, ptr, ptr, i32, i32, [255 x i8] }
%struct.tokendefn = type { ptr, i32, ptr }

@.str.69 = external hidden unnamed_addr constant [11 x i8], align 1

; 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 zeroext i1 @lex_isatend(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @lex_identifytoken(ptr noundef, ptr noundef) #1

declare void @morpho_writeerrorwithid(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @lex(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  store i8 0, ptr %8, align 1, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.slexer, ptr %11, i32 0, i32 6
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %25

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.slexer, ptr %16, i32 0, i32 6
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = call zeroext i1 %18(ptr noundef %19, ptr noundef %20, ptr noundef %21)
  br i1 %22, label %24, label %23

23:                                               ; preds = %15
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %95

24:                                               ; preds = %15
  br label %25

25:                                               ; preds = %24, %3
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.slexer, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.slexer, ptr %29, i32 0, i32 0
  store ptr %28, ptr %30, align 8, !tbaa !16
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = call zeroext i1 @lex_isatend(ptr noundef %31)
  br i1 %32, label %33, label %39

33:                                               ; preds = %25
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.slexer, ptr %35, i32 0, i32 8
  %37 = load i32, ptr %36, align 8, !tbaa !17
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  call void @lex_recordtoken(ptr noundef %34, i32 noundef %37, ptr noundef %38)
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %95

39:                                               ; preds = %25
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.slexer, ptr %40, i32 0, i32 7
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %63

44:                                               ; preds = %39
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.slexer, ptr %45, i32 0, i32 7
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = call zeroext i1 %47(ptr noundef %48, ptr noundef %49, ptr noundef %50)
  %52 = zext i1 %51 to i8
  store i8 %52, ptr %8, align 1, !tbaa !9
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.error, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !19
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %44
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %95

58:                                               ; preds = %44
  %59 = load i8, ptr %8, align 1, !tbaa !9, !range !21, !noundef !22
  %60 = trunc i8 %59 to i1
  br i1 %60, label %61, label %62

61:                                               ; preds = %58
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %95

62:                                               ; preds = %58
  br label %63

63:                                               ; preds = %62, %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store ptr null, ptr %10, align 8, !tbaa !5
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = call zeroext i1 @lex_identifytoken(ptr noundef %64, ptr noundef %10)
  br i1 %65, label %66, label %72

66:                                               ; preds = %63
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.tokendefn, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 8, !tbaa !23
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  call void @lex_recordtoken(ptr noundef %67, i32 noundef %70, ptr noundef %71)
  br label %80

72:                                               ; preds = %63
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.slexer, ptr %74, i32 0, i32 2
  %76 = load i32, ptr %75, align 8, !tbaa !25
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.slexer, ptr %77, i32 0, i32 3
  %79 = load i32, ptr %78, align 4, !tbaa !26
  call void (ptr, ptr, ptr, i32, i32, ...) @morpho_writeerrorwithid(ptr noundef %73, ptr noundef @.str.69, ptr noundef null, i32 noundef %76, i32 noundef %79)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %94

80:                                               ; preds = %66
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.tokendefn, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !27
  %84 = icmp ne ptr %83, null
  br i1 %84, label %85, label %93

85:                                               ; preds = %80
  %86 = load ptr, ptr %10, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.tokendefn, ptr %86, i32 0, i32 2
  %88 = load ptr, ptr %87, align 8, !tbaa !27
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = call zeroext i1 %88(ptr noundef %89, ptr noundef %90, ptr noundef %91)
  store i1 %92, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %94

93:                                               ; preds = %80
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %94

94:                                               ; preds = %93, %85, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %95

95:                                               ; preds = %94, %61, %57, %33, %23
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  %96 = load i1, ptr %4, align 1
  ret i1 %96
}

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 = { "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 #3 = { 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 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !6, i64 32}
!12 = !{!"slexer", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 20, !10, i64 24, !10, 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, !14, i64 88}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !13, i64 0, !13, i64 4, !6, i64 8}
!15 = !{!12, !6, i64 8}
!16 = !{!12, !6, i64 0}
!17 = !{!12, !13, i64 48}
!18 = !{!12, !6, i64 40}
!19 = !{!20, !13, i64 0}
!20 = !{!"", !13, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 28, !7, i64 32}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!24, !13, i64 8}
!24 = !{!"", !6, i64 0, !13, i64 8, !6, i64 16}
!25 = !{!12, !13, i64 16}
!26 = !{!12, !13, i64 20}
!27 = !{!24, !6, i64 16}


; 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"

@.str.69 = external hidden unnamed_addr constant [11 x i8], align 1

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

; Function Attrs: mustprogress 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) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @lex_isatend(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @lex_identifytoken(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @morpho_writeerrorwithid(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, ...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @lex(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca ptr, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %9, label %7

7:                                                ; preds = %3
  %8 = tail call zeroext i1 %6(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2) #3
  br i1 %8, label %9, label %39

9:                                                ; preds = %7, %3
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  store ptr %11, ptr %0, align 8, !tbaa !14
  %12 = tail call zeroext i1 @lex_isatend(ptr noundef nonnull %0)
  br i1 %12, label %13, label %16

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %0, i64 48
  %15 = load i32, ptr %14, align 8, !tbaa !15
  tail call void @lex_recordtoken(ptr noundef nonnull %0, i32 noundef %15, ptr noundef %1)
  br label %39

16:                                               ; preds = %9
  %17 = getelementptr inbounds i8, ptr %0, i64 40
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %.not30 = icmp eq ptr %18, null
  br i1 %.not30, label %22, label %19

19:                                               ; preds = %16
  %20 = tail call zeroext i1 %18(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2) #3
  %21 = load i32, ptr %2, align 8, !tbaa !17
  %.not31 = icmp ne i32 %21, 0
  %brmerge = select i1 %.not31, i1 true, i1 %20
  %not..not31 = xor i1 %.not31, true
  br i1 %brmerge, label %39, label %22

22:                                               ; preds = %19, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store ptr null, ptr %4, align 8, !tbaa !19
  %23 = call zeroext i1 @lex_identifytoken(ptr noundef nonnull %0, ptr noundef nonnull %4)
  br i1 %23, label %24, label %31

24:                                               ; preds = %22
  %25 = load ptr, ptr %4, align 8, !tbaa !19
  %26 = getelementptr inbounds i8, ptr %25, i64 8
  %27 = load i32, ptr %26, align 8, !tbaa !20
  call void @lex_recordtoken(ptr noundef nonnull %0, i32 noundef %27, ptr noundef %1)
  %28 = load ptr, ptr %4, align 8, !tbaa !19
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  %30 = load ptr, ptr %29, align 8, !tbaa !22
  %.not32 = icmp eq ptr %30, null
  br i1 %.not32, label %38, label %36

31:                                               ; preds = %22
  %32 = getelementptr inbounds i8, ptr %0, i64 16
  %33 = load i32, ptr %32, align 8, !tbaa !23
  %34 = getelementptr inbounds i8, ptr %0, i64 20
  %35 = load i32, ptr %34, align 4, !tbaa !24
  call void (ptr, ptr, ptr, i32, i32, ...) @morpho_writeerrorwithid(ptr noundef %2, ptr noundef nonnull @.str.69, ptr noundef null, i32 noundef %33, i32 noundef %35) #3
  br label %38

36:                                               ; preds = %24
  %37 = call zeroext i1 %30(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2) #3
  br label %38

38:                                               ; preds = %24, %36, %31
  %.0 = phi i1 [ %37, %36 ], [ false, %31 ], [ true, %24 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  br label %39

39:                                               ; preds = %19, %7, %38, %13
  %.1 = phi i1 [ true, %13 ], [ %.0, %38 ], [ false, %7 ], [ %not..not31, %19 ]
  ret i1 %.1
}

attributes #0 = { mustprogress 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 = { "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 #3 = { 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, !7, i64 32}
!6 = !{!"slexer", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !11, i64 24, !11, i64 25, !7, i64 32, !7, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !7, i64 72, !10, i64 80, !12, i64 88}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4, !7, i64 8}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 0}
!15 = !{!6, !10, i64 48}
!16 = !{!6, !7, i64 40}
!17 = !{!18, !10, i64 0}
!18 = !{!"", !10, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !8, i64 32}
!19 = !{!7, !7, i64 0}
!20 = !{!21, !10, i64 8}
!21 = !{!"", !7, i64 0, !10, i64 8, !7, i64 16}
!22 = !{!21, !7, i64 16}
!23 = !{!6, !10, i64 16}
!24 = !{!6, !10, i64 20}


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