; 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.BUFFER = type { ptr, ptr, i32, ptr, i32, ptr, i32, i32, [128 x i8], [128 x i8] }
%struct.LINE = type { ptr, ptr, i16, i16, [32768 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 @forwparag(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = 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
  %6 = load ptr, ptr @curwp, align 8, !tbaa !9
  %7 = getelementptr inbounds %struct.WINDOW, ptr %6, i32 0, i32 3
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  store ptr %8, ptr %5, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %39, %2
  %10 = load ptr, ptr %5, align 8, !tbaa !9
  %11 = load ptr, ptr @curbp, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.BUFFER, ptr %11, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = icmp ne ptr %10, %13
  br i1 %14, label %15, label %37

15:                                               ; preds = %9
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.LINE, ptr %16, i32 0, i32 3
  %18 = load i16, ptr %17, align 2, !tbaa !15
  %19 = sext i16 %18 to i32
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %35

21:                                               ; preds = %15
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.LINE, ptr %22, i32 0, i32 4
  %24 = getelementptr inbounds [32768 x i8], ptr %23, i64 0, i64 0
  %25 = load i8, ptr %24, align 4, !tbaa !18
  %26 = sext i8 %25 to i32
  %27 = icmp ne i32 %26, 46
  br i1 %27, label %28, label %35

28:                                               ; preds = %21
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.LINE, ptr %29, i32 0, i32 4
  %31 = getelementptr inbounds [32768 x i8], ptr %30, i64 0, i64 0
  %32 = load i8, ptr %31, align 4, !tbaa !18
  %33 = sext i8 %32 to i32
  %34 = icmp ne i32 %33, 92
  br label %35

35:                                               ; preds = %28, %21, %15
  %36 = phi i1 [ false, %21 ], [ false, %15 ], [ %34, %28 ]
  br label %37

37:                                               ; preds = %35, %9
  %38 = phi i1 [ false, %9 ], [ %36, %35 ]
  br i1 %38, label %39, label %43

39:                                               ; preds = %37
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.LINE, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !19
  store ptr %42, ptr %5, align 8, !tbaa !9
  br label %9, !llvm.loop !20

43:                                               ; preds = %37
  br label %44

44:                                               ; preds = %75, %43
  %45 = load ptr, ptr %5, align 8, !tbaa !9
  %46 = load ptr, ptr @curbp, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.BUFFER, ptr %46, i32 0, i32 5
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = icmp ne ptr %45, %48
  br i1 %49, label %50, label %73

50:                                               ; preds = %44
  %51 = load ptr, ptr %5, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.LINE, ptr %51, i32 0, i32 3
  %53 = load i16, ptr %52, align 2, !tbaa !15
  %54 = sext i16 %53 to i32
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %70

56:                                               ; preds = %50
  %57 = load ptr, ptr %5, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.LINE, ptr %57, i32 0, i32 4
  %59 = getelementptr inbounds [32768 x i8], ptr %58, i64 0, i64 0
  %60 = load i8, ptr %59, align 4, !tbaa !18
  %61 = sext i8 %60 to i32
  %62 = icmp ne i32 %61, 46
  br i1 %62, label %63, label %70

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

70:                                               ; preds = %63, %56, %50
  %71 = phi i1 [ false, %56 ], [ false, %50 ], [ %69, %63 ]
  %72 = xor i1 %71, true
  br label %73

73:                                               ; preds = %70, %44
  %74 = phi i1 [ false, %44 ], [ %72, %70 ]
  br i1 %74, label %75, label %79

75:                                               ; preds = %73
  %76 = load ptr, ptr %5, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.LINE, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !19
  store ptr %78, ptr %5, align 8, !tbaa !9
  br label %44, !llvm.loop !22

79:                                               ; preds = %73
  %80 = load ptr, ptr %5, align 8, !tbaa !9
  %81 = load ptr, ptr @curwp, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct.WINDOW, ptr %81, i32 0, i32 3
  store ptr %80, ptr %82, align 8, !tbaa !11
  %83 = load ptr, ptr @curwp, align 8, !tbaa !9
  %84 = getelementptr inbounds %struct.WINDOW, ptr %83, i32 0, i32 4
  store i32 0, ptr %84, align 8, !tbaa !23
  %85 = load ptr, ptr @curwp, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.WINDOW, ptr %85, i32 0, i32 11
  %87 = load i32, ptr %86, align 4, !tbaa !24
  %88 = or i32 %87, 2
  store i32 %88, ptr %86, align 4, !tbaa !24
  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 40}
!14 = !{!"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}
!15 = !{!16, !17, i64 18}
!16 = !{!"LINE", !10, i64 0, !10, i64 8, !17, i64 16, !17, i64 18, !7, i64 20}
!17 = !{!"short", !7, i64 0}
!18 = !{!7, !7, i64 0}
!19 = !{!16, !10, 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 @forwparag(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 @curbp, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %12, %2
  %.0.in = phi ptr [ %4, %2 ], [ %.0, %12 ]
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, %7
  br i1 %.not, label %.critedge2, label %9

9:                                                ; preds = %8
  %10 = getelementptr inbounds i8, ptr %.0, i64 18
  %11 = load i16, ptr %10, align 2, !tbaa !12
  %.not15 = icmp eq i16 %11, 0
  br i1 %.not15, label %.lr.ph.preheader, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %.0, i64 20
  %14 = load i8, ptr %13, align 4, !tbaa !15
  switch i8 %14, label %8 [
    i8 46, label %.lr.ph.preheader
    i8 92, label %.lr.ph.preheader
  ], !llvm.loop !16

.lr.ph.preheader:                                 ; preds = %12, %12, %9
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.critedge22
  %.124 = phi ptr [ %20, %.critedge22 ], [ %.0, %.lr.ph.preheader ]
  %15 = getelementptr inbounds i8, ptr %.124, i64 18
  %16 = load i16, ptr %15, align 2, !tbaa !12
  %.not19 = icmp eq i16 %16, 0
  br i1 %.not19, label %.critedge22, label %17

17:                                               ; preds = %.lr.ph
  %18 = getelementptr inbounds i8, ptr %.124, i64 20
  %19 = load i8, ptr %18, align 4, !tbaa !15
  switch i8 %19, label %.critedge2 [
    i8 92, label %.critedge22
    i8 46, label %.critedge22
  ]

.critedge22:                                      ; preds = %17, %17, %.lr.ph
  %20 = load ptr, ptr %.124, align 8, !tbaa !18
  %.not18 = icmp eq ptr %20, %7
  br i1 %.not18, label %.critedge2, label %.lr.ph, !llvm.loop !19

.critedge2:                                       ; preds = %8, %.critedge22, %17
  %.1.lcssa = phi ptr [ %.124, %17 ], [ %20, %.critedge22 ], [ %.0, %8 ]
  store ptr %.1.lcssa, ptr %4, align 8, !tbaa !20
  %21 = getelementptr inbounds i8, ptr %3, i64 32
  store i32 0, ptr %21, align 8, !tbaa !22
  %22 = getelementptr inbounds i8, ptr %3, i64 68
  %23 = load i32, ptr %22, align 4, !tbaa !23
  %24 = or i32 %23, 2
  store i32 %24, ptr %22, 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 40}
!10 = !{!"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}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !14, i64 18}
!13 = !{!"LINE", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 18, !7, i64 20}
!14 = !{!"short", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!13, !6, i64 0}
!19 = distinct !{!19, !17}
!20 = !{!21, !6, i64 24}
!21 = !{!"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}
!22 = !{!21, !11, i64 32}
!23 = !{!21, !11, i64 68}


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