; 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.tokendefn = type { ptr, 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 willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @_lex_tokendefnwithtokenfirstcharcmp(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @lex_advanceby(ptr noundef, i64 noundef) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare ptr @bsearch(ptr noundef nonnull, ptr noundef nonnull, i64 noundef, i64 noundef, ptr noundef nonnull) #3

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @lex_identifytoken(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #4
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call signext i8 @lex_peek(ptr noundef %11)
  store i8 %12, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.slexer, ptr %13, i32 0, i32 14
  %15 = load ptr, ptr %14, align 8, !tbaa !10
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.slexer, ptr %16, i32 0, i32 15
  %18 = load i32, ptr %17, align 8, !tbaa !15
  %19 = sext i32 %18 to i64
  %20 = call ptr @bsearch(ptr noundef %6, ptr noundef %15, i64 noundef %19, i64 noundef 24, ptr noundef @_lex_tokendefnwithtokenfirstcharcmp)
  store ptr %20, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %24, label %23

23:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %106

24:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.slexer, ptr %25, i32 0, i32 14
  %27 = load ptr, ptr %26, align 8, !tbaa !10
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.slexer, ptr %28, i32 0, i32 15
  %30 = load i32, ptr %29, align 8, !tbaa !15
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds %struct.tokendefn, ptr %27, i64 %31
  %33 = getelementptr inbounds %struct.tokendefn, ptr %32, i64 -1
  store ptr %33, ptr %9, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %51, %24
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = icmp ult ptr %35, %36
  br i1 %37, label %38, label %49

38:                                               ; preds = %34
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.tokendefn, ptr %39, i64 1
  %41 = getelementptr inbounds %struct.tokendefn, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = getelementptr inbounds i8, ptr %42, i64 0
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = sext i8 %44 to i32
  %46 = load i8, ptr %6, align 1, !tbaa !9
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %45, %47
  br label %49

49:                                               ; preds = %38, %34
  %50 = phi i1 [ false, %34 ], [ %48, %38 ]
  br i1 %50, label %51, label %54

51:                                               ; preds = %49
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.tokendefn, ptr %52, i32 1
  store ptr %53, ptr %7, align 8, !tbaa !5
  br label %34, !llvm.loop !18

54:                                               ; preds = %49
  br label %55

55:                                               ; preds = %101, %54
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.tokendefn, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  %59 = getelementptr inbounds i8, ptr %58, i64 0
  %60 = load i8, ptr %59, align 1, !tbaa !9
  %61 = sext i8 %60 to i32
  %62 = load i8, ptr %6, align 1, !tbaa !9
  %63 = sext i8 %62 to i32
  %64 = icmp eq i32 %61, %63
  br i1 %64, label %65, label %71

65:                                               ; preds = %55
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.slexer, ptr %67, i32 0, i32 14
  %69 = load ptr, ptr %68, align 8, !tbaa !10
  %70 = icmp uge ptr %66, %69
  br label %71

71:                                               ; preds = %65, %55
  %72 = phi i1 [ false, %55 ], [ %70, %65 ]
  br i1 %72, label %73, label %104

73:                                               ; preds = %71
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.tokendefn, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !16
  %77 = call i64 @strlen(ptr noundef %76) #5
  store i64 %77, ptr %10, align 8, !tbaa !20
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.tokendefn, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !16
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.slexer, ptr %81, i32 0, i32 1
  %83 = load ptr, ptr %82, align 8, !tbaa !22
  %84 = load i64, ptr %10, align 8, !tbaa !20
  %85 = call i32 @strncmp(ptr noundef %80, ptr noundef %83, i64 noundef %84) #5
  %86 = icmp eq i32 %85, 0
  br i1 %86, label %87, label %97

87:                                               ; preds = %73
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = load i64, ptr %10, align 8, !tbaa !20
  %90 = call signext i8 @lex_advanceby(ptr noundef %88, i64 noundef %89)
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = icmp ne ptr %91, null
  br i1 %92, label %93, label %96

93:                                               ; preds = %87
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %94, ptr %95, align 8, !tbaa !5
  br label %96

96:                                               ; preds = %93, %87
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %98

97:                                               ; preds = %73
  store i32 0, ptr %8, align 4
  br label %98

98:                                               ; preds = %97, %96
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %99 = load i32, ptr %8, align 4
  switch i32 %99, label %105 [
    i32 0, label %100
  ]

100:                                              ; preds = %98
  br label %101

101:                                              ; preds = %100
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.tokendefn, ptr %102, i32 -1
  store ptr %103, ptr %7, align 8, !tbaa !5
  br label %55, !llvm.loop !23

104:                                              ; preds = %71
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %105

105:                                              ; preds = %104, %98
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %106

106:                                              ; preds = %105, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  %107 = load i1, ptr %3, align 1
  ret i1 %107
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(read) "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 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 #3 = { inlinehint 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 72}
!11 = !{!"slexer", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !13, i64 24, !13, i64 25, !6, i64 32, !6, i64 40, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !6, i64 72, !12, i64 80, !14, i64 88}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"", !12, i64 0, !12, i64 4, !6, i64 8}
!15 = !{!11, !12, i64 80}
!16 = !{!17, !6, i64 0}
!17 = !{!"", !6, i64 0, !12, i64 8, !6, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !21, i64 0}
!21 = !{!"long", !7, i64 0}
!22 = !{!11, !6, i64 8}
!23 = distinct !{!23, !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"

%struct.tokendefn = type { ptr, i32, ptr }

; 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: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strncmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @_lex_tokendefnwithtokenfirstcharcmp(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @lex_advanceby(ptr noundef, i64 noundef) local_unnamed_addr #2

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

; Function Attrs: inlinehint nounwind uwtable
declare ptr @bsearch(ptr noundef nonnull, ptr noundef nonnull, i64 noundef, i64 noundef, ptr noundef nonnull) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @lex_identifytoken(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #2 {
  %3 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #4
  %4 = tail call signext i8 @lex_peek(ptr noundef %0)
  store i8 %4, ptr %3, align 1, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 72
  %6 = load ptr, ptr %5, align 8, !tbaa !8
  %7 = getelementptr inbounds i8, ptr %0, i64 80
  %8 = load i32, ptr %7, align 8, !tbaa !14
  %9 = sext i32 %8 to i64
  %10 = call ptr @bsearch(ptr noundef %3, ptr noundef %6, i64 noundef %9, i64 noundef 24, ptr noundef @_lex_tokendefnwithtokenfirstcharcmp)
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %.critedge2, label %11

11:                                               ; preds = %2
  %12 = load ptr, ptr %5, align 8, !tbaa !8
  %13 = load i32, ptr %7, align 8, !tbaa !14
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds %struct.tokendefn, ptr %12, i64 %14
  %16 = getelementptr inbounds i8, ptr %15, i64 -24
  %17 = load i8, ptr %3, align 1
  br label %18

18:                                               ; preds = %20, %11
  %.026 = phi ptr [ %10, %11 ], [ %21, %20 ]
  %19 = icmp ult ptr %.026, %16
  br i1 %19, label %20, label %.critedge

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %.026, i64 24
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = icmp eq i8 %23, %17
  br i1 %24, label %18, label %.critedge, !llvm.loop !17

.critedge:                                        ; preds = %18, %20
  %25 = load ptr, ptr %.026, align 8, !tbaa !15
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = icmp eq i8 %26, %17
  br i1 %27, label %.lr.ph, label %.critedge2

.lr.ph:                                           ; preds = %.critedge
  %28 = getelementptr inbounds i8, ptr %0, i64 8
  br label %29

29:                                               ; preds = %.lr.ph, %.critedge35
  %30 = phi ptr [ %25, %.lr.ph ], [ %39, %.critedge35 ]
  %.12737 = phi ptr [ %.026, %.lr.ph ], [ %38, %.critedge35 ]
  %.not31 = icmp ult ptr %.12737, %12
  br i1 %.not31, label %.critedge2, label %31

31:                                               ; preds = %29
  %32 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %30) #5
  %33 = load ptr, ptr %28, align 8, !tbaa !19
  %34 = call i32 @strncmp(ptr noundef nonnull %30, ptr noundef %33, i64 noundef %32) #5
  %.not33 = icmp eq i32 %34, 0
  br i1 %.not33, label %35, label %.critedge35

35:                                               ; preds = %31
  %36 = call signext i8 @lex_advanceby(ptr noundef nonnull %0, i64 noundef %32)
  %.not32 = icmp eq ptr %1, null
  br i1 %.not32, label %.critedge2, label %37

37:                                               ; preds = %35
  store ptr %.12737, ptr %1, align 8, !tbaa !20
  br label %.critedge2

.critedge35:                                      ; preds = %31
  %38 = getelementptr inbounds i8, ptr %.12737, i64 -24
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = load i8, ptr %39, align 1, !tbaa !5
  %41 = icmp eq i8 %40, %17
  br i1 %41, label %29, label %.critedge2, !llvm.loop !21

.critedge2:                                       ; preds = %29, %.critedge35, %.critedge, %37, %35, %2
  %.3 = phi i1 [ false, %2 ], [ true, %35 ], [ true, %37 ], [ false, %.critedge ], [ false, %.critedge35 ], [ false, %29 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #4
  ret i1 %.3
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 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 #3 = { inlinehint 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

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


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