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

%struct.docctl = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i32, i32, i32, [26 x i32] }
%struct.cout = type { i32, i32, i32, i32, [200000 x i8] }

@dc = external global %struct.docctl, align 4
@co = external global %struct.cout, align 4

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @width(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @putwrd(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = call i32 @width(ptr noundef %9)
  store i32 %10, ptr %3, align 4, !tbaa !9
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = call i64 @strlen(ptr noundef %11) #5
  %13 = load i32, ptr @co, align 4, !tbaa !11
  %14 = sext i32 %13 to i64
  %15 = add i64 %12, %14
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr %4, align 4, !tbaa !9
  %17 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 3), align 4, !tbaa !13
  %18 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 4), align 4, !tbaa !15
  %19 = sub nsw i32 %17, %18
  store i32 %19, ptr %5, align 4, !tbaa !9
  %20 = load i32, ptr @co, align 4, !tbaa !11
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %22, label %28

22:                                               ; preds = %1
  %23 = load i32, ptr getelementptr inbounds (%struct.cout, ptr @co, i32 0, i32 1), align 4, !tbaa !16
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = add nsw i32 %23, %24
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = icmp sgt i32 %25, %26
  br i1 %27, label %31, label %28

28:                                               ; preds = %22, %1
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = icmp sgt i32 %29, 200000
  br i1 %30, label %31, label %71

31:                                               ; preds = %28, %22
  %32 = load i32, ptr @co, align 4, !tbaa !11
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = sub nsw i32 %33, %32
  store i32 %34, ptr %4, align 4, !tbaa !9
  %35 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 8), align 4, !tbaa !17
  %36 = icmp eq i32 %35, 1
  br i1 %36, label %37, label %70

37:                                               ; preds = %31
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = load i32, ptr getelementptr inbounds (%struct.cout, ptr @co, i32 0, i32 1), align 4, !tbaa !16
  %40 = sub nsw i32 %38, %39
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %8, align 4, !tbaa !9
  %42 = load i32, ptr @co, align 4, !tbaa !11
  %43 = sub nsw i32 %42, 2
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [200000 x i8], ptr getelementptr inbounds (%struct.cout, ptr @co, i32 0, i32 4), i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !18
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %47, 32
  br i1 %48, label %49, label %54

49:                                               ; preds = %37
  %50 = load i32, ptr @co, align 4, !tbaa !11
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr @co, align 4, !tbaa !11
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %8, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %49, %37
  %55 = load i32, ptr @co, align 4, !tbaa !11
  %56 = sub nsw i32 %55, 1
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = load i32, ptr getelementptr inbounds (%struct.cout, ptr @co, i32 0, i32 2), align 4, !tbaa !19
  call void @spread(ptr noundef getelementptr inbounds (%struct.cout, ptr @co, i32 0, i32 4), i32 noundef %56, i32 noundef %57, i32 noundef %58)
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = icmp sgt i32 %59, 0
  br i1 %60, label %61, label %69

61:                                               ; preds = %54
  %62 = load i32, ptr getelementptr inbounds (%struct.cout, ptr @co, i32 0, i32 2), align 4, !tbaa !19
  %63 = icmp sgt i32 %62, 1
  br i1 %63, label %64, label %69

64:                                               ; preds = %61
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = sub nsw i32 %65, 1
  %67 = load i32, ptr @co, align 4, !tbaa !11
  %68 = add nsw i32 %67, %66
  store i32 %68, ptr @co, align 4, !tbaa !11
  br label %69

69:                                               ; preds = %64, %61, %54
  br label %70

70:                                               ; preds = %69, %31
  call void (...) @brek()
  br label %71

71:                                               ; preds = %70, %28
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %72, ptr %6, align 8, !tbaa !5
  %73 = load i32, ptr @co, align 4, !tbaa !11
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i8, ptr getelementptr inbounds (%struct.cout, ptr @co, i32 0, i32 4), i64 %74
  store ptr %75, ptr %7, align 8, !tbaa !5
  br label %76

76:                                               ; preds = %81, %71
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = load i8, ptr %77, align 1, !tbaa !18
  %79 = sext i8 %78 to i32
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %87

81:                                               ; preds = %76
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %82, i32 1
  store ptr %83, ptr %6, align 8, !tbaa !5
  %84 = load i8, ptr %82, align 1, !tbaa !18
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = getelementptr inbounds i8, ptr %85, i32 1
  store ptr %86, ptr %7, align 8, !tbaa !5
  store i8 %84, ptr %85, align 1, !tbaa !18
  br label %76, !llvm.loop !20

87:                                               ; preds = %76
  %88 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %88, ptr @co, align 4, !tbaa !11
  %89 = load i32, ptr @co, align 4, !tbaa !11
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr @co, align 4, !tbaa !11
  %91 = sext i32 %89 to i64
  %92 = getelementptr inbounds [200000 x i8], ptr getelementptr inbounds (%struct.cout, ptr @co, i32 0, i32 4), i64 0, i64 %91
  store i8 32, ptr %92, align 1, !tbaa !18
  %93 = load i32, ptr %3, align 4, !tbaa !9
  %94 = add nsw i32 %93, 1
  %95 = load i32, ptr getelementptr inbounds (%struct.cout, ptr @co, i32 0, i32 1), align 4, !tbaa !16
  %96 = add nsw i32 %95, %94
  store i32 %96, ptr getelementptr inbounds (%struct.cout, ptr @co, i32 0, i32 1), align 4, !tbaa !16
  %97 = load i32, ptr getelementptr inbounds (%struct.cout, ptr @co, i32 0, i32 2), align 4, !tbaa !19
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr getelementptr inbounds (%struct.cout, ptr @co, i32 0, i32 2), align 4, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret void
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

declare void @brek(...) #3

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind willreturn memory(read) "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 = { "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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!12, !10, i64 0}
!12 = !{!"cout", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !7, i64 16}
!13 = !{!14, !10, i64 12}
!14 = !{!"docctl", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !7, i64 48, !7, i64 49, !10, i64 52, !10, i64 56, !10, i64 60, !7, i64 64}
!15 = !{!14, !10, i64 16}
!16 = !{!12, !10, i64 4}
!17 = !{!14, !10, i64 32}
!18 = !{!7, !7, i64 0}
!19 = !{!12, !10, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"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"

%struct.docctl = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i8, i32, i32, i32, [26 x i32] }
%struct.cout = type { i32, i32, i32, i32, [200000 x i8] }

@dc = external local_unnamed_addr global %struct.docctl, align 4
@co = external global %struct.cout, align 4

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

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

; Function Attrs: nounwind uwtable
define dso_local void @putwrd(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @width(ptr noundef %0)
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %4 = load i32, ptr @co, align 4, !tbaa !5
  %5 = trunc i64 %3 to i32
  %6 = add i32 %4, %5
  %7 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 12), align 4, !tbaa !10
  %8 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 16), align 4, !tbaa !12
  %9 = sub nsw i32 %7, %8
  %10 = icmp sgt i32 %4, 0
  br i1 %10, label %11, label %16

11:                                               ; preds = %1
  %12 = load i32, ptr getelementptr inbounds (i8, ptr @co, i64 4), align 4, !tbaa !13
  %13 = add nsw i32 %12, %2
  %14 = icmp sgt i32 %13, %9
  %15 = icmp sgt i32 %6, 200000
  %or.cond = select i1 %14, i1 true, i1 %15
  br i1 %or.cond, label %17, label %44

16:                                               ; preds = %1
  %.old1 = icmp sgt i32 %6, 200000
  br i1 %.old1, label %17, label %44

17:                                               ; preds = %16, %11
  %18 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 32), align 4, !tbaa !14
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %20, label %43

20:                                               ; preds = %17
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @co, i64 4), align 4, !tbaa !13
  %22 = sub nsw i32 %9, %21
  %23 = add nsw i32 %22, 1
  %24 = add nsw i32 %4, -2
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [200000 x i8], ptr getelementptr inbounds (i8, ptr @co, i64 16), i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !15
  %28 = icmp eq i8 %27, 32
  br i1 %28, label %29, label %32

29:                                               ; preds = %20
  %30 = add nsw i32 %4, -1
  store i32 %30, ptr @co, align 4, !tbaa !5
  %31 = add nsw i32 %22, 2
  br label %32

32:                                               ; preds = %29, %20
  %33 = phi i32 [ %30, %29 ], [ %4, %20 ]
  %.0 = phi i32 [ %31, %29 ], [ %23, %20 ]
  %34 = add nsw i32 %33, -1
  %35 = load i32, ptr getelementptr inbounds (i8, ptr @co, i64 8), align 4, !tbaa !16
  tail call void @spread(ptr noundef nonnull getelementptr inbounds (i8, ptr @co, i64 16), i32 noundef %34, i32 noundef %.0, i32 noundef %35)
  %36 = icmp sgt i32 %.0, 0
  %37 = load i32, ptr getelementptr inbounds (i8, ptr @co, i64 8), align 4
  %38 = icmp sgt i32 %37, 1
  %or.cond4 = select i1 %36, i1 %38, i1 false
  br i1 %or.cond4, label %39, label %43

39:                                               ; preds = %32
  %40 = add nsw i32 %.0, -1
  %41 = load i32, ptr @co, align 4, !tbaa !5
  %42 = add nsw i32 %40, %41
  store i32 %42, ptr @co, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %32, %39, %17
  tail call void (...) @brek() #4
  %.pre = load i32, ptr @co, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %11, %43, %16
  %45 = phi i32 [ %.pre, %43 ], [ %4, %11 ], [ %4, %16 ]
  %.023 = phi i32 [ %5, %43 ], [ %6, %11 ], [ %6, %16 ]
  %46 = load i8, ptr %0, align 1, !tbaa !15
  %.not25 = icmp eq i8 %46, 0
  br i1 %.not25, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %44
  %47 = sext i32 %45 to i64
  %48 = getelementptr inbounds i8, ptr getelementptr inbounds (i8, ptr @co, i64 16), i64 %47
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %49 = phi i8 [ %52, %.lr.ph ], [ %46, %.lr.ph.preheader ]
  %.02127 = phi ptr [ %51, %.lr.ph ], [ %48, %.lr.ph.preheader ]
  %.02226 = phi ptr [ %50, %.lr.ph ], [ %0, %.lr.ph.preheader ]
  %50 = getelementptr inbounds i8, ptr %.02226, i64 1
  %51 = getelementptr inbounds i8, ptr %.02127, i64 1
  store i8 %49, ptr %.02127, align 1, !tbaa !15
  %52 = load i8, ptr %50, align 1, !tbaa !15
  %.not = icmp eq i8 %52, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph, %44
  %53 = add nsw i32 %.023, 1
  store i32 %53, ptr @co, align 4, !tbaa !5
  %54 = sext i32 %.023 to i64
  %55 = getelementptr inbounds [200000 x i8], ptr getelementptr inbounds (i8, ptr @co, i64 16), i64 0, i64 %54
  store i8 32, ptr %55, align 1, !tbaa !15
  %56 = add nsw i32 %2, 1
  %57 = load <2 x i32>, ptr getelementptr inbounds (i8, ptr @co, i64 4), align 4, !tbaa !19
  %58 = insertelement <2 x i32> <i32 poison, i32 1>, i32 %56, i64 0
  %59 = add nsw <2 x i32> %58, %57
  store <2 x i32> %59, ptr getelementptr inbounds (i8, ptr @co, i64 4), align 4, !tbaa !19
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

declare void @brek(...) local_unnamed_addr #2

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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }
attributes #4 = { 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, !7, i64 0}
!6 = !{!"cout", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !8, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 12}
!11 = !{!"docctl", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !8, i64 48, !8, i64 49, !7, i64 52, !7, i64 56, !7, i64 60, !8, i64 64}
!12 = !{!11, !7, i64 16}
!13 = !{!6, !7, i64 4}
!14 = !{!11, !7, i64 32}
!15 = !{!8, !8, i64 0}
!16 = !{!6, !7, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass