; LLVM IR from jingweizhanghuai/Morn :: test (test_large_integer)

; 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.MArray = type { i32, i16, %union.anon }
%union.anon = type { ptr }

@.str.1 = external hidden unnamed_addr constant [81 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@__FUNCTION__.test2_Morn = external hidden unnamed_addr constant [11 x i8], align 1

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

declare void @_mTimerBegin(ptr noundef) #1

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

declare float @_mTimerEnd(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

declare ptr @ArrayCreate(i32 noundef, i32 noundef, ptr noundef) #1

declare void @mIntToLInt(ptr noundef, i64 noundef) #1

declare void @m_LIntMulInt(ptr noundef, i64 noundef, ptr noundef) #1

declare void @m_LIntMul(ptr noundef, ptr noundef, ptr noundef) #1

declare void @mLIntToString(ptr noundef, ptr noundef) #1

declare void @mArrayRelease(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @test2_Morn(i32 noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %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 i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %9 = call ptr @ArrayCreate(i32 noundef -1, i32 noundef 0, ptr noundef null)
  store ptr %9, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %10 = call ptr @ArrayCreate(i32 noundef -1, i32 noundef 0, ptr noundef null)
  store ptr %10, ptr %6, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  call void @mIntToLInt(ptr noundef %11, i64 noundef 1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %39, %2
  %13 = load i32, ptr %7, align 4, !tbaa !5
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %42

17:                                               ; preds = %12
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = sext i32 %19 to i64
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = add nsw i64 %22, 1
  %24 = icmp eq i64 %20, %23
  br i1 %24, label %25, label %32

25:                                               ; preds = %17
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = trunc i64 %28 to i32
  %30 = sext i32 %29 to i64
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  call void @m_LIntMulInt(ptr noundef %26, i64 noundef %30, ptr noundef %31)
  br label %38

32:                                               ; preds = %17
  %33 = load ptr, ptr %5, align 8, !tbaa !9
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = inttoptr i64 %35 to ptr
  %37 = load ptr, ptr %5, align 8, !tbaa !9
  call void @m_LIntMul(ptr noundef %33, ptr noundef %36, ptr noundef %37)
  br label %38

38:                                               ; preds = %32, %25
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %7, align 4, !tbaa !5
  br label %12, !llvm.loop !11

42:                                               ; preds = %16
  call void @_mTimerBegin(ptr noundef @.str.4)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %71, %42
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = icmp slt i32 %44, 1000
  br i1 %45, label %47, label %46

46:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %74

47:                                               ; preds = %43
  %48 = load ptr, ptr %5, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.MArray, ptr %48, i64 1
  %50 = ptrtoint ptr %49 to i64
  %51 = load ptr, ptr %5, align 8, !tbaa !9
  %52 = ptrtoint ptr %51 to i64
  %53 = add nsw i64 %52, 1
  %54 = icmp eq i64 %50, %53
  br i1 %54, label %55, label %63

55:                                               ; preds = %47
  %56 = load ptr, ptr %5, align 8, !tbaa !9
  %57 = load ptr, ptr %5, align 8, !tbaa !9
  %58 = ptrtoint ptr %57 to i64
  %59 = trunc i64 %58 to i32
  %60 = sext i32 %59 to i64
  %61 = load ptr, ptr %6, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.MArray, ptr %61, i64 0
  call void @m_LIntMulInt(ptr noundef %56, i64 noundef %60, ptr noundef %62)
  br label %70

63:                                               ; preds = %47
  %64 = load ptr, ptr %5, align 8, !tbaa !9
  %65 = load ptr, ptr %5, align 8, !tbaa !9
  %66 = ptrtoint ptr %65 to i64
  %67 = inttoptr i64 %66 to ptr
  %68 = load ptr, ptr %6, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.MArray, ptr %68, i64 0
  call void @m_LIntMul(ptr noundef %64, ptr noundef %67, ptr noundef %69)
  br label %70

70:                                               ; preds = %63, %55
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %8, align 4, !tbaa !5
  br label %43, !llvm.loop !13

74:                                               ; preds = %46
  %75 = call float @_mTimerEnd(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 145, ptr noundef @__FUNCTION__.test2_Morn)
  %76 = load ptr, ptr %6, align 8, !tbaa !9
  %77 = load ptr, ptr %4, align 8, !tbaa !9
  call void @mLIntToString(ptr noundef %76, ptr noundef %77)
  %78 = load ptr, ptr %5, align 8, !tbaa !9
  call void @mArrayRelease(ptr noundef %78)
  %79 = load ptr, ptr %6, align 8, !tbaa !9
  call void @mArrayRelease(ptr noundef %79)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@.str.1 = external hidden unnamed_addr constant [81 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@__FUNCTION__.test2_Morn = external hidden unnamed_addr constant [11 x i8], align 1

declare void @_mTimerBegin(ptr noundef) local_unnamed_addr #0

declare float @_mTimerEnd(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare ptr @ArrayCreate(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare void @mIntToLInt(ptr noundef, i64 noundef) local_unnamed_addr #0

declare void @m_LIntMulInt(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

declare void @m_LIntMul(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @mLIntToString(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @mArrayRelease(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @test2_Morn(i32 noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call ptr @ArrayCreate(i32 noundef -1, i32 noundef 0, ptr noundef null) #2
  %4 = tail call ptr @ArrayCreate(i32 noundef -1, i32 noundef 0, ptr noundef null) #2
  tail call void @mIntToLInt(ptr noundef %3, i64 noundef 1) #2
  %.not26 = icmp slt i32 %0, 1
  br i1 %.not26, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %5 = add nuw i32 %0, 1
  %wide.trip.count = zext i32 %5 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %2
  tail call void @_mTimerBegin(ptr noundef nonnull @.str.4) #2
  %6 = getelementptr inbounds i8, ptr %3, i64 16
  %7 = ptrtoint ptr %6 to i64
  %8 = ptrtoint ptr %3 to i64
  %9 = add nsw i64 %8, 1
  %10 = icmp eq i64 %9, %7
  %sext = shl i64 %8, 32
  %11 = ashr exact i64 %sext, 32
  br i1 %10, label %.split.us, label %.split

.split.us:                                        ; preds = %._crit_edge, %.split.us
  %.028.us = phi i32 [ %12, %.split.us ], [ 0, %._crit_edge ]
  tail call void @m_LIntMulInt(ptr noundef %3, i64 noundef %11, ptr noundef %4) #2
  %12 = add nuw nsw i32 %.028.us, 1
  %exitcond34.not = icmp eq i32 %12, 1000
  br i1 %exitcond34.not, label %.split30.us, label %.split.us, !llvm.loop !5

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  tail call void @m_LIntMulInt(ptr noundef %3, i64 noundef %indvars.iv, ptr noundef %3) #2
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !7

.split30.us:                                      ; preds = %.split, %.split.us
  %13 = tail call float @_mTimerEnd(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 145, ptr noundef nonnull @__FUNCTION__.test2_Morn) #2
  tail call void @mLIntToString(ptr noundef %4, ptr noundef %1) #2
  tail call void @mArrayRelease(ptr noundef %3) #2
  tail call void @mArrayRelease(ptr noundef %4) #2
  ret void

.split:                                           ; preds = %._crit_edge, %.split
  %.028 = phi i32 [ %14, %.split ], [ 0, %._crit_edge ]
  tail call void @m_LIntMul(ptr noundef %3, ptr noundef %3, ptr noundef %4) #2
  %14 = add nuw nsw i32 %.028, 1
  %exitcond33.not = icmp eq i32 %14, 1000
  br i1 %exitcond33.not, label %.split30.us, label %.split, !llvm.loop !5
}

attributes #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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: ConstraintEliminationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass