; LLVM IR from Dev-XYS/Algorithms :: Linear-Basis.ll (Z12linear_basisv)

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

@n = external dso_local global i32, align 4
@d = external dso_local global [100000 x i32], align 16
@b = external dso_local global [32 x i32], align 16
@bsize = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z12linear_basisv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %64, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp slt i32 %5, %6
  br i1 %7, label %9, label %8

8:                                                ; preds = %4
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %67

9:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 30, ptr %3, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %59, %9
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = icmp sge i32 %11, 0
  br i1 %12, label %13, label %19

13:                                               ; preds = %10
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100000 x i32], ptr @d, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 0
  br label %19

19:                                               ; preds = %13, %10
  %20 = phi i1 [ false, %10 ], [ %18, %13 ]
  br i1 %20, label %22, label %21

21:                                               ; preds = %19
  store i32 5, ptr %2, align 4
  br label %62

22:                                               ; preds = %19
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100000 x i32], ptr @d, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = ashr i32 %26, %27
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %22
  br label %59

31:                                               ; preds = %22
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [32 x i32], ptr @b, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %47

37:                                               ; preds = %31
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [32 x i32], ptr @b, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = load i32, ptr %1, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100000 x i32], ptr @d, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = xor i32 %45, %41
  store i32 %46, ptr %44, align 4, !tbaa !5
  br label %57

47:                                               ; preds = %31
  %48 = load i32, ptr %1, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100000 x i32], ptr @d, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [32 x i32], ptr @b, i64 0, i64 %53
  store i32 %51, ptr %54, align 4, !tbaa !5
  %55 = load i32, ptr @bsize, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr @bsize, align 4, !tbaa !5
  store i32 5, ptr %2, align 4
  br label %62

57:                                               ; preds = %37
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58, %30
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = add nsw i32 %60, -1
  store i32 %61, ptr %3, align 4, !tbaa !5
  br label %10, !llvm.loop !9

62:                                               ; preds = %47, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %1, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %1, align 4, !tbaa !5
  br label %4, !llvm.loop !11

67:                                               ; preds = %8
  ret void
}

; 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

attributes #0 = { mustprogress 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 }

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


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

@n = external dso_local local_unnamed_addr global i32, align 4
@d = external dso_local local_unnamed_addr global [100000 x i32], align 16
@b = external dso_local local_unnamed_addr global [32 x i32], align 16
@bsize = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z12linear_basisv() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.preheader.preheader, label %._crit_edge

.preheader.preheader:                             ; preds = %0
  %bsize.promoted = load i32, ptr @bsize, align 4, !tbaa !5
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.critedge
  %indvars.iv23 = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next24, %.critedge ]
  %3 = phi i32 [ %bsize.promoted, %.preheader.preheader ], [ %32, %.critedge ]
  %4 = getelementptr inbounds [100000 x i32], ptr @d, i64 0, i64 %indvars.iv23
  %.promoted = load i32, ptr %4, align 4, !tbaa !5
  br label %5

._crit_edge:                                      ; preds = %.critedge, %0
  ret void

5:                                                ; preds = %30, %.preheader
  %indvars.iv = phi i64 [ 30, %.preheader ], [ %indvars.iv.next.1, %30 ]
  %6 = phi i32 [ %.promoted, %.preheader ], [ %31, %30 ]
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %.critedge, label %7

7:                                                ; preds = %5
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  %9 = ashr i32 %6, %8
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %19, label %11

11:                                               ; preds = %7
  %12 = getelementptr inbounds [32 x i32], ptr @b, i64 0, i64 %indvars.iv
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %.not15 = icmp eq i32 %13, 0
  br i1 %.not15, label %16, label %14

14:                                               ; preds = %11
  %15 = xor i32 %13, %6
  store i32 %15, ptr %4, align 4, !tbaa !5
  br label %19

16:                                               ; preds = %25, %11
  %indvars.iv.lcssa32 = phi i64 [ %indvars.iv, %11 ], [ %indvars.iv.next, %25 ]
  %.lcssa31 = phi i32 [ %6, %11 ], [ %20, %25 ]
  %17 = getelementptr inbounds [32 x i32], ptr @b, i64 0, i64 %indvars.iv.lcssa32
  store i32 %.lcssa31, ptr %17, align 4, !tbaa !5
  %18 = add nsw i32 %3, 1
  store i32 %18, ptr @bsize, align 4, !tbaa !5
  br label %.critedge

19:                                               ; preds = %7, %14
  %20 = phi i32 [ %6, %7 ], [ %15, %14 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not26 = icmp eq i64 %indvars.iv, 0
  %.not.1 = icmp eq i32 %20, 0
  %or.cond = or i1 %.not26, %.not.1
  br i1 %or.cond, label %.critedge, label %21, !llvm.loop !9

21:                                               ; preds = %19
  %22 = trunc nuw nsw i64 %indvars.iv.next to i32
  %23 = ashr i32 %20, %22
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %30, label %25

25:                                               ; preds = %21
  %26 = getelementptr inbounds [32 x i32], ptr @b, i64 0, i64 %indvars.iv.next
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not15.1 = icmp eq i32 %27, 0
  br i1 %.not15.1, label %16, label %28

28:                                               ; preds = %25
  %29 = xor i32 %27, %20
  store i32 %29, ptr %4, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %28, %21
  %31 = phi i32 [ %20, %21 ], [ %29, %28 ]
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, -2
  br label %5

.critedge:                                        ; preds = %5, %19, %16
  %32 = phi i32 [ %18, %16 ], [ %3, %19 ], [ %3, %5 ]
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next24, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.preheader, !llvm.loop !11
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, 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" }

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


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