; 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_isdigit(i8 noundef signext) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @lex_isspace(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 signext i8 @lex_peekahead(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @lex_number(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
  %8 = alloca i8, align 1
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.slexer, ptr %9, i32 0, i32 9
  %11 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %11, ptr %7, align 4, !tbaa !14
  br label %12

12:                                               ; preds = %16, %3
  %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 i1 %15, label %16, label %19

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

19:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  store i8 0, ptr %8, align 1, !tbaa !17
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call signext i8 @lex_peek(ptr noundef %20)
  %22 = sext i8 %21 to i32
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %27

24:                                               ; preds = %19
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = call signext i8 @lex_peekahead(ptr noundef %25, i32 noundef 1)
  store i8 %26, ptr %8, align 1, !tbaa !17
  br label %27

27:                                               ; preds = %24, %19
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call signext i8 @lex_peek(ptr noundef %28)
  %30 = sext i8 %29 to i32
  %31 = icmp eq i32 %30, 46
  br i1 %31, label %32, label %56

32:                                               ; preds = %27
  %33 = load i8, ptr %8, align 1, !tbaa !17
  %34 = call zeroext i1 @lex_isdigit(i8 noundef signext %33)
  br i1 %34, label %42, label %35

35:                                               ; preds = %32
  %36 = load i8, ptr %8, align 1, !tbaa !17
  %37 = call zeroext i1 @lex_isspace(i8 noundef signext %36)
  br i1 %37, label %42, label %38

38:                                               ; preds = %35
  %39 = load i8, ptr %8, align 1, !tbaa !17
  %40 = sext i8 %39 to i32
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %56

42:                                               ; preds = %38, %35, %32
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.slexer, ptr %43, i32 0, i32 10
  %45 = load i32, ptr %44, align 8, !tbaa !18
  store i32 %45, ptr %7, align 4, !tbaa !14
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = call signext i8 @lex_advance(ptr noundef %46)
  br label %48

48:                                               ; preds = %52, %42
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = call signext i8 @lex_peek(ptr noundef %49)
  %51 = call zeroext i1 @lex_isdigit(i8 noundef signext %50)
  br i1 %51, label %52, label %55

52:                                               ; preds = %48
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = call signext i8 @lex_advance(ptr noundef %53)
  br label %48, !llvm.loop !19

55:                                               ; preds = %48
  br label %56

56:                                               ; preds = %55, %38, %27
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = call signext i8 @lex_peek(ptr noundef %57)
  %59 = sext i8 %58 to i32
  %60 = icmp eq i32 %59, 101
  br i1 %60, label %66, label %61

61:                                               ; preds = %56
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = call signext i8 @lex_peek(ptr noundef %62)
  %64 = sext i8 %63 to i32
  %65 = icmp eq i32 %64, 69
  br i1 %65, label %66, label %93

66:                                               ; preds = %61, %56
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.slexer, ptr %67, i32 0, i32 10
  %69 = load i32, ptr %68, align 8, !tbaa !18
  store i32 %69, ptr %7, align 4, !tbaa !14
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = call signext i8 @lex_advance(ptr noundef %70)
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = call signext i8 @lex_peek(ptr noundef %72)
  %74 = sext i8 %73 to i32
  %75 = icmp eq i32 %74, 43
  br i1 %75, label %81, label %76

76:                                               ; preds = %66
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = call signext i8 @lex_peek(ptr noundef %77)
  %79 = sext i8 %78 to i32
  %80 = icmp eq i32 %79, 45
  br i1 %80, label %81, label %84

81:                                               ; preds = %76, %66
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = call signext i8 @lex_advance(ptr noundef %82)
  br label %84

84:                                               ; preds = %81, %76
  br label %85

85:                                               ; preds = %89, %84
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = call signext i8 @lex_peek(ptr noundef %86)
  %88 = call zeroext i1 @lex_isdigit(i8 noundef signext %87)
  br i1 %88, label %89, label %92

89:                                               ; preds = %85
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = call signext i8 @lex_advance(ptr noundef %90)
  br label %85, !llvm.loop !20

92:                                               ; preds = %85
  br label %93

93:                                               ; preds = %92, %61
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = call signext i8 @lex_peek(ptr noundef %94)
  %96 = sext i8 %95 to i32
  %97 = icmp eq i32 %96, 105
  br i1 %97, label %98, label %111

98:                                               ; preds = %93
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = call signext i8 @lex_peekahead(ptr noundef %99, i32 noundef 1)
  %101 = sext i8 %100 to i32
  %102 = icmp eq i32 %101, 109
  br i1 %102, label %103, label %111

103:                                              ; preds = %98
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.slexer, ptr %104, i32 0, i32 11
  %106 = load i32, ptr %105, align 4, !tbaa !21
  store i32 %106, ptr %7, align 4, !tbaa !14
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  %108 = call signext i8 @lex_advance(ptr noundef %107)
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = call signext i8 @lex_advance(ptr noundef %109)
  br label %111

111:                                              ; preds = %103, %98, %93
  %112 = load ptr, ptr %4, align 8, !tbaa !5
  %113 = load i32, ptr %7, align 4, !tbaa !14
  %114 = load ptr, ptr %5, align 8, !tbaa !5
  call void @lex_recordtoken(ptr noundef %112, i32 noundef %113, ptr noundef %114)
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  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 = !{!10, !11, i64 52}
!10 = !{!"slexer", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !12, i64 24, !12, i64 25, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !6, i64 72, !11, i64 80, !13, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"", !11, i64 0, !11, i64 4, !6, i64 8}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!7, !7, i64 0}
!18 = !{!10, !11, i64 56}
!19 = distinct !{!19, !16}
!20 = distinct !{!20, !16}
!21 = !{!10, !11, i64 60}


; 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_isdigit(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @lex_isspace(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 signext i8 @lex_peekahead(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @lex_number(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readnone %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 52
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = tail call signext i8 @lex_peek(ptr noundef %0)
  %7 = tail call zeroext i1 @lex_isdigit(i8 noundef signext %6)
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %8 = tail call signext i8 @lex_advance(ptr noundef %0)
  %9 = tail call signext i8 @lex_peek(ptr noundef %0)
  %10 = tail call zeroext i1 @lex_isdigit(i8 noundef signext %9)
  br i1 %10, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %3
  %11 = tail call signext i8 @lex_peek(ptr noundef %0)
  %.not = icmp eq i8 %11, 0
  br i1 %.not, label %14, label %12

12:                                               ; preds = %._crit_edge
  %13 = tail call signext i8 @lex_peekahead(ptr noundef %0, i32 noundef 1)
  br label %14

14:                                               ; preds = %12, %._crit_edge
  %.0 = phi i8 [ %13, %12 ], [ 0, %._crit_edge ]
  %15 = tail call signext i8 @lex_peek(ptr noundef %0)
  %16 = icmp eq i8 %15, 46
  br i1 %16, label %17, label %.loopexit32

17:                                               ; preds = %14
  %18 = tail call zeroext i1 @lex_isdigit(i8 noundef signext %.0)
  br i1 %18, label %22, label %19

19:                                               ; preds = %17
  %20 = tail call zeroext i1 @lex_isspace(i8 noundef signext %.0)
  %21 = icmp eq i8 %.0, 0
  %or.cond = select i1 %20, i1 true, i1 %21
  br i1 %or.cond, label %22, label %.loopexit32

22:                                               ; preds = %19, %17
  %23 = getelementptr inbounds i8, ptr %0, i64 56
  %24 = load i32, ptr %23, align 8, !tbaa !15
  %25 = tail call signext i8 @lex_advance(ptr noundef %0)
  %26 = tail call signext i8 @lex_peek(ptr noundef %0)
  %27 = tail call zeroext i1 @lex_isdigit(i8 noundef signext %26)
  br i1 %27, label %.lr.ph34, label %.loopexit32

.lr.ph34:                                         ; preds = %22, %.lr.ph34
  %28 = tail call signext i8 @lex_advance(ptr noundef %0)
  %29 = tail call signext i8 @lex_peek(ptr noundef %0)
  %30 = tail call zeroext i1 @lex_isdigit(i8 noundef signext %29)
  br i1 %30, label %.lr.ph34, label %.loopexit32, !llvm.loop !16

.loopexit32:                                      ; preds = %.lr.ph34, %22, %19, %14
  %.031 = phi i32 [ %5, %19 ], [ %5, %14 ], [ %24, %22 ], [ %24, %.lr.ph34 ]
  %31 = tail call signext i8 @lex_peek(ptr noundef %0)
  %32 = icmp eq i8 %31, 101
  br i1 %32, label %36, label %33

33:                                               ; preds = %.loopexit32
  %34 = tail call signext i8 @lex_peek(ptr noundef %0)
  %35 = icmp eq i8 %34, 69
  br i1 %35, label %36, label %.loopexit

36:                                               ; preds = %33, %.loopexit32
  %37 = getelementptr inbounds i8, ptr %0, i64 56
  %38 = load i32, ptr %37, align 8, !tbaa !15
  %39 = tail call signext i8 @lex_advance(ptr noundef %0)
  %40 = tail call signext i8 @lex_peek(ptr noundef %0)
  %41 = icmp eq i8 %40, 43
  br i1 %41, label %45, label %42

42:                                               ; preds = %36
  %43 = tail call signext i8 @lex_peek(ptr noundef nonnull %0)
  %44 = icmp eq i8 %43, 45
  br i1 %44, label %45, label %47

45:                                               ; preds = %42, %36
  %46 = tail call signext i8 @lex_advance(ptr noundef nonnull %0)
  br label %47

47:                                               ; preds = %45, %42
  %48 = tail call signext i8 @lex_peek(ptr noundef nonnull %0)
  %49 = tail call zeroext i1 @lex_isdigit(i8 noundef signext %48)
  br i1 %49, label %.lr.ph36, label %.loopexit

.lr.ph36:                                         ; preds = %47, %.lr.ph36
  %50 = tail call signext i8 @lex_advance(ptr noundef %0)
  %51 = tail call signext i8 @lex_peek(ptr noundef %0)
  %52 = tail call zeroext i1 @lex_isdigit(i8 noundef signext %51)
  br i1 %52, label %.lr.ph36, label %.loopexit, !llvm.loop !17

.loopexit:                                        ; preds = %.lr.ph36, %47, %33
  %.1 = phi i32 [ %.031, %33 ], [ %38, %47 ], [ %38, %.lr.ph36 ]
  %53 = tail call signext i8 @lex_peek(ptr noundef %0)
  %54 = icmp eq i8 %53, 105
  br i1 %54, label %55, label %63

55:                                               ; preds = %.loopexit
  %56 = tail call signext i8 @lex_peekahead(ptr noundef %0, i32 noundef 1)
  %57 = icmp eq i8 %56, 109
  br i1 %57, label %58, label %63

58:                                               ; preds = %55
  %59 = getelementptr inbounds i8, ptr %0, i64 60
  %60 = load i32, ptr %59, align 4, !tbaa !18
  %61 = tail call signext i8 @lex_advance(ptr noundef %0)
  %62 = tail call signext i8 @lex_advance(ptr noundef %0)
  br label %63

63:                                               ; preds = %58, %55, %.loopexit
  %.2 = phi i32 [ %60, %58 ], [ %.1, %55 ], [ %.1, %.loopexit ]
  tail call void @lex_recordtoken(ptr noundef %0, i32 noundef %.2, 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 = !{!6, !10, i64 52}
!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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !10, i64 56}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}
!18 = !{!6, !10, i64 60}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass