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

; Function Attrs: nounwind uwtable
declare dso_local i32 @backword(i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @forwword(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 @backword(i32 noundef %9, i32 noundef %11)
  store i32 %12, ptr %3, align 4
  br label %38

13:                                               ; preds = %2
  br label %14

14:                                               ; preds = %36, %13
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr %5, align 4, !tbaa !5
  %17 = icmp ne i32 %15, 0
  br i1 %17, label %18, label %37

18:                                               ; preds = %14
  br label %19

19:                                               ; preds = %26, %18
  %20 = call i32 @inword(i32 noundef 0)
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %27

22:                                               ; preds = %19
  %23 = call i32 @forwchar(i32 noundef 0, i32 noundef 1)
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  store i32 0, ptr %3, align 4
  br label %38

26:                                               ; preds = %22
  br label %19, !llvm.loop !9

27:                                               ; preds = %19
  br label %28

28:                                               ; preds = %35, %27
  %29 = call i32 @inword(i32 noundef 0)
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %36

31:                                               ; preds = %28
  %32 = call i32 @forwchar(i32 noundef 0, i32 noundef 1)
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %31
  store i32 0, ptr %3, align 4
  br label %38

35:                                               ; preds = %31
  br label %28, !llvm.loop !11

36:                                               ; preds = %28
  br label %14, !llvm.loop !12

37:                                               ; preds = %14
  store i32 1, ptr %3, align 4
  br label %38

38:                                               ; preds = %37, %34, %25, %8
  %39 = load i32, ptr %3, align 4
  ret i32 %39
}

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 @forwchar(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @backword(i32 noundef, i32 noundef) local_unnamed_addr #0

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

.preheader11:                                     ; preds = %2
  %.not13 = icmp eq i32 %1, 0
  br i1 %.not13, label %.loopexit8, label %.preheader9

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

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

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

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

11:                                               ; preds = %8
  %12 = tail call i32 @forwchar(i32 noundef 0, i32 noundef 1) #2
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %.loopexit8, label %8, !llvm.loop !7

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

15:                                               ; preds = %.preheader
  %16 = tail call i32 @forwchar(i32 noundef 0, i32 noundef 1) #2
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %.loopexit8, label %.preheader, !llvm.loop !8

.loopexit8:                                       ; preds = %.loopexit, %11, %15, %.preheader11, %4
  %.05 = phi i32 [ %6, %4 ], [ 1, %.preheader11 ], [ 0, %15 ], [ 0, %11 ], [ 1, %.loopexit ]
  ret i32 %.05
}

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