; LLVM IR from freakout42/macrocalc :: mc/mex (word)

; 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.WINDOW = type { ptr, ptr, ptr, ptr, i32, ptr, i32, i32, i32, i32, i32, i32 }
%struct.LINE = type { ptr, ptr, i16, i16, [32768 x i8] }
%struct.BUFFER = type { ptr, ptr, i32, ptr, i32, ptr, i32, i32, [128 x i8], [128 x i8] }

@curwp = external global ptr, align 8
@curbp = external global ptr, align 8

; 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
define dso_local i32 @backparag(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %7 = load ptr, ptr @curwp, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct.WINDOW, ptr %7, i32 0, i32 3
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds %struct.LINE, ptr %9, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  store ptr %11, ptr %5, align 8, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %12, ptr %6, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %44, %2
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  %15 = load ptr, ptr @curbp, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.BUFFER, ptr %15, i32 0, i32 5
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = icmp ne ptr %14, %17
  br i1 %18, label %19, label %42

19:                                               ; preds = %13
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.LINE, ptr %20, i32 0, i32 3
  %22 = load i16, ptr %21, align 2, !tbaa !18
  %23 = sext i16 %22 to i32
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %39

25:                                               ; preds = %19
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.LINE, ptr %26, i32 0, i32 4
  %28 = getelementptr inbounds [32768 x i8], ptr %27, i64 0, i64 0
  %29 = load i8, ptr %28, align 4, !tbaa !19
  %30 = sext i8 %29 to i32
  %31 = icmp ne i32 %30, 46
  br i1 %31, label %32, label %39

32:                                               ; preds = %25
  %33 = load ptr, ptr %5, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.LINE, ptr %33, i32 0, i32 4
  %35 = getelementptr inbounds [32768 x i8], ptr %34, i64 0, i64 0
  %36 = load i8, ptr %35, align 4, !tbaa !19
  %37 = sext i8 %36 to i32
  %38 = icmp ne i32 %37, 92
  br label %39

39:                                               ; preds = %32, %25, %19
  %40 = phi i1 [ false, %25 ], [ false, %19 ], [ %38, %32 ]
  %41 = xor i1 %40, true
  br label %42

42:                                               ; preds = %39, %13
  %43 = phi i1 [ false, %13 ], [ %41, %39 ]
  br i1 %43, label %44, label %49

44:                                               ; preds = %42
  %45 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %45, ptr %6, align 8, !tbaa !9
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.LINE, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  store ptr %48, ptr %5, align 8, !tbaa !9
  br label %13, !llvm.loop !20

49:                                               ; preds = %42
  br label %50

50:                                               ; preds = %80, %49
  %51 = load ptr, ptr %5, align 8, !tbaa !9
  %52 = load ptr, ptr @curbp, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.BUFFER, ptr %52, i32 0, i32 5
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = icmp ne ptr %51, %54
  br i1 %55, label %56, label %78

56:                                               ; preds = %50
  %57 = load ptr, ptr %5, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.LINE, ptr %57, i32 0, i32 3
  %59 = load i16, ptr %58, align 2, !tbaa !18
  %60 = sext i16 %59 to i32
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %76

62:                                               ; preds = %56
  %63 = load ptr, ptr %5, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.LINE, ptr %63, i32 0, i32 4
  %65 = getelementptr inbounds [32768 x i8], ptr %64, i64 0, i64 0
  %66 = load i8, ptr %65, align 4, !tbaa !19
  %67 = sext i8 %66 to i32
  %68 = icmp ne i32 %67, 46
  br i1 %68, label %69, label %76

69:                                               ; preds = %62
  %70 = load ptr, ptr %5, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.LINE, ptr %70, i32 0, i32 4
  %72 = getelementptr inbounds [32768 x i8], ptr %71, i64 0, i64 0
  %73 = load i8, ptr %72, align 4, !tbaa !19
  %74 = sext i8 %73 to i32
  %75 = icmp ne i32 %74, 92
  br label %76

76:                                               ; preds = %69, %62, %56
  %77 = phi i1 [ false, %62 ], [ false, %56 ], [ %75, %69 ]
  br label %78

78:                                               ; preds = %76, %50
  %79 = phi i1 [ false, %50 ], [ %77, %76 ]
  br i1 %79, label %80, label %85

80:                                               ; preds = %78
  %81 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %81, ptr %6, align 8, !tbaa !9
  %82 = load ptr, ptr %5, align 8, !tbaa !9
  %83 = getelementptr inbounds %struct.LINE, ptr %82, i32 0, i32 1
  %84 = load ptr, ptr %83, align 8, !tbaa !13
  store ptr %84, ptr %5, align 8, !tbaa !9
  br label %50, !llvm.loop !22

85:                                               ; preds = %78
  %86 = load ptr, ptr %6, align 8, !tbaa !9
  %87 = load ptr, ptr @curwp, align 8, !tbaa !9
  %88 = getelementptr inbounds %struct.WINDOW, ptr %87, i32 0, i32 3
  store ptr %86, ptr %88, align 8, !tbaa !11
  %89 = load ptr, ptr @curwp, align 8, !tbaa !9
  %90 = getelementptr inbounds %struct.WINDOW, ptr %89, i32 0, i32 4
  store i32 0, ptr %90, align 8, !tbaa !23
  %91 = load ptr, ptr @curwp, align 8, !tbaa !9
  %92 = getelementptr inbounds %struct.WINDOW, ptr %91, i32 0, i32 11
  %93 = load i32, ptr %92, align 4, !tbaa !24
  %94 = or i32 %93, 2
  store i32 %94, ptr %92, align 4, !tbaa !24
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i32 1
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"WINDOW", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !6, i64 52, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68}
!13 = !{!14, !10, i64 8}
!14 = !{!"LINE", !10, i64 0, !10, i64 8, !15, i64 16, !15, i64 18, !7, i64 20}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !10, i64 40}
!17 = !{!"BUFFER", !10, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !6, i64 52, !7, i64 56, !7, i64 184}
!18 = !{!14, !15, i64 18}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}
!23 = !{!12, !6, i64 32}
!24 = !{!12, !6, i64 68}


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

@curwp = external local_unnamed_addr global ptr, align 8
@curbp = external local_unnamed_addr global ptr, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @backparag(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @curwp, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 24
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %8 = load ptr, ptr @curbp, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 40
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %.not28 = icmp eq ptr %7, %10
  br i1 %.not28, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.critedge27
  %.030 = phi ptr [ %.01629, %.critedge27 ], [ %7, %2 ]
  %.01629 = phi ptr [ %17, %.critedge27 ], [ %7, %2 ]
  %11 = getelementptr inbounds i8, ptr %.01629, i64 18
  %12 = load i16, ptr %11, align 2, !tbaa !17
  %.not20 = icmp eq i16 %12, 0
  br i1 %.not20, label %.critedge27, label %13

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds i8, ptr %.01629, i64 20
  %15 = load i8, ptr %14, align 4, !tbaa !18
  switch i8 %15, label %.critedge [
    i8 92, label %.critedge27
    i8 46, label %.critedge27
  ]

.critedge27:                                      ; preds = %13, %13, %.lr.ph
  %16 = getelementptr inbounds i8, ptr %.01629, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %.not = icmp eq ptr %17, %10
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !19

.critedge:                                        ; preds = %.critedge27, %13, %2
  %.016.lcssa = phi ptr [ %7, %2 ], [ %.01629, %13 ], [ %17, %.critedge27 ]
  %.0.lcssa = phi ptr [ %7, %2 ], [ %.030, %13 ], [ %.01629, %.critedge27 ]
  %.not2237 = icmp eq ptr %.016.lcssa, %10
  br i1 %.not2237, label %.critedge2, label %.lr.ph40.preheader

.lr.ph40.preheader:                               ; preds = %.critedge
  %18 = getelementptr inbounds i8, ptr %.016.lcssa, i64 18
  %19 = load i16, ptr %18, align 2, !tbaa !17
  %.not2348 = icmp eq i16 %19, 0
  br i1 %.not2348, label %.critedge2, label %.lr.ph51

.lr.ph40:                                         ; preds = %24
  %20 = getelementptr inbounds i8, ptr %26, i64 18
  %21 = load i16, ptr %20, align 2, !tbaa !17
  %.not23 = icmp eq i16 %21, 0
  br i1 %.not23, label %.critedge2, label %.lr.ph51, !llvm.loop !21

.lr.ph51:                                         ; preds = %.lr.ph40.preheader, %.lr.ph40
  %.1173850 = phi ptr [ %26, %.lr.ph40 ], [ %.016.lcssa, %.lr.ph40.preheader ]
  %.13949 = phi ptr [ %.1173850, %.lr.ph40 ], [ %.0.lcssa, %.lr.ph40.preheader ]
  %22 = getelementptr inbounds i8, ptr %.1173850, i64 20
  %23 = load i8, ptr %22, align 4, !tbaa !18
  switch i8 %23, label %24 [
    i8 46, label %.critedge2
    i8 92, label %.critedge2
  ]

24:                                               ; preds = %.lr.ph51
  %25 = getelementptr inbounds i8, ptr %.1173850, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %.not22 = icmp eq ptr %26, %10
  br i1 %.not22, label %.critedge2, label %.lr.ph40, !llvm.loop !21

.critedge2:                                       ; preds = %.lr.ph51, %.lr.ph51, %24, %.lr.ph40, %.lr.ph40.preheader, %.critedge
  %.1.lcssa = phi ptr [ %.0.lcssa, %.critedge ], [ %.0.lcssa, %.lr.ph40.preheader ], [ %.1173850, %.lr.ph40 ], [ %.1173850, %24 ], [ %.13949, %.lr.ph51 ], [ %.13949, %.lr.ph51 ]
  store ptr %.1.lcssa, ptr %4, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %3, i64 32
  store i32 0, ptr %27, align 8, !tbaa !22
  %28 = getelementptr inbounds i8, ptr %3, i64 68
  %29 = load i32, ptr %28, align 4, !tbaa !23
  %30 = or i32 %29, 2
  store i32 %30, ptr %28, align 4, !tbaa !23
  ret i32 1
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"WINDOW", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 8}
!13 = !{!"LINE", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 18, !7, i64 20}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !6, i64 40}
!16 = !{!"BUFFER", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !11, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !7, i64 56, !7, i64 184}
!17 = !{!13, !14, i64 18}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}
!22 = !{!10, !11, i64 32}
!23 = !{!10, !11, i64 68}


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