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

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

@expesc.font = external hidden global [2 x i32], align 4
@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
define dso_local void @expesc(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = 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) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %9, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %10, ptr %6, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %107, %2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %108

16:                                               ; preds = %11
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = sext i8 %18 to i32
  switch i32 %19, label %86 [
    i32 92, label %20
  ]

20:                                               ; preds = %16
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 1
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = sext i8 %23 to i32
  switch i32 %24, label %84 [
    i32 92, label %25
    i32 110, label %28
    i32 78, label %28
    i32 102, label %66
    i32 70, label %66
  ]

25:                                               ; preds = %20
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i32 1
  store ptr %27, ptr %5, align 8, !tbaa !5
  br label %87

28:                                               ; preds = %20, %20
  %29 = call ptr @__ctype_b_loc() #6
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 2
  %33 = load i8, ptr %32, align 1, !tbaa !9
  %34 = sext i8 %33 to i32
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i16, ptr %30, i64 %35
  %37 = load i16, ptr %36, align 2, !tbaa !10
  %38 = zext i16 %37 to i32
  %39 = and i32 %38, 1024
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %65

41:                                               ; preds = %28
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i64 2
  store ptr %43, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %44 = call ptr @__ctype_tolower_loc() #6
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i32 1
  store ptr %47, ptr %5, align 8, !tbaa !5
  %48 = load i8, ptr %46, align 1, !tbaa !9
  %49 = sext i8 %48 to i32
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i32, ptr %45, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !12
  store i32 %52, ptr %7, align 4, !tbaa !12
  %53 = load i32, ptr %7, align 4, !tbaa !12
  store i32 %53, ptr %8, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  %54 = load i32, ptr %8, align 4, !tbaa !12
  %55 = sub nsw i32 %54, 97
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [26 x i32], ptr getelementptr inbounds (%struct.docctl, ptr @dc, i32 0, i32 17), i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !12
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = call i32 (i32, ptr, i32, ...) @itoda(i32 noundef %58, ptr noundef %59, i32 noundef 6)
  %61 = sub nsw i32 %60, 1
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = sext i32 %61 to i64
  %64 = getelementptr inbounds i8, ptr %62, i64 %63
  store ptr %64, ptr %6, align 8, !tbaa !5
  br label %85

65:                                               ; preds = %28
  br label %87

66:                                               ; preds = %20, %20
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i64 2
  %69 = load i8, ptr %68, align 1, !tbaa !9
  %70 = sext i8 %69 to i32
  switch i32 %70, label %82 [
    i32 66, label %71
    i32 73, label %73
    i32 82, label %75
    i32 80, label %77
  ]

71:                                               ; preds = %66
  %72 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @expesc.font, i64 0, i64 1), align 4, !tbaa !12
  store i32 %72, ptr @expesc.font, align 4, !tbaa !12
  store i32 1, ptr getelementptr inbounds ([2 x i32], ptr @expesc.font, i64 0, i64 1), align 4, !tbaa !12
  br label %79

73:                                               ; preds = %66
  %74 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @expesc.font, i64 0, i64 1), align 4, !tbaa !12
  store i32 %74, ptr @expesc.font, align 4, !tbaa !12
  store i32 2, ptr getelementptr inbounds ([2 x i32], ptr @expesc.font, i64 0, i64 1), align 4, !tbaa !12
  br label %79

75:                                               ; preds = %66
  %76 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @expesc.font, i64 0, i64 1), align 4, !tbaa !12
  store i32 %76, ptr @expesc.font, align 4, !tbaa !12
  store i32 0, ptr getelementptr inbounds ([2 x i32], ptr @expesc.font, i64 0, i64 1), align 4, !tbaa !12
  br label %79

77:                                               ; preds = %66
  %78 = load i32, ptr @expesc.font, align 4, !tbaa !12
  store i32 %78, ptr getelementptr inbounds ([2 x i32], ptr @expesc.font, i64 0, i64 1), align 4, !tbaa !12
  br label %79

79:                                               ; preds = %77, %75, %73, %71
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i64 3
  store ptr %81, ptr %5, align 8, !tbaa !5
  br label %83

82:                                               ; preds = %66
  br label %87

83:                                               ; preds = %79
  br label %85

84:                                               ; preds = %20
  br label %87

85:                                               ; preds = %83, %41
  br label %107

86:                                               ; preds = %16
  br label %87

87:                                               ; preds = %86, %84, %82, %65, %25
  %88 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @expesc.font, i64 0, i64 1), align 4, !tbaa !12
  switch i32 %88, label %106 [
    i32 1, label %89
    i32 2, label %94
    i32 0, label %100
  ]

89:                                               ; preds = %87
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = load i8, ptr %90, align 1, !tbaa !9
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds i8, ptr %92, i32 1
  store ptr %93, ptr %6, align 8, !tbaa !5
  store i8 %91, ptr %92, align 1, !tbaa !9
  br label %97

94:                                               ; preds = %87
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = getelementptr inbounds i8, ptr %95, i32 1
  store ptr %96, ptr %6, align 8, !tbaa !5
  store i8 95, ptr %95, align 1, !tbaa !9
  br label %97

97:                                               ; preds = %94, %89
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = getelementptr inbounds i8, ptr %98, i32 1
  store ptr %99, ptr %6, align 8, !tbaa !5
  store i8 8, ptr %98, align 1, !tbaa !9
  br label %100

100:                                              ; preds = %97, %87
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = getelementptr inbounds i8, ptr %101, i32 1
  store ptr %102, ptr %5, align 8, !tbaa !5
  %103 = load i8, ptr %101, align 1, !tbaa !9
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = getelementptr inbounds i8, ptr %104, i32 1
  store ptr %105, ptr %6, align 8, !tbaa !5
  store i8 %103, ptr %104, align 1, !tbaa !9
  br label %106

106:                                              ; preds = %100, %87
  br label %107

107:                                              ; preds = %106, %85
  br label %11, !llvm.loop !14

108:                                              ; preds = %11
  %109 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 0, ptr %109, align 1, !tbaa !9
  %110 = load ptr, ptr %3, align 8, !tbaa !5
  %111 = load ptr, ptr %4, align 8, !tbaa !5
  %112 = call ptr @strcpy(ptr noundef %110, ptr noundef %111) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() #2

declare i32 @itoda(...) #3

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_tolower_loc() #2

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #4

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 willreturn memory(none) "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 "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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] }

@expesc.font = external hidden local_unnamed_addr global [2 x i32], align 4
@dc = external local_unnamed_addr global %struct.docctl, align 4

; Function Attrs: nounwind uwtable
define dso_local void @expesc(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  br label %.outer

.outer:                                           ; preds = %.outer.backedge, %2
  %.023.ph = phi ptr [ %1, %2 ], [ %.023.ph.be, %.outer.backedge ]
  %.0.ph = phi ptr [ %0, %2 ], [ %.0.ph.be, %.outer.backedge ]
  %expesc.font.promoted = load i32, ptr @expesc.font, align 4, !tbaa !5
  %.promoted = load i32, ptr getelementptr inbounds (i8, ptr @expesc.font, i64 4), align 4, !tbaa !5
  br label %3

3:                                                ; preds = %.backedge, %.outer
  %.sink46 = phi i32 [ %.promoted, %.outer ], [ %.sink45, %.backedge ]
  %4 = phi i32 [ %expesc.font.promoted, %.outer ], [ %43, %.backedge ]
  %.0 = phi ptr [ %.0.ph, %.outer ], [ %.0.be, %.backedge ]
  %5 = load i8, ptr %.0, align 1, !tbaa !9
  switch i8 %5, label %42 [
    i8 0, label %50
    i8 92, label %6
  ]

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %.0, i64 1
  %8 = load i8, ptr %7, align 1, !tbaa !9
  switch i8 %8, label %42 [
    i8 92, label %9
    i8 110, label %10
    i8 78, label %10
    i8 102, label %33
    i8 70, label %33
  ]

9:                                                ; preds = %6
  br label %42

10:                                               ; preds = %6, %6
  %11 = tail call ptr @__ctype_b_loc() #4
  %12 = load ptr, ptr %11, align 8, !tbaa !10
  %13 = getelementptr inbounds i8, ptr %.0, i64 2
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %15 = sext i8 %14 to i64
  %16 = getelementptr inbounds i16, ptr %12, i64 %15
  %17 = load i16, ptr %16, align 2, !tbaa !12
  %18 = and i16 %17, 1024
  %.not27 = icmp eq i16 %18, 0
  br i1 %.not27, label %42, label %19

19:                                               ; preds = %10
  %20 = tail call ptr @__ctype_tolower_loc() #4
  %21 = load ptr, ptr %20, align 8, !tbaa !10
  %22 = getelementptr inbounds i8, ptr %.0, i64 3
  %23 = getelementptr inbounds i32, ptr %21, i64 %15
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add nsw i32 %24, -97
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [26 x i32], ptr getelementptr inbounds (i8, ptr @dc, i64 64), i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = tail call i32 (i32, ptr, i32, ...) @itoda(i32 noundef %28, ptr noundef %.023.ph, i32 noundef 6) #5
  %30 = add nsw i32 %29, -1
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i8, ptr %.023.ph, i64 %31
  br label %.outer.backedge

33:                                               ; preds = %6, %6
  %34 = getelementptr inbounds i8, ptr %.0, i64 2
  %35 = load i8, ptr %34, align 1, !tbaa !9
  switch i8 %35, label %42 [
    i8 66, label %36
    i8 73, label %37
    i8 82, label %38
    i8 80, label %39
  ]

36:                                               ; preds = %33
  store i32 %.sink46, ptr @expesc.font, align 4, !tbaa !5
  br label %39

37:                                               ; preds = %33
  store i32 %.sink46, ptr @expesc.font, align 4, !tbaa !5
  br label %39

38:                                               ; preds = %33
  store i32 %.sink46, ptr @expesc.font, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %33, %38, %37, %36
  %40 = phi i32 [ %.sink46, %38 ], [ %.sink46, %37 ], [ %.sink46, %36 ], [ %4, %33 ]
  %.sink = phi i32 [ 0, %38 ], [ 2, %37 ], [ 1, %36 ], [ %4, %33 ]
  store i32 %.sink, ptr getelementptr inbounds (i8, ptr @expesc.font, i64 4), align 4, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %.0, i64 3
  br label %.backedge

42:                                               ; preds = %3, %6, %33, %10, %9
  %.1 = phi ptr [ %.0, %6 ], [ %.0, %33 ], [ %.0, %10 ], [ %7, %9 ], [ %.0, %3 ]
  switch i32 %.sink46, label %.backedge [
    i32 1, label %44
    i32 2, label %.loopexit
    i32 0, label %.loopexit28
  ]

.backedge:                                        ; preds = %42, %39
  %.sink45 = phi i32 [ %.sink46, %42 ], [ %.sink, %39 ]
  %43 = phi i32 [ %4, %42 ], [ %40, %39 ]
  %.0.be = phi ptr [ %.1, %42 ], [ %41, %39 ]
  br label %3, !llvm.loop !14

44:                                               ; preds = %42
  %45 = load i8, ptr %.1, align 1, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %42, %44
  %storemerge = phi i8 [ %45, %44 ], [ 95, %42 ]
  %.124 = getelementptr inbounds i8, ptr %.023.ph, i64 1
  store i8 %storemerge, ptr %.023.ph, align 1, !tbaa !9
  %46 = getelementptr inbounds i8, ptr %.023.ph, i64 2
  store i8 8, ptr %.124, align 1, !tbaa !9
  br label %.loopexit28

.loopexit28:                                      ; preds = %42, %.loopexit
  %.225 = phi ptr [ %46, %.loopexit ], [ %.023.ph, %42 ]
  %47 = getelementptr inbounds i8, ptr %.1, i64 1
  %48 = load i8, ptr %.1, align 1, !tbaa !9
  %49 = getelementptr inbounds i8, ptr %.225, i64 1
  store i8 %48, ptr %.225, align 1, !tbaa !9
  br label %.outer.backedge

.outer.backedge:                                  ; preds = %.loopexit28, %19
  %.023.ph.be = phi ptr [ %32, %19 ], [ %49, %.loopexit28 ]
  %.0.ph.be = phi ptr [ %22, %19 ], [ %47, %.loopexit28 ]
  br label %.outer, !llvm.loop !14

50:                                               ; preds = %3
  store i8 0, ptr %.023.ph, align 1, !tbaa !9
  %51 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) %1) #5
  ret void
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() local_unnamed_addr #1

declare i32 @itoda(...) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_tolower_loc() local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 willreturn memory(none) }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass