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

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

@wheadp = 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 void @lchange(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %4 = load ptr, ptr @curbp, align 8, !tbaa !9
  %5 = getelementptr inbounds %struct.BUFFER, ptr %4, i32 0, i32 6
  %6 = load i32, ptr %5, align 8, !tbaa !11
  %7 = icmp ne i32 %6, 1
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i32 8, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %8, %1
  %10 = load ptr, ptr @curbp, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.BUFFER, ptr %10, i32 0, i32 7
  %12 = load i32, ptr %11, align 4, !tbaa !13
  %13 = and i32 %12, 2
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %22

15:                                               ; preds = %9
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = or i32 %16, 16
  store i32 %17, ptr %2, align 4, !tbaa !5
  %18 = load ptr, ptr @curbp, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.BUFFER, ptr %18, i32 0, i32 7
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = or i32 %20, 2
  store i32 %21, ptr %19, align 4, !tbaa !13
  br label %22

22:                                               ; preds = %15, %9
  %23 = load ptr, ptr @wheadp, align 8, !tbaa !9
  store ptr %23, ptr %3, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %39, %22
  %25 = load ptr, ptr %3, align 8, !tbaa !9
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %43

27:                                               ; preds = %24
  %28 = load ptr, ptr %3, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.WINDOW, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = load ptr, ptr @curbp, align 8, !tbaa !9
  %32 = icmp eq ptr %30, %31
  br i1 %32, label %33, label %39

33:                                               ; preds = %27
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = load ptr, ptr %3, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.WINDOW, ptr %35, i32 0, i32 11
  %37 = load i32, ptr %36, align 4, !tbaa !16
  %38 = or i32 %37, %34
  store i32 %38, ptr %36, align 4, !tbaa !16
  br label %39

39:                                               ; preds = %33, %27
  %40 = load ptr, ptr %3, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.WINDOW, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  store ptr %42, ptr %3, align 8, !tbaa !9
  br label %24, !llvm.loop !18

43:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

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, !6, i64 48}
!12 = !{!"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}
!13 = !{!12, !6, i64 52}
!14 = !{!15, !10, i64 8}
!15 = !{!"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}
!16 = !{!15, !6, i64 68}
!17 = !{!15, !10, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

@wheadp = 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 void @lchange(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @curbp, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 48
  %4 = load i32, ptr %3, align 8, !tbaa !9
  %.not = icmp eq i32 %4, 1
  %spec.select = select i1 %.not, i32 %0, i32 8
  %5 = getelementptr inbounds i8, ptr %2, i64 52
  %6 = load i32, ptr %5, align 4, !tbaa !12
  %7 = and i32 %6, 2
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %12

9:                                                ; preds = %1
  %10 = or i32 %spec.select, 16
  %11 = or disjoint i32 %6, 2
  store i32 %11, ptr %5, align 4, !tbaa !12
  br label %12

12:                                               ; preds = %9, %1
  %.1 = phi i32 [ %10, %9 ], [ %spec.select, %1 ]
  %.07 = load ptr, ptr @wheadp, align 8, !tbaa !5
  %.not68 = icmp eq ptr %.07, null
  br i1 %.not68, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %12, %20
  %.09 = phi ptr [ %.0, %20 ], [ %.07, %12 ]
  %13 = getelementptr inbounds i8, ptr %.09, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = icmp eq ptr %14, %2
  br i1 %15, label %16, label %20

16:                                               ; preds = %.lr.ph
  %17 = getelementptr inbounds i8, ptr %.09, i64 68
  %18 = load i32, ptr %17, align 4, !tbaa !15
  %19 = or i32 %18, %.1
  store i32 %19, ptr %17, align 4, !tbaa !15
  br label %20

20:                                               ; preds = %16, %.lr.ph
  %.0 = load ptr, ptr %.09, align 8, !tbaa !5
  %.not6 = icmp eq ptr %.0, null
  br i1 %.not6, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %20, %12
  ret void
}

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, !11, i64 48}
!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 = !{!10, !11, i64 52}
!13 = !{!14, !6, i64 8}
!14 = !{!"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}
!15 = !{!14, !11, i64 68}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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