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

@.str.68 = 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 signext i8 @lex_advance(ptr noundef) #1

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

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

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

20:                                               ; preds = %77, %3
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call signext i8 @lex_peek(ptr noundef %21)
  %23 = sext i8 %22 to i32
  %24 = icmp ne i32 %23, 34
  br i1 %24, label %25, label %29

25:                                               ; preds = %20
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call zeroext i1 @lex_isatend(ptr noundef %26)
  %28 = xor i1 %27, true
  br label %29

29:                                               ; preds = %25, %20
  %30 = phi i1 [ false, %20 ], [ %28, %25 ]
  br i1 %30, label %31, label %80

31:                                               ; preds = %29
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = call signext i8 @lex_peek(ptr noundef %32)
  %34 = sext i8 %33 to i32
  %35 = icmp eq i32 %34, 10
  br i1 %35, label %36, label %38

36:                                               ; preds = %31
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  call void @lex_newline(ptr noundef %37)
  br label %38

38:                                               ; preds = %36, %31
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.slexer, ptr %39, i32 0, i32 5
  %41 = load i8, ptr %40, align 1, !tbaa !17, !range !18, !noundef !19
  %42 = trunc i8 %41 to i1
  br i1 %42, label %43, label %69

43:                                               ; preds = %38
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = call signext i8 @lex_peek(ptr noundef %44)
  %46 = sext i8 %45 to i32
  %47 = icmp eq i32 %46, 36
  br i1 %47, label %48, label %69

48:                                               ; preds = %43
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = call signext i8 @lex_peekahead(ptr noundef %49, i32 noundef 1)
  %51 = sext i8 %50 to i32
  %52 = icmp eq i32 %51, 123
  br i1 %52, label %53, label %69

53:                                               ; preds = %48
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = call signext i8 @lex_advance(ptr noundef %54)
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = call signext i8 @lex_advance(ptr noundef %56)
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  call void @lex_recordtoken(ptr noundef %58, i32 noundef 3, ptr noundef %59)
  %60 = load i8, ptr %10, align 1, !tbaa !16
  %61 = sext i8 %60 to i32
  %62 = icmp eq i32 %61, 34
  br i1 %62, label %63, label %68

63:                                               ; preds = %53
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.slexer, ptr %64, i32 0, i32 13
  %66 = load i32, ptr %65, align 4, !tbaa !20
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %65, align 4, !tbaa !20
  br label %68

68:                                               ; preds = %63, %53
  store i1 true, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %113

69:                                               ; preds = %48, %43, %38
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = call signext i8 @lex_peek(ptr noundef %70)
  %72 = sext i8 %71 to i32
  %73 = icmp eq i32 %72, 92
  br i1 %73, label %74, label %77

74:                                               ; preds = %69
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = call signext i8 @lex_advance(ptr noundef %75)
  br label %77

77:                                               ; preds = %74, %69
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = call signext i8 @lex_advance(ptr noundef %78)
  br label %20, !llvm.loop !21

80:                                               ; preds = %29
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = call zeroext i1 @lex_isatend(ptr noundef %81)
  br i1 %82, label %83, label %89

83:                                               ; preds = %80
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  %85 = load i32, ptr %8, align 4, !tbaa !14
  %86 = load i32, ptr %9, align 4, !tbaa !14
  call void (ptr, ptr, ptr, i32, i32, ...) @morpho_writeerrorwithid(ptr noundef %84, ptr noundef @.str.68, ptr noundef null, i32 noundef %85, i32 noundef %86)
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  call void @lex_recordtoken(ptr noundef %87, i32 noundef 71, ptr noundef %88)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %113

89:                                               ; preds = %80
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = call signext i8 @lex_advance(ptr noundef %90)
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.slexer, ptr %92, i32 0, i32 5
  %94 = load i8, ptr %93, align 1, !tbaa !17, !range !18, !noundef !19
  %95 = trunc i8 %94 to i1
  br i1 %95, label %96, label %110

96:                                               ; preds = %89
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.slexer, ptr %97, i32 0, i32 13
  %99 = load i32, ptr %98, align 4, !tbaa !20
  %100 = icmp sgt i32 %99, 0
  br i1 %100, label %101, label %110

101:                                              ; preds = %96
  %102 = load i8, ptr %10, align 1, !tbaa !16
  %103 = sext i8 %102 to i32
  %104 = icmp eq i32 %103, 125
  br i1 %104, label %105, label %110

105:                                              ; preds = %101
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.slexer, ptr %106, i32 0, i32 13
  %108 = load i32, ptr %107, align 4, !tbaa !20
  %109 = add nsw i32 %108, -1
  store i32 %109, ptr %107, align 4, !tbaa !20
  br label %110

110:                                              ; preds = %105, %101, %96, %89
  %111 = load ptr, ptr %5, align 8, !tbaa !5
  %112 = load ptr, ptr %6, align 8, !tbaa !5
  call void @lex_recordtoken(ptr noundef %111, i32 noundef 2, ptr noundef %112)
  store i1 true, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %113

113:                                              ; preds = %110, %83, %68
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %114 = load i1, ptr %4, align 1
  ret i1 %114
}

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

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, !11, i64 16}
!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 = !{!10, !11, i64 20}
!16 = !{!7, !7, i64 0}
!17 = !{!10, !12, i64 25}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!10, !11, i64 68}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; 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.68 = external hidden unnamed_addr constant [11 x i8], align 1

; 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_isatend(ptr noundef) 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
declare dso_local signext i8 @lex_peekprevious(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @lex_string(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 20
  %7 = load i32, ptr %6, align 4, !tbaa !13
  %8 = tail call signext i8 @lex_peekprevious(ptr noundef %0)
  %9 = tail call signext i8 @lex_peek(ptr noundef nonnull %0)
  %.not35 = icmp eq i8 %9, 34
  br i1 %.not35, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 25
  br label %11

11:                                               ; preds = %.lr.ph, %39
  %12 = tail call zeroext i1 @lex_isatend(ptr noundef nonnull %0)
  br i1 %12, label %.critedge, label %13

13:                                               ; preds = %11
  %14 = tail call signext i8 @lex_peek(ptr noundef nonnull %0)
  %15 = icmp eq i8 %14, 10
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  tail call void @lex_newline(ptr noundef %0)
  br label %17

17:                                               ; preds = %16, %13
  %18 = load i8, ptr %10, align 1, !tbaa !14, !range !15, !noundef !16
  %19 = trunc nuw i8 %18 to i1
  br i1 %19, label %20, label %34

20:                                               ; preds = %17
  %21 = tail call signext i8 @lex_peek(ptr noundef nonnull %0)
  %22 = icmp eq i8 %21, 36
  br i1 %22, label %23, label %34

23:                                               ; preds = %20
  %24 = tail call signext i8 @lex_peekahead(ptr noundef nonnull %0, i32 noundef 1)
  %25 = icmp eq i8 %24, 123
  br i1 %25, label %26, label %34

26:                                               ; preds = %23
  %27 = tail call signext i8 @lex_advance(ptr noundef nonnull %0)
  %28 = tail call signext i8 @lex_advance(ptr noundef nonnull %0)
  tail call void @lex_recordtoken(ptr noundef nonnull %0, i32 noundef 3, ptr noundef %1)
  %29 = icmp eq i8 %8, 34
  br i1 %29, label %30, label %57

30:                                               ; preds = %26
  %31 = getelementptr inbounds i8, ptr %0, i64 68
  %32 = load i32, ptr %31, align 4, !tbaa !17
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %31, align 4, !tbaa !17
  br label %57

34:                                               ; preds = %23, %20, %17
  %35 = tail call signext i8 @lex_peek(ptr noundef nonnull %0)
  %36 = icmp eq i8 %35, 92
  br i1 %36, label %37, label %39

37:                                               ; preds = %34
  %38 = tail call signext i8 @lex_advance(ptr noundef nonnull %0)
  br label %39

39:                                               ; preds = %37, %34
  %40 = tail call signext i8 @lex_advance(ptr noundef nonnull %0)
  %41 = tail call signext i8 @lex_peek(ptr noundef nonnull %0)
  %.not = icmp eq i8 %41, 34
  br i1 %.not, label %.critedge, label %11, !llvm.loop !18

.critedge:                                        ; preds = %11, %39, %3
  %42 = tail call zeroext i1 @lex_isatend(ptr noundef nonnull %0)
  br i1 %42, label %43, label %44

43:                                               ; preds = %.critedge
  tail call void (ptr, ptr, ptr, i32, i32, ...) @morpho_writeerrorwithid(ptr noundef %2, ptr noundef nonnull @.str.68, ptr noundef null, i32 noundef %5, i32 noundef %7) #2
  tail call void @lex_recordtoken(ptr noundef nonnull %0, i32 noundef 71, ptr noundef %1)
  br label %57

44:                                               ; preds = %.critedge
  %45 = tail call signext i8 @lex_advance(ptr noundef nonnull %0)
  %46 = getelementptr inbounds i8, ptr %0, i64 25
  %47 = load i8, ptr %46, align 1, !tbaa !14, !range !15, !noundef !16
  %48 = trunc nuw i8 %47 to i1
  br i1 %48, label %49, label %56

49:                                               ; preds = %44
  %50 = getelementptr inbounds i8, ptr %0, i64 68
  %51 = load i32, ptr %50, align 4, !tbaa !17
  %52 = icmp sgt i32 %51, 0
  %53 = icmp eq i8 %8, 125
  %or.cond = select i1 %52, i1 %53, i1 false
  br i1 %or.cond, label %54, label %56

54:                                               ; preds = %49
  %55 = add nsw i32 %51, -1
  store i32 %55, ptr %50, align 4, !tbaa !17
  br label %56

56:                                               ; preds = %54, %49, %44
  tail call void @lex_recordtoken(ptr noundef nonnull %0, i32 noundef 2, ptr noundef %1)
  br label %57

57:                                               ; preds = %26, %30, %56, %43
  %.0 = phi i1 [ false, %43 ], [ true, %56 ], [ true, %30 ], [ true, %26 ]
  ret i1 %.0
}

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

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" }
attributes #1 = { "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, !10, i64 16}
!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, !10, i64 20}
!14 = !{!6, !11, i64 25}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!6, !10, i64 68}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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