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

; 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::CPerson" = type { ptr, ptr, ptr, %"class.TPCE::CRandom", i8, i32, i64, ptr, ptr }
%"class.TPCE::CRandom" = type { i64 }

; 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 @_ZN4TPCE7CPerson16InitNextLoadUnitEx(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %"class.TPCE::CPerson", ptr %6, i32 0, i32 4
  %8 = load i8, ptr %7, align 8, !tbaa !11, !range !16, !noundef !17
  %9 = trunc i8 %8 to i1
  br i1 %9, label %10, label %36

10:                                               ; preds = %2
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = getelementptr inbounds %"class.TPCE::CPerson", ptr %6, i32 0, i32 6
  %13 = load i64, ptr %12, align 8, !tbaa !18
  %14 = add nsw i64 %13, %11
  store i64 %14, ptr %12, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !19
  br label %15

15:                                               ; preds = %32, %10
  %16 = load i32, ptr %5, align 4, !tbaa !19
  %17 = getelementptr inbounds %"class.TPCE::CPerson", ptr %6, i32 0, i32 5
  %18 = load i32, ptr %17, align 4, !tbaa !20
  %19 = icmp slt i32 %16, %18
  br i1 %19, label %21, label %20

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

21:                                               ; preds = %15
  %22 = getelementptr inbounds %"class.TPCE::CPerson", ptr %6, i32 0, i32 8
  %23 = load ptr, ptr %22, align 8, !tbaa !21
  %24 = load i32, ptr %5, align 4, !tbaa !19
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds ptr, ptr %23, i64 %25
  store ptr null, ptr %26, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.TPCE::CPerson", ptr %6, i32 0, i32 7
  %28 = load ptr, ptr %27, align 8, !tbaa !22
  %29 = load i32, ptr %5, align 4, !tbaa !19
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds ptr, ptr %28, i64 %30
  store ptr null, ptr %31, align 8, !tbaa !5
  br label %32

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

35:                                               ; preds = %20
  br label %36

36:                                               ; preds = %35, %2
  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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !14, i64 32}
!12 = !{!"_ZTSN4TPCE7CPersonE", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !14, i64 32, !15, i64 36, !10, i64 40, !6, i64 48, !6, i64 56}
!13 = !{!"_ZTSN4TPCE7CRandomE", !10, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!12, !10, i64 40}
!19 = !{!15, !15, i64 0}
!20 = !{!12, !15, i64 36}
!21 = !{!12, !6, i64 56}
!22 = !{!12, !6, i64 48}
!23 = distinct !{!23, !24}
!24 = !{!"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 nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN4TPCE7CPerson16InitNextLoadUnitEx(ptr nocapture noundef nonnull align 8 dereferenceable(64) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load i8, ptr %3, align 8, !tbaa !5, !range !14, !noundef !15
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %6, label %.loopexit

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load i64, ptr %7, align 8, !tbaa !16
  %9 = add nsw i64 %8, %1
  store i64 %9, ptr %7, align 8, !tbaa !16
  %10 = getelementptr inbounds i8, ptr %0, i64 36
  %11 = load i32, ptr %10, align 4, !tbaa !17
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %6
  %13 = getelementptr inbounds i8, ptr %0, i64 56
  %14 = getelementptr inbounds i8, ptr %0, i64 48
  %wide.trip.count = zext nneg i32 %11 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %15 = icmp eq i32 %11, 1
  br i1 %15, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

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

16:                                               ; preds = %16, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %16 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %16 ]
  %17 = load ptr, ptr %13, align 8, !tbaa !18
  %18 = getelementptr inbounds ptr, ptr %17, i64 %indvars.iv
  store ptr null, ptr %18, align 8, !tbaa !19
  %19 = load ptr, ptr %14, align 8, !tbaa !20
  %20 = getelementptr inbounds ptr, ptr %19, i64 %indvars.iv
  store ptr null, ptr %20, align 8, !tbaa !19
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %21 = load ptr, ptr %13, align 8, !tbaa !18
  %22 = getelementptr inbounds ptr, ptr %21, i64 %indvars.iv.next
  store ptr null, ptr %22, align 8, !tbaa !19
  %23 = load ptr, ptr %14, align 8, !tbaa !20
  %24 = getelementptr inbounds ptr, ptr %23, i64 %indvars.iv.next
  store ptr null, ptr %24, align 8, !tbaa !19
  %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 %.loopexit.loopexit.unr-lcssa, label %16, !llvm.loop !21

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

.loopexit.loopexit.epilog-lcssa:                  ; preds = %.loopexit.loopexit.unr-lcssa
  %25 = load ptr, ptr %13, align 8, !tbaa !18
  %26 = getelementptr inbounds ptr, ptr %25, i64 %indvars.iv.unr
  store ptr null, ptr %26, align 8, !tbaa !19
  %27 = load ptr, ptr %14, align 8, !tbaa !20
  %28 = getelementptr inbounds ptr, ptr %27, i64 %indvars.iv.unr
  store ptr null, ptr %28, align 8, !tbaa !19
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %6, %2
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(write, 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, !12, i64 32}
!6 = !{!"_ZTSN4TPCE7CPersonE", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !12, i64 32, !13, i64 36, !11, i64 40, !7, i64 48, !7, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN4TPCE7CRandomE", !11, i64 0}
!11 = !{!"long long", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!6, !11, i64 40}
!17 = !{!6, !13, i64 36}
!18 = !{!6, !7, i64 56}
!19 = !{!7, !7, i64 0}
!20 = !{!6, !7, i64 48}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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