; LLVM IR from freakout42/macrocalc :: mc/nro (nrotxt)

; 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
define dso_local i32 @strkovr(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %7, ptr %5, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %46, %2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = load i8, ptr %9, align 1, !tbaa !11
  %11 = sext i8 %10 to i32
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %51

13:                                               ; preds = %8
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  store i8 32, ptr %14, align 1, !tbaa !11
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %16, ptr %17, align 1, !tbaa !11
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i32 1
  store ptr %19, ptr %3, align 8, !tbaa !5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load i8, ptr %20, align 1, !tbaa !11
  %22 = sext i8 %21 to i32
  %23 = icmp eq i32 %22, 8
  br i1 %23, label %24, label %46

24:                                               ; preds = %13
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = icmp sge i32 %27, 32
  br i1 %28, label %29, label %45

29:                                               ; preds = %24
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = sext i8 %31 to i32
  %33 = icmp sle i32 %32, 126
  br i1 %33, label %34, label %45

34:                                               ; preds = %29
  store i32 1, ptr %6, align 4, !tbaa !9
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  store i8 %36, ptr %37, align 1, !tbaa !11
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i32 1
  store ptr %39, ptr %3, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load i8, ptr %40, align 1, !tbaa !11
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %41, ptr %42, align 1, !tbaa !11
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i32 1
  store ptr %44, ptr %3, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %34, %29, %24
  br label %46

46:                                               ; preds = %45, %13
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i32 1
  store ptr %48, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i32 1
  store ptr %50, ptr %5, align 8, !tbaa !5
  br label %8, !llvm.loop !12

51:                                               ; preds = %8
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 0, ptr %52, align 1, !tbaa !11
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  store i8 0, ptr %53, align 1, !tbaa !11
  %54 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i32 %54
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @strkovr(ptr nocapture noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = load i8, ptr %0, align 1, !tbaa !5
  %.not29 = icmp eq i8 %3, 0
  br i1 %.not29, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %14
  %.033 = phi i32 [ %.1, %14 ], [ 0, %2 ]
  %.01932 = phi ptr [ %17, %14 ], [ %0, %2 ]
  %.02031 = phi ptr [ %16, %14 ], [ %1, %2 ]
  %.02130 = phi ptr [ %.122, %14 ], [ %0, %2 ]
  store i8 32, ptr %.02031, align 1, !tbaa !5
  %4 = load i8, ptr %.02130, align 1, !tbaa !5
  store i8 %4, ptr %.01932, align 1, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %.02130, i64 1
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = icmp ne i8 %6, 8
  %8 = add i8 %4, -127
  %9 = icmp ult i8 %8, -95
  %or.cond25 = select i1 %7, i1 true, i1 %9
  br i1 %or.cond25, label %14, label %10

10:                                               ; preds = %.lr.ph
  store i8 %4, ptr %.02031, align 1, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %.02130, i64 2
  %12 = load i8, ptr %11, align 1, !tbaa !5
  store i8 %12, ptr %.01932, align 1, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %.02130, i64 3
  %.pre = load i8, ptr %13, align 1, !tbaa !5
  br label %14

14:                                               ; preds = %10, %.lr.ph
  %15 = phi i8 [ %.pre, %10 ], [ %6, %.lr.ph ]
  %.122 = phi ptr [ %13, %10 ], [ %5, %.lr.ph ]
  %.1 = phi i32 [ 1, %10 ], [ %.033, %.lr.ph ]
  %16 = getelementptr inbounds i8, ptr %.02031, i64 1
  %17 = getelementptr inbounds i8, ptr %.01932, i64 1
  %.not = icmp eq i8 %15, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %14, %2
  %.020.lcssa = phi ptr [ %1, %2 ], [ %16, %14 ]
  %.019.lcssa = phi ptr [ %0, %2 ], [ %17, %14 ]
  %.0.lcssa = phi i32 [ 0, %2 ], [ %.1, %14 ]
  store i8 0, ptr %.019.lcssa, align 1, !tbaa !5
  store i8 0, ptr %.020.lcssa, align 1, !tbaa !5
  ret i32 %.0.lcssa
}

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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