; LLVM IR from sfu-dis/mosaicdb :: benchmarks/egen/AddressTable.ll (ZN4TPCE13CAddressTable16InitNextLoadUnitEv)

; 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.TPCE::TableTemplate" = type { ptr, %"struct.TPCE::ADDRESS_ROW", i64, i8, %"class.TPCE::CRandom" }
%"struct.TPCE::ADDRESS_ROW" = type { i64, [81 x i8], [81 x i8], [13 x i8], [81 x i8] }
%"class.TPCE::CRandom" = type { i64 }
%"class.TPCE::CAddressTable" = type { %"class.TPCE::TableTemplate", %"class.TPCE::CDateTime", ptr, ptr, ptr, ptr, i64, i64, i8, i8, i64, i32, i64, i8, i32, i64, ptr }
%"class.TPCE::CDateTime" = type { i32, i32, ptr }

; 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 uwtable
define dso_local void @_ZN4TPCE13CAddressTable16InitNextLoadUnitEv(ptr noundef nonnull align 8 dereferenceable(416) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %4, i32 0, i32 4
  %6 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %4, i32 0, i32 4
  %7 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %4, i32 0, i32 2
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = mul i64 %8, 10
  %10 = call noundef i64 @_ZN4TPCE7CRandom13RndNthElementEyy(ptr noundef nonnull align 8 dereferenceable(8) %6, i64 noundef 37039940, i64 noundef %9)
  call void @_ZN4TPCE7CRandom7SetSeedEy(ptr noundef nonnull align 8 dereferenceable(8) %5, i64 noundef %10)
  call void @_ZN4TPCE13TableTemplateINS_11ADDRESS_ROWEE11ClearRecordEv(ptr noundef nonnull align 8 dereferenceable(296) %4)
  %11 = getelementptr inbounds %"class.TPCE::CAddressTable", ptr %4, i32 0, i32 13
  %12 = load i8, ptr %11, align 8, !tbaa !15, !range !19, !noundef !20
  %13 = trunc i8 %12 to i1
  br i1 %13, label %14, label %34

14:                                               ; preds = %1
  %15 = getelementptr inbounds %"class.TPCE::CAddressTable", ptr %4, i32 0, i32 15
  %16 = load i64, ptr %15, align 8, !tbaa !21
  %17 = add nsw i64 %16, 1000
  store i64 %17, ptr %15, align 8, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !22
  br label %18

18:                                               ; preds = %30, %14
  %19 = load i32, ptr %3, align 4, !tbaa !22
  %20 = getelementptr inbounds %"class.TPCE::CAddressTable", ptr %4, i32 0, i32 14
  %21 = load i32, ptr %20, align 4, !tbaa !23
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %18
  %25 = getelementptr inbounds %"class.TPCE::CAddressTable", ptr %4, i32 0, i32 16
  %26 = load ptr, ptr %25, align 8, !tbaa !24
  %27 = load i32, ptr %3, align 4, !tbaa !22
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds ptr, ptr %26, i64 %28
  store ptr null, ptr %29, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %24
  %31 = load i32, ptr %3, align 4, !tbaa !22
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %3, align 4, !tbaa !22
  br label %18, !llvm.loop !25

33:                                               ; preds = %23
  br label %34

34:                                               ; preds = %33, %1
  ret void
}

declare void @_ZN4TPCE7CRandom7SetSeedEy(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #2

declare noundef i64 @_ZN4TPCE7CRandom13RndNthElementEyy(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef, i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4TPCE13TableTemplateINS_11ADDRESS_ROWEE11ClearRecordEv(ptr noundef nonnull align 8 dereferenceable(296)) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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 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 #4 = { 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, !12, i64 272}
!10 = !{!"_ZTSN4TPCE13TableTemplateINS_11ADDRESS_ROWEEE", !11, i64 8, !12, i64 272, !13, i64 280, !14, i64 288}
!11 = !{!"_ZTSN4TPCE11ADDRESS_ROWE", !12, i64 0, !7, i64 8, !7, i64 89, !7, i64 170, !7, i64 183}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN4TPCE7CRandomE", !12, i64 0}
!15 = !{!16, !13, i64 392}
!16 = !{!"_ZTSN4TPCE13CAddressTableE", !10, i64 0, !17, i64 296, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !12, i64 344, !12, i64 352, !13, i64 360, !13, i64 361, !12, i64 368, !18, i64 376, !12, i64 384, !13, i64 392, !18, i64 396, !12, i64 400, !6, i64 408}
!17 = !{!"_ZTSN4TPCE9CDateTimeE", !18, i64 0, !18, i64 4, !6, i64 8}
!18 = !{!"int", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!16, !12, i64 400}
!22 = !{!18, !18, i64 0}
!23 = !{!16, !18, i64 396}
!24 = !{!16, !6, i64 408}
!25 = distinct !{!25, !26}
!26 = !{!"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"

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4TPCE13CAddressTable16InitNextLoadUnitEv(ptr noundef nonnull align 8 dereferenceable(416) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 288
  %3 = getelementptr inbounds i8, ptr %0, i64 272
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = mul i64 %4, 10
  %6 = tail call noundef i64 @_ZN4TPCE7CRandom13RndNthElementEyy(ptr noundef nonnull align 8 dereferenceable(8) %2, i64 noundef 37039940, i64 noundef %5)
  tail call void @_ZN4TPCE7CRandom7SetSeedEy(ptr noundef nonnull align 8 dereferenceable(8) %2, i64 noundef %6)
  tail call void @_ZN4TPCE13TableTemplateINS_11ADDRESS_ROWEE11ClearRecordEv(ptr noundef nonnull align 8 dereferenceable(296) %0)
  %7 = getelementptr inbounds i8, ptr %0, i64 392
  %8 = load i8, ptr %7, align 8, !tbaa !13, !range !18, !noundef !19
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %10, label %.loopexit

10:                                               ; preds = %1
  %11 = getelementptr inbounds i8, ptr %0, i64 400
  %12 = load i64, ptr %11, align 8, !tbaa !20
  %13 = add nsw i64 %12, 1000
  store i64 %13, ptr %11, align 8, !tbaa !20
  %14 = getelementptr inbounds i8, ptr %0, i64 396
  %15 = load i32, ptr %14, align 4, !tbaa !21
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %10
  %17 = getelementptr inbounds i8, ptr %0, i64 408
  %wide.trip.count = zext nneg i32 %15 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %18 = icmp ult i32 %15, 4
  br i1 %18, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

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

19:                                               ; preds = %19, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %19 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %19 ]
  %20 = load ptr, ptr %17, align 8, !tbaa !22
  %21 = getelementptr inbounds ptr, ptr %20, i64 %indvars.iv
  store ptr null, ptr %21, align 8, !tbaa !23
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %22 = load ptr, ptr %17, align 8, !tbaa !22
  %23 = getelementptr inbounds ptr, ptr %22, i64 %indvars.iv.next
  store ptr null, ptr %23, align 8, !tbaa !23
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %24 = load ptr, ptr %17, align 8, !tbaa !22
  %25 = getelementptr inbounds ptr, ptr %24, i64 %indvars.iv.next.1
  store ptr null, ptr %25, align 8, !tbaa !23
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %26 = load ptr, ptr %17, align 8, !tbaa !22
  %27 = getelementptr inbounds ptr, ptr %26, i64 %indvars.iv.next.2
  store ptr null, ptr %27, align 8, !tbaa !23
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.loopexit.loopexit.unr-lcssa, label %19, !llvm.loop !24

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

.epil.preheader:                                  ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %28 = load ptr, ptr %17, align 8, !tbaa !22
  %29 = getelementptr inbounds ptr, ptr %28, i64 %indvars.iv.epil
  store ptr null, ptr %29, align 8, !tbaa !23
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.loopexit, label %.epil.preheader, !llvm.loop !26

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader, %10, %1
  ret void
}

declare void @_ZN4TPCE7CRandom7SetSeedEy(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #1

declare noundef i64 @_ZN4TPCE7CRandom13RndNthElementEyy(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4TPCE13TableTemplateINS_11ADDRESS_ROWEE11ClearRecordEv(ptr noundef nonnull align 8 dereferenceable(296)) local_unnamed_addr #2 align 2

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

!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, !8, i64 272}
!6 = !{!"_ZTSN4TPCE13TableTemplateINS_11ADDRESS_ROWEEE", !7, i64 8, !8, i64 272, !11, i64 280, !12, i64 288}
!7 = !{!"_ZTSN4TPCE11ADDRESS_ROWE", !8, i64 0, !9, i64 8, !9, i64 89, !9, i64 170, !9, i64 183}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"bool", !9, i64 0}
!12 = !{!"_ZTSN4TPCE7CRandomE", !8, i64 0}
!13 = !{!14, !11, i64 392}
!14 = !{!"_ZTSN4TPCE13CAddressTableE", !6, i64 0, !15, i64 296, !17, i64 312, !17, i64 320, !17, i64 328, !17, i64 336, !8, i64 344, !8, i64 352, !11, i64 360, !11, i64 361, !8, i64 368, !16, i64 376, !8, i64 384, !11, i64 392, !16, i64 396, !8, i64 400, !17, i64 408}
!15 = !{!"_ZTSN4TPCE9CDateTimeE", !16, i64 0, !16, i64 4, !17, i64 8}
!16 = !{!"int", !9, i64 0}
!17 = !{!"any pointer", !9, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!14, !8, i64 400}
!21 = !{!14, !16, i64 396}
!22 = !{!14, !17, i64 408}
!23 = !{!17, !17, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.unroll.disable"}


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