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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @lex_skipcomment(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
  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) #2
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = call signext i8 @lex_peekahead(ptr noundef %10, i32 noundef 1)
  store i8 %11, ptr %8, align 1, !tbaa !9
  %12 = load i8, ptr %8, align 1, !tbaa !9
  %13 = sext i8 %12 to i32
  %14 = icmp eq i32 %13, 47
  br i1 %14, label %15, label %31

15:                                               ; preds = %3
  br label %16

16:                                               ; preds = %27, %15
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call signext i8 @lex_peek(ptr noundef %17)
  %19 = sext i8 %18 to i32
  %20 = icmp ne i32 %19, 10
  br i1 %20, label %21, label %25

21:                                               ; preds = %16
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call zeroext i1 @lex_isatend(ptr noundef %22)
  %24 = xor i1 %23, true
  br label %25

25:                                               ; preds = %21, %16
  %26 = phi i1 [ false, %16 ], [ %24, %21 ]
  br i1 %26, label %27, label %30

27:                                               ; preds = %25
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call signext i8 @lex_advance(ptr noundef %28)
  br label %16, !llvm.loop !10

30:                                               ; preds = %25
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %42

31:                                               ; preds = %3
  %32 = load i8, ptr %8, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 42
  br i1 %34, label %35, label %40

35:                                               ; preds = %31
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = call zeroext i1 @lex_skipmultilinecomment(ptr noundef %36, ptr noundef %37, ptr noundef %38)
  store i1 %39, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %42

40:                                               ; preds = %31
  br label %41

41:                                               ; preds = %40
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %42

42:                                               ; preds = %41, %35, %30
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  %43 = load i1, ptr %4, align 1
  ret i1 %43
}

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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

; 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 zeroext i1 @lex_skipmultilinecomment(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @lex_skipcomment(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call signext i8 @lex_peekahead(ptr noundef %0, i32 noundef 1)
  switch i8 %4, label %.critedge [
    i8 47, label %.preheader
    i8 42, label %10
  ]

.preheader:                                       ; preds = %3
  %5 = tail call signext i8 @lex_peek(ptr noundef %0)
  %.not10 = icmp eq i8 %5, 10
  br i1 %.not10, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %7
  %6 = tail call zeroext i1 @lex_isatend(ptr noundef %0)
  br i1 %6, label %.critedge, label %7

7:                                                ; preds = %.lr.ph
  %8 = tail call signext i8 @lex_advance(ptr noundef %0)
  %9 = tail call signext i8 @lex_peek(ptr noundef %0)
  %.not = icmp eq i8 %9, 10
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !5

10:                                               ; preds = %3
  %11 = tail call zeroext i1 @lex_skipmultilinecomment(ptr noundef %0, ptr noundef %1, ptr noundef %2)
  br label %.critedge

.critedge:                                        ; preds = %7, %.lr.ph, %.preheader, %3, %10
  %.0 = phi i1 [ %11, %10 ], [ false, %3 ], [ true, %.preheader ], [ true, %.lr.ph ], [ true, %7 ]
  ret i1 %.0
}

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


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