; LLVM IR from buresjan/optim_lbm :: nomad/ext/sgtelib/src/TrainingSet.ll (ZN7SGTELIB11TrainingSet17compute_nvar_mvarEv)

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

%"class.SGTELIB::TrainingSet" = type { ptr, i32, i32, i32, i8, ptr, i8, i32, double, double, i32, %"class.SGTELIB::Matrix", %"class.SGTELIB::Matrix", %"class.SGTELIB::Matrix", %"class.SGTELIB::Matrix", %"class.SGTELIB::Matrix", i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, double }
%"class.SGTELIB::Matrix" = type { ptr, %"class.std::__cxx11::basic_string", i32, i32, ptr }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN7SGTELIB11TrainingSet17compute_nvar_mvarEv(ptr noundef nonnull align 8 dereferenceable(504) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %5, i32 0, i32 16
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %5, i32 0, i32 2
  %9 = load i32, ptr %8, align 4, !tbaa !18
  %10 = icmp ne i32 %7, %9
  br i1 %10, label %11, label %36

11:                                               ; preds = %1
  %12 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %5, i32 0, i32 16
  store i32 0, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !19
  br label %13

13:                                               ; preds = %32, %11
  %14 = load i32, ptr %3, align 4, !tbaa !19
  %15 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %5, i32 0, i32 2
  %16 = load i32, ptr %15, align 4, !tbaa !18
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %35

19:                                               ; preds = %13
  %20 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %5, i32 0, i32 25
  %21 = load ptr, ptr %20, align 8, !tbaa !20
  %22 = load i32, ptr %3, align 4, !tbaa !19
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %21, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !19
  %26 = icmp sgt i32 %25, 1
  br i1 %26, label %27, label %31

27:                                               ; preds = %19
  %28 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %5, i32 0, i32 16
  %29 = load i32, ptr %28, align 8, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %28, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %27, %19
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %3, align 4, !tbaa !19
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %3, align 4, !tbaa !19
  br label %13, !llvm.loop !21

35:                                               ; preds = %18
  br label %36

36:                                               ; preds = %35, %1
  %37 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %5, i32 0, i32 17
  %38 = load i32, ptr %37, align 4, !tbaa !23
  %39 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %5, i32 0, i32 3
  %40 = load i32, ptr %39, align 8, !tbaa !24
  %41 = icmp ne i32 %38, %40
  br i1 %41, label %42, label %67

42:                                               ; preds = %36
  %43 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %5, i32 0, i32 17
  store i32 0, ptr %43, align 4, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !19
  br label %44

44:                                               ; preds = %63, %42
  %45 = load i32, ptr %4, align 4, !tbaa !19
  %46 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %5, i32 0, i32 3
  %47 = load i32, ptr %46, align 8, !tbaa !24
  %48 = icmp slt i32 %45, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %66

50:                                               ; preds = %44
  %51 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %5, i32 0, i32 36
  %52 = load ptr, ptr %51, align 8, !tbaa !25
  %53 = load i32, ptr %4, align 4, !tbaa !19
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !19
  %57 = icmp sgt i32 %56, 1
  br i1 %57, label %58, label %62

58:                                               ; preds = %50
  %59 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %5, i32 0, i32 17
  %60 = load i32, ptr %59, align 4, !tbaa !23
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %59, align 4, !tbaa !23
  br label %62

62:                                               ; preds = %58, %50
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %4, align 4, !tbaa !19
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %4, align 4, !tbaa !19
  br label %44, !llvm.loop !26

66:                                               ; preds = %49
  br label %67

67:                                               ; preds = %66, %36
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 344}
!10 = !{!"_ZTSN7SGTELIB11TrainingSetE", !11, i64 8, !11, i64 12, !11, i64 16, !12, i64 20, !6, i64 24, !12, i64 32, !11, i64 36, !13, i64 40, !13, i64 48, !11, i64 56, !14, i64 64, !14, i64 120, !14, i64 176, !14, i64 232, !14, i64 288, !11, i64 344, !11, i64 348, !11, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !6, i64 392, !6, i64 400, !6, i64 408, !11, i64 416, !11, i64 420, !6, i64 424, !6, i64 432, !6, i64 440, !6, i64 448, !6, i64 456, !6, i64 464, !6, i64 472, !6, i64 480, !6, i64 488, !13, i64 496}
!11 = !{!"int", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!"_ZTSN7SGTELIB6MatrixE", !15, i64 8, !11, i64 40, !11, i64 44, !6, i64 48}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !16, i64 0, !17, i64 8, !7, i64 16}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!10, !11, i64 12}
!19 = !{!11, !11, i64 0}
!20 = !{!10, !6, i64 408}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!10, !11, i64 348}
!24 = !{!10, !11, i64 16}
!25 = !{!10, !6, i64 488}
!26 = distinct !{!26, !22}


; 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 nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN7SGTELIB11TrainingSet17compute_nvar_mvarEv(ptr nocapture noundef nonnull align 8 dereferenceable(504) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 344
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %5 = load i32, ptr %4, align 4, !tbaa !17
  %.not = icmp eq i32 %3, %5
  br i1 %.not, label %.loopexit8, label %6

6:                                                ; preds = %1
  store i32 0, ptr %2, align 8, !tbaa !5
  %7 = icmp sgt i32 %5, 0
  br i1 %7, label %.lr.ph, label %.loopexit8

.lr.ph:                                           ; preds = %6
  %8 = getelementptr inbounds i8, ptr %0, i64 408
  %9 = load ptr, ptr %8, align 8, !tbaa !18
  %wide.trip.count = zext nneg i32 %5 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %10 = icmp eq i32 %5, 1
  br i1 %10, label %.loopexit8.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %11

11:                                               ; preds = %25, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %25 ]
  %12 = phi i32 [ 0, %.lr.ph.new ], [ %26, %25 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %25 ]
  %13 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv
  %14 = load i32, ptr %13, align 4, !tbaa !19
  %15 = icmp sgt i32 %14, 1
  br i1 %15, label %16, label %18

16:                                               ; preds = %11
  %17 = add nsw i32 %12, 1
  store i32 %17, ptr %2, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %11, %16
  %19 = phi i32 [ %12, %11 ], [ %17, %16 ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %20 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv.next
  %21 = load i32, ptr %20, align 4, !tbaa !19
  %22 = icmp sgt i32 %21, 1
  br i1 %22, label %23, label %25

23:                                               ; preds = %18
  %24 = add nsw i32 %19, 1
  store i32 %24, ptr %2, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %23, %18
  %26 = phi i32 [ %19, %18 ], [ %24, %23 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit8.loopexit.unr-lcssa.loopexit, label %11, !llvm.loop !20

.loopexit8.loopexit.unr-lcssa.loopexit:           ; preds = %25
  %27 = add nsw i32 %26, 1
  br label %.loopexit8.loopexit.unr-lcssa

.loopexit8.loopexit.unr-lcssa:                    ; preds = %.loopexit8.loopexit.unr-lcssa.loopexit, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %.loopexit8.loopexit.unr-lcssa.loopexit ]
  %.unr = phi i32 [ 1, %.lr.ph ], [ %27, %.loopexit8.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit8, label %.epil.preheader

.epil.preheader:                                  ; preds = %.loopexit8.loopexit.unr-lcssa
  %28 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv.unr
  %29 = load i32, ptr %28, align 4, !tbaa !19
  %30 = icmp sgt i32 %29, 1
  br i1 %30, label %31, label %.loopexit8

31:                                               ; preds = %.epil.preheader
  store i32 %.unr, ptr %2, align 8, !tbaa !5
  br label %.loopexit8

.loopexit8:                                       ; preds = %.loopexit8.loopexit.unr-lcssa, %31, %.epil.preheader, %6, %1
  %32 = getelementptr inbounds i8, ptr %0, i64 348
  %33 = load i32, ptr %32, align 4, !tbaa !22
  %34 = getelementptr inbounds i8, ptr %0, i64 16
  %35 = load i32, ptr %34, align 8, !tbaa !23
  %.not7 = icmp eq i32 %33, %35
  br i1 %.not7, label %.loopexit, label %36

36:                                               ; preds = %.loopexit8
  store i32 0, ptr %32, align 4, !tbaa !22
  %37 = icmp sgt i32 %35, 0
  br i1 %37, label %.lr.ph12, label %.loopexit

.lr.ph12:                                         ; preds = %36
  %38 = getelementptr inbounds i8, ptr %0, i64 488
  %39 = load ptr, ptr %38, align 8, !tbaa !24
  %wide.trip.count17 = zext nneg i32 %35 to i64
  %xtraiter20 = and i64 %wide.trip.count17, 1
  %40 = icmp eq i32 %35, 1
  br i1 %40, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph12.new

.lr.ph12.new:                                     ; preds = %.lr.ph12
  %unroll_iter23 = and i64 %wide.trip.count17, 2147483646
  br label %41

41:                                               ; preds = %55, %.lr.ph12.new
  %indvars.iv14 = phi i64 [ 0, %.lr.ph12.new ], [ %indvars.iv.next15.1, %55 ]
  %42 = phi i32 [ 0, %.lr.ph12.new ], [ %56, %55 ]
  %niter24 = phi i64 [ 0, %.lr.ph12.new ], [ %niter24.next.1, %55 ]
  %43 = getelementptr inbounds i32, ptr %39, i64 %indvars.iv14
  %44 = load i32, ptr %43, align 4, !tbaa !19
  %45 = icmp sgt i32 %44, 1
  br i1 %45, label %46, label %48

46:                                               ; preds = %41
  %47 = add nsw i32 %42, 1
  store i32 %47, ptr %32, align 4, !tbaa !22
  br label %48

48:                                               ; preds = %41, %46
  %49 = phi i32 [ %42, %41 ], [ %47, %46 ]
  %indvars.iv.next15 = or disjoint i64 %indvars.iv14, 1
  %50 = getelementptr inbounds i32, ptr %39, i64 %indvars.iv.next15
  %51 = load i32, ptr %50, align 4, !tbaa !19
  %52 = icmp sgt i32 %51, 1
  br i1 %52, label %53, label %55

53:                                               ; preds = %48
  %54 = add nsw i32 %49, 1
  store i32 %54, ptr %32, align 4, !tbaa !22
  br label %55

55:                                               ; preds = %53, %48
  %56 = phi i32 [ %49, %48 ], [ %54, %53 ]
  %indvars.iv.next15.1 = add nuw nsw i64 %indvars.iv14, 2
  %niter24.next.1 = add i64 %niter24, 2
  %niter24.ncmp.1 = icmp eq i64 %niter24.next.1, %unroll_iter23
  br i1 %niter24.ncmp.1, label %.loopexit.loopexit.unr-lcssa.loopexit, label %41, !llvm.loop !25

.loopexit.loopexit.unr-lcssa.loopexit:            ; preds = %55
  %57 = add nsw i32 %56, 1
  br label %.loopexit.loopexit.unr-lcssa

.loopexit.loopexit.unr-lcssa:                     ; preds = %.loopexit.loopexit.unr-lcssa.loopexit, %.lr.ph12
  %indvars.iv14.unr = phi i64 [ 0, %.lr.ph12 ], [ %indvars.iv.next15.1, %.loopexit.loopexit.unr-lcssa.loopexit ]
  %.unr21 = phi i32 [ 1, %.lr.ph12 ], [ %57, %.loopexit.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod22.not = icmp eq i64 %xtraiter20, 0
  br i1 %lcmp.mod22.not, label %.loopexit, label %.epil.preheader19

.epil.preheader19:                                ; preds = %.loopexit.loopexit.unr-lcssa
  %58 = getelementptr inbounds i32, ptr %39, i64 %indvars.iv14.unr
  %59 = load i32, ptr %58, align 4, !tbaa !19
  %60 = icmp sgt i32 %59, 1
  br i1 %60, label %61, label %.loopexit

61:                                               ; preds = %.epil.preheader19
  store i32 %.unr21, ptr %32, align 4, !tbaa !22
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %61, %.epil.preheader19, %36, %.loopexit8
  ret void
}

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

!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, !7, i64 344}
!6 = !{!"_ZTSN7SGTELIB11TrainingSetE", !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 20, !11, i64 24, !10, i64 32, !7, i64 36, !12, i64 40, !12, i64 48, !7, i64 56, !13, i64 64, !13, i64 120, !13, i64 176, !13, i64 232, !13, i64 288, !7, i64 344, !7, i64 348, !7, i64 352, !11, i64 360, !11, i64 368, !11, i64 376, !11, i64 384, !11, i64 392, !11, i64 400, !11, i64 408, !7, i64 416, !7, i64 420, !11, i64 424, !11, i64 432, !11, i64 440, !11, i64 448, !11, i64 456, !11, i64 464, !11, i64 472, !11, i64 480, !11, i64 488, !12, i64 496}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = !{!"_ZTSN7SGTELIB6MatrixE", !14, i64 8, !7, i64 40, !7, i64 44, !11, i64 48}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !15, i64 0, !16, i64 8, !8, i64 16}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !11, i64 0}
!16 = !{!"long", !8, i64 0}
!17 = !{!6, !7, i64 12}
!18 = !{!6, !11, i64 408}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!6, !7, i64 348}
!23 = !{!6, !7, i64 16}
!24 = !{!6, !11, i64 488}
!25 = distinct !{!25, !21}


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