; 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 void @expand(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca [200000 x i8], align 16
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = trunc i32 %1 to i8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %11, ptr %5, align 1, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 200000, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %12, ptr %8, align 8, !tbaa !5
  %13 = getelementptr inbounds [200000 x i8], ptr %7, i64 0, i64 0
  store ptr %13, ptr %9, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %45, %3
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = sext i8 %16 to i32
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %48

19:                                               ; preds = %14
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = load i8, ptr %5, align 1, !tbaa !9
  %24 = sext i8 %23 to i32
  %25 = icmp eq i32 %22, %24
  br i1 %25, label %26, label %40

26:                                               ; preds = %19
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %27, ptr %10, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %33, %26
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = sext i8 %30 to i32
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %39

33:                                               ; preds = %28
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i32 1
  store ptr %35, ptr %10, align 8, !tbaa !5
  %36 = load i8, ptr %34, align 1, !tbaa !9
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i32 1
  store ptr %38, ptr %9, align 8, !tbaa !5
  store i8 %36, ptr %37, align 1, !tbaa !9
  br label %28, !llvm.loop !10

39:                                               ; preds = %28
  br label %45

40:                                               ; preds = %19
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load i8, ptr %41, align 1, !tbaa !9
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i32 1
  store ptr %44, ptr %9, align 8, !tbaa !5
  store i8 %42, ptr %43, align 1, !tbaa !9
  br label %45

45:                                               ; preds = %40, %39
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i32 1
  store ptr %47, ptr %8, align 8, !tbaa !5
  br label %14, !llvm.loop !12

48:                                               ; preds = %14
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  store i8 0, ptr %49, align 1, !tbaa !9
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds [200000 x i8], ptr %7, i64 0, i64 0
  %52 = call ptr @strcpy(ptr noundef %50, ptr noundef %51) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 200000, ptr %7) #3
  ret void
}

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

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 "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 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; 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: 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: nofree nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @expand(ptr noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = alloca [200000 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 200000, ptr nonnull %4) #3
  %5 = load i8, ptr %0, align 1, !tbaa !5
  %.not19 = icmp eq i8 %5, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph22

.lr.ph22:                                         ; preds = %3
  %sext = shl i32 %1, 24
  %6 = ashr exact i32 %sext, 24
  br label %7

7:                                                ; preds = %.lr.ph22, %.loopexit
  %8 = phi i8 [ %5, %.lr.ph22 ], [ %19, %.loopexit ]
  %.01221 = phi ptr [ %4, %.lr.ph22 ], [ %.2, %.loopexit ]
  %.01320 = phi ptr [ %0, %.lr.ph22 ], [ %18, %.loopexit ]
  %9 = sext i8 %8 to i32
  %10 = icmp eq i32 %6, %9
  br i1 %10, label %.preheader, label %16

.preheader:                                       ; preds = %7
  %11 = load i8, ptr %2, align 1, !tbaa !5
  %.not1516 = icmp eq i8 %11, 0
  br i1 %.not1516, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %12 = phi i8 [ %15, %.lr.ph ], [ %11, %.preheader ]
  %.018 = phi ptr [ %13, %.lr.ph ], [ %2, %.preheader ]
  %.117 = phi ptr [ %14, %.lr.ph ], [ %.01221, %.preheader ]
  %13 = getelementptr inbounds i8, ptr %.018, i64 1
  %14 = getelementptr inbounds i8, ptr %.117, i64 1
  store i8 %12, ptr %.117, align 1, !tbaa !5
  %15 = load i8, ptr %13, align 1, !tbaa !5
  %.not15 = icmp eq i8 %15, 0
  br i1 %.not15, label %.loopexit, label %.lr.ph, !llvm.loop !8

16:                                               ; preds = %7
  %17 = getelementptr inbounds i8, ptr %.01221, i64 1
  store i8 %8, ptr %.01221, align 1, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.preheader, %16
  %.2 = phi ptr [ %17, %16 ], [ %.01221, %.preheader ], [ %14, %.lr.ph ]
  %18 = getelementptr inbounds i8, ptr %.01320, i64 1
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %.not = icmp eq i8 %19, 0
  br i1 %.not, label %._crit_edge, label %7, !llvm.loop !10

._crit_edge:                                      ; preds = %.loopexit, %3
  %.012.lcssa = phi ptr [ %4, %3 ], [ %.2, %.loopexit ]
  store i8 0, ptr %.012.lcssa, align 1, !tbaa !5
  %20 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) %4) #3
  call void @llvm.lifetime.end.p0(i64 200000, ptr nonnull %4) #3
  ret void
}

; 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 #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree 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" }
attributes #2 = { 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 #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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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