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

; 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 i32 @inword(i32 noundef) #1

declare i32 @backchar(i32 noundef, i32 noundef) #2

declare i32 @forwchar(i32 noundef, i32 noundef) #2

declare i32 @ldelete(i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @delbword(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

11:                                               ; preds = %2
  %12 = call i32 @backchar(i32 noundef 0, i32 noundef 1)
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

15:                                               ; preds = %11
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %42, %15
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = add nsw i32 %17, -1
  store i32 %18, ptr %5, align 4, !tbaa !5
  %19 = icmp ne i32 %17, 0
  br i1 %19, label %20, label %43

20:                                               ; preds = %16
  br label %21

21:                                               ; preds = %28, %20
  %22 = call i32 @inword(i32 noundef 0)
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %31

24:                                               ; preds = %21
  %25 = call i32 @backchar(i32 noundef 0, i32 noundef 1)
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

28:                                               ; preds = %24
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %6, align 4, !tbaa !5
  br label %21, !llvm.loop !9

31:                                               ; preds = %21
  br label %32

32:                                               ; preds = %39, %31
  %33 = call i32 @inword(i32 noundef 0)
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %42

35:                                               ; preds = %32
  %36 = call i32 @backchar(i32 noundef 0, i32 noundef 1)
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

39:                                               ; preds = %35
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %6, align 4, !tbaa !5
  br label %32, !llvm.loop !11

42:                                               ; preds = %32
  br label %16, !llvm.loop !12

43:                                               ; preds = %16
  %44 = call i32 @forwchar(i32 noundef 0, i32 noundef 1)
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %43
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

47:                                               ; preds = %43
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = call i32 @ldelete(i32 noundef %48, i32 noundef 1)
  store i32 %49, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %50

50:                                               ; preds = %47, %46, %38, %27, %14, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %51 = load i32, ptr %3, align 4
  ret i32 %51
}

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 = { "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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; 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 i32 @inword(i32 noundef) local_unnamed_addr #0

declare i32 @backchar(i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @forwchar(i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @ldelete(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @delbword(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp slt i32 %1, 0
  br i1 %3, label %.loopexit10, label %4

4:                                                ; preds = %2
  %5 = tail call i32 @backchar(i32 noundef 0, i32 noundef 1) #2
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %.loopexit10, label %.preheader13

.preheader13:                                     ; preds = %4
  %.not23 = icmp eq i32 %1, 0
  br i1 %.not23, label %._crit_edge, label %.preheader11

.loopexit:                                        ; preds = %19, %.preheader
  %.2.lcssa = phi i32 [ %.1.lcssa, %.preheader ], [ %20, %19 ]
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %._crit_edge, label %.preheader11, !llvm.loop !5

.preheader11:                                     ; preds = %.preheader13, %.loopexit
  %.in = phi i32 [ %7, %.loopexit ], [ %1, %.preheader13 ]
  %.024 = phi i32 [ %.2.lcssa, %.loopexit ], [ 0, %.preheader13 ]
  %7 = add nsw i32 %.in, -1
  %8 = tail call i32 @inword(i32 noundef 0)
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %13, %.preheader11
  %.1.lcssa = phi i32 [ %.024, %.preheader11 ], [ %14, %13 ]
  %10 = tail call i32 @inword(i32 noundef 0)
  %.not919 = icmp eq i32 %10, 0
  br i1 %.not919, label %.loopexit, label %.lr.ph21

.lr.ph:                                           ; preds = %.preheader11, %13
  %.118 = phi i32 [ %14, %13 ], [ %.024, %.preheader11 ]
  %11 = tail call i32 @backchar(i32 noundef 0, i32 noundef 1) #2
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %.loopexit10, label %13

13:                                               ; preds = %.lr.ph
  %14 = add nsw i32 %.118, 1
  %15 = tail call i32 @inword(i32 noundef 0)
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %.lr.ph, label %.preheader, !llvm.loop !7

.lr.ph21:                                         ; preds = %.preheader, %19
  %.220 = phi i32 [ %20, %19 ], [ %.1.lcssa, %.preheader ]
  %17 = tail call i32 @backchar(i32 noundef 0, i32 noundef 1) #2
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %.loopexit10, label %19

19:                                               ; preds = %.lr.ph21
  %20 = add nsw i32 %.220, 1
  %21 = tail call i32 @inword(i32 noundef 0)
  %.not9 = icmp eq i32 %21, 0
  br i1 %.not9, label %.loopexit, label %.lr.ph21, !llvm.loop !8

._crit_edge:                                      ; preds = %.loopexit, %.preheader13
  %.0.lcssa = phi i32 [ 0, %.preheader13 ], [ %.2.lcssa, %.loopexit ]
  %22 = tail call i32 @forwchar(i32 noundef 0, i32 noundef 1) #2
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %.loopexit10, label %24

24:                                               ; preds = %._crit_edge
  %25 = tail call i32 @ldelete(i32 noundef %.0.lcssa, i32 noundef 1) #2
  br label %.loopexit10

.loopexit10:                                      ; preds = %.lr.ph, %.lr.ph21, %._crit_edge, %4, %2, %24
  %.07 = phi i32 [ %25, %24 ], [ 0, %2 ], [ 0, %4 ], [ 0, %._crit_edge ], [ 0, %.lr.ph21 ], [ 0, %.lr.ph ]
  ret i32 %.07
}

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" }
attributes #1 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}


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