; 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] }

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

; 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 void @putwrd(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @leadbl(ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @center(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @getwrd(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @text(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca [200000 x i8], align 16
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 200000, ptr %4) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = load i8, ptr %5, align 1, !tbaa !9
  %7 = sext i8 %6 to i32
  %8 = icmp eq i32 %7, 32
  br i1 %8, label %19, label %9

9:                                                ; preds = %1
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = sext i8 %11 to i32
  %13 = icmp eq i32 %12, 10
  br i1 %13, label %19, label %14

14:                                               ; preds = %9
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = sext i8 %16 to i32
  %18 = icmp eq i32 %17, 13
  br i1 %18, label %19, label %21

19:                                               ; preds = %14, %9, %1
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  call void @leadbl(ptr noundef %20)
  br label %21

21:                                               ; preds = %19, %14
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds [200000 x i8], ptr %4, i64 0, i64 0
  call void (ptr, ptr, ...) @expesc(ptr noundef %22, ptr noundef %23)
  %24 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 6), align 4, !tbaa !10
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %26, label %31

26:                                               ; preds = %21
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds [200000 x i8], ptr %4, i64 0, i64 0
  call void @underl(ptr noundef %27, ptr noundef %28, i32 noundef 200000)
  %29 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 6), align 4, !tbaa !10
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 6), align 4, !tbaa !10
  br label %31

31:                                               ; preds = %26, %21
  %32 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 7), align 4, !tbaa !13
  %33 = icmp sgt i32 %32, 0
  br i1 %33, label %34, label %39

34:                                               ; preds = %31
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds [200000 x i8], ptr %4, i64 0, i64 0
  call void @underl(ptr noundef %35, ptr noundef %36, i32 noundef 200000)
  %37 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 7), align 4, !tbaa !13
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 7), align 4, !tbaa !13
  br label %39

39:                                               ; preds = %34, %31
  %40 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 9), align 4, !tbaa !14
  %41 = icmp sgt i32 %40, 0
  br i1 %41, label %42, label %47

42:                                               ; preds = %39
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds [200000 x i8], ptr %4, i64 0, i64 0
  call void @bold(ptr noundef %43, ptr noundef %44, i32 noundef 200000)
  %45 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 9), align 4, !tbaa !14
  %46 = add nsw i32 %45, -1
  store i32 %46, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 9), align 4, !tbaa !14
  br label %47

47:                                               ; preds = %42, %39
  %48 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 5), align 4, !tbaa !15
  %49 = icmp sgt i32 %48, 0
  br i1 %49, label %50, label %55

50:                                               ; preds = %47
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  call void @center(ptr noundef %51)
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  call void @put(ptr noundef %52)
  %53 = load i32, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 5), align 4, !tbaa !15
  %54 = add nsw i32 %53, -1
  store i32 %54, ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 5), align 4, !tbaa !15
  br label %87

55:                                               ; preds = %47
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = load i8, ptr %56, align 1, !tbaa !9
  %58 = sext i8 %57 to i32
  %59 = icmp eq i32 %58, 13
  br i1 %59, label %65, label %60

60:                                               ; preds = %55
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = load i8, ptr %61, align 1, !tbaa !9
  %63 = sext i8 %62 to i32
  %64 = icmp eq i32 %63, 10
  br i1 %64, label %65, label %67

65:                                               ; preds = %60, %55
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  call void @put(ptr noundef %66)
  br label %86

67:                                               ; preds = %60
  %68 = load i32, ptr @dc, align 4, !tbaa !16
  %69 = icmp eq i32 %68, 0
  br i1 %69, label %70, label %72

70:                                               ; preds = %67
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  call void @put(ptr noundef %71)
  br label %85

72:                                               ; preds = %67
  br label %73

73:                                               ; preds = %78, %72
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds [200000 x i8], ptr %4, i64 0, i64 0
  %76 = call i32 @getwrd(ptr noundef %74, ptr noundef %75)
  store i32 %76, ptr %3, align 4, !tbaa !17
  %77 = icmp sgt i32 %76, 0
  br i1 %77, label %78, label %84

78:                                               ; preds = %73
  %79 = getelementptr inbounds [200000 x i8], ptr %4, i64 0, i64 0
  call void @putwrd(ptr noundef %79)
  %80 = load i32, ptr %3, align 4, !tbaa !17
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = sext i32 %80 to i64
  %83 = getelementptr inbounds i8, ptr %81, i64 %82
  store ptr %83, ptr %2, align 8, !tbaa !5
  br label %73, !llvm.loop !18

84:                                               ; preds = %73
  br label %85

85:                                               ; preds = %84, %70
  br label %86

86:                                               ; preds = %85, %65
  br label %87

87:                                               ; preds = %86, %50
  call void @llvm.lifetime.end.p0(i64 200000, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

declare void @expesc(...) #2

; Function Attrs: nounwind uwtable
declare dso_local void @put(ptr noundef) #1

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 24}
!11 = !{!"docctl", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !7, i64 48, !7, i64 49, !12, i64 52, !12, i64 56, !12, i64 60, !7, i64 64}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !12, i64 28}
!14 = !{!11, !12, i64 36}
!15 = !{!11, !12, i64 20}
!16 = !{!11, !12, i64 0}
!17 = !{!12, !12, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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] }

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

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

; Function Attrs: mustprogress 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 void @putwrd(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @leadbl(ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @center(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @getwrd(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @text(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca [200000 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 200000, ptr nonnull %2) #3
  %3 = load i8, ptr %0, align 1, !tbaa !5
  switch i8 %3, label %5 [
    i8 32, label %4
    i8 10, label %4
    i8 13, label %4
  ]

4:                                                ; preds = %1, %1, %1
  tail call void @leadbl(ptr noundef nonnull %0)
  br label %5

5:                                                ; preds = %1, %4
  call void (ptr, ptr, ...) @expesc(ptr noundef nonnull %0, ptr noundef nonnull %2) #3
  %6 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 24), align 4, !tbaa !8
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %8, label %11

8:                                                ; preds = %5
  call void @underl(ptr noundef nonnull %0, ptr noundef nonnull %2, i32 noundef 200000)
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 24), align 4, !tbaa !8
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr getelementptr inbounds (i8, ptr @dc, i64 24), align 4, !tbaa !8
  br label %11

11:                                               ; preds = %8, %5
  %12 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 28), align 4, !tbaa !11
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %17

14:                                               ; preds = %11
  call void @underl(ptr noundef nonnull %0, ptr noundef nonnull %2, i32 noundef 200000)
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 28), align 4, !tbaa !11
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr getelementptr inbounds (i8, ptr @dc, i64 28), align 4, !tbaa !11
  br label %17

17:                                               ; preds = %14, %11
  %18 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 36), align 4, !tbaa !12
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  call void @bold(ptr noundef nonnull %0, ptr noundef nonnull %2, i32 noundef 200000)
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 36), align 4, !tbaa !12
  %22 = add nsw i32 %21, -1
  store i32 %22, ptr getelementptr inbounds (i8, ptr @dc, i64 36), align 4, !tbaa !12
  br label %23

23:                                               ; preds = %20, %17
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 20), align 4, !tbaa !13
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %23
  call void @center(ptr noundef nonnull %0)
  call void @put(ptr noundef nonnull %0)
  %27 = load i32, ptr getelementptr inbounds (i8, ptr @dc, i64 20), align 4, !tbaa !13
  %28 = add nsw i32 %27, -1
  store i32 %28, ptr getelementptr inbounds (i8, ptr @dc, i64 20), align 4, !tbaa !13
  br label %.loopexit

29:                                               ; preds = %23
  %30 = load i8, ptr %0, align 1, !tbaa !5
  switch i8 %30, label %32 [
    i8 13, label %31
    i8 10, label %31
  ]

31:                                               ; preds = %29, %29
  call void @put(ptr noundef nonnull %0)
  br label %.loopexit

32:                                               ; preds = %29
  %33 = load i32, ptr @dc, align 4, !tbaa !14
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %37, label %.preheader

.preheader:                                       ; preds = %32
  %35 = call i32 @getwrd(ptr noundef nonnull %0, ptr noundef nonnull %2)
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %.lr.ph, label %.loopexit

37:                                               ; preds = %32
  call void @put(ptr noundef nonnull %0)
  br label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %38 = phi i32 [ %41, %.lr.ph ], [ %35, %.preheader ]
  %.019 = phi ptr [ %40, %.lr.ph ], [ %0, %.preheader ]
  call void @putwrd(ptr noundef nonnull %2)
  %39 = zext nneg i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %.019, i64 %39
  %41 = call i32 @getwrd(ptr noundef nonnull %40, ptr noundef nonnull %2)
  %42 = icmp sgt i32 %41, 0
  br i1 %42, label %.lr.ph, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph, %.preheader, %31, %37, %26
  call void @llvm.lifetime.end.p0(i64 200000, ptr nonnull %2) #3
  ret void
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @put(ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 24}
!9 = !{!"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, !6, i64 48, !6, i64 49, !10, i64 52, !10, i64 56, !10, i64 60, !6, i64 64}
!10 = !{!"int", !6, i64 0}
!11 = !{!9, !10, i64 28}
!12 = !{!9, !10, i64 36}
!13 = !{!9, !10, i64 20}
!14 = !{!9, !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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