; 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: nounwind uwtable
declare dso_local i32 @inword(i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @backword(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %8, label %13

8:                                                ; preds = %2
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = sub nsw i32 0, %10
  %12 = call i32 @forwword(i32 noundef %9, i32 noundef %11)
  store i32 %12, ptr %3, align 4
  br label %43

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

16:                                               ; preds = %13
  store i32 0, ptr %3, align 4
  br label %43

17:                                               ; preds = %13
  br label %18

18:                                               ; preds = %40, %17
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = add nsw i32 %19, -1
  store i32 %20, ptr %5, align 4, !tbaa !5
  %21 = icmp ne i32 %19, 0
  br i1 %21, label %22, label %41

22:                                               ; preds = %18
  br label %23

23:                                               ; preds = %30, %22
  %24 = call i32 @inword(i32 noundef 0)
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %31

26:                                               ; preds = %23
  %27 = call i32 @backchar(i32 noundef 0, i32 noundef 1)
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  store i32 0, ptr %3, align 4
  br label %43

30:                                               ; preds = %26
  br label %23, !llvm.loop !9

31:                                               ; preds = %23
  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 %40

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
  br label %43

39:                                               ; preds = %35
  br label %32, !llvm.loop !11

40:                                               ; preds = %32
  br label %18, !llvm.loop !12

41:                                               ; preds = %18
  %42 = call i32 @forwchar(i32 noundef 0, i32 noundef 1)
  store i32 %42, ptr %3, align 4
  br label %43

43:                                               ; preds = %41, %38, %29, %16, %8
  %44 = load i32, ptr %3, align 4
  ret i32 %44
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @forwword(i32 noundef, i32 noundef) #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" }
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" }

!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

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

4:                                                ; preds = %2
  %5 = sub nsw i32 0, %1
  %6 = tail call i32 @forwword(i32 noundef %0, i32 noundef %5)
  br label %.loopexit8

7:                                                ; preds = %2
  %8 = tail call i32 @backchar(i32 noundef 0, i32 noundef 1) #2
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %.loopexit8, label %.preheader11

.preheader11:                                     ; preds = %7
  %.not12 = icmp eq i32 %1, 0
  br i1 %.not12, label %._crit_edge, label %.preheader9

.loopexit:                                        ; preds = %.preheader
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %._crit_edge, label %.preheader9, !llvm.loop !5

.preheader9:                                      ; preds = %.preheader11, %.loopexit
  %.in = phi i32 [ %10, %.loopexit ], [ %1, %.preheader11 ]
  %10 = add nsw i32 %.in, -1
  br label %11

11:                                               ; preds = %.preheader9, %14
  %12 = tail call i32 @inword(i32 noundef 0)
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %.preheader

14:                                               ; preds = %11
  %15 = tail call i32 @backchar(i32 noundef 0, i32 noundef 1) #2
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %.loopexit8, label %11, !llvm.loop !7

.preheader:                                       ; preds = %11, %18
  %17 = tail call i32 @inword(i32 noundef 0)
  %.not7 = icmp eq i32 %17, 0
  br i1 %.not7, label %.loopexit, label %18

18:                                               ; preds = %.preheader
  %19 = tail call i32 @backchar(i32 noundef 0, i32 noundef 1) #2
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %.loopexit8, label %.preheader, !llvm.loop !8

._crit_edge:                                      ; preds = %.loopexit, %.preheader11
  %21 = tail call i32 @forwchar(i32 noundef 0, i32 noundef 1) #2
  br label %.loopexit8

.loopexit8:                                       ; preds = %14, %18, %7, %._crit_edge, %4
  %.05 = phi i32 [ %6, %4 ], [ %21, %._crit_edge ], [ 0, %7 ], [ 0, %18 ], [ 0, %14 ]
  ret i32 %.05
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @forwword(i32 noundef, i32 noundef) local_unnamed_addr #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" }
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: GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass