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

; 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: mustprogress uwtable
declare dso_local void @_ZN4TPCE13CAddressTable16InitNextLoadUnitEv(ptr noundef nonnull align 8 dereferenceable(416)) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN4TPCE13CAddressTable17GenerateNextAD_IDEv(ptr noundef nonnull align 8 dereferenceable(416) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  %4 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 2
  %5 = load i64, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds %"class.TPCE::CAddressTable", ptr %3, i32 0, i32 11
  %7 = load i32, ptr %6, align 8, !tbaa !15
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds %"class.TPCE::CAddressTable", ptr %3, i32 0, i32 10
  %10 = load i64, ptr %9, align 8, !tbaa !19
  %11 = add nsw i64 %8, %10
  %12 = icmp sgt i64 %5, %11
  br i1 %12, label %13, label %26

13:                                               ; preds = %1
  %14 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 2
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %"class.TPCE::CAddressTable", ptr %3, i32 0, i32 11
  %17 = load i32, ptr %16, align 8, !tbaa !15
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds %"class.TPCE::CAddressTable", ptr %3, i32 0, i32 10
  %20 = load i64, ptr %19, align 8, !tbaa !19
  %21 = add nsw i64 %18, %20
  %22 = sub nsw i64 %15, %21
  %23 = srem i64 %22, 1000
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %13
  call void @_ZN4TPCE13CAddressTable16InitNextLoadUnitEv(ptr noundef nonnull align 8 dereferenceable(416) %3)
  br label %26

26:                                               ; preds = %25, %13, %1
  %27 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 2
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = add nsw i64 %28, 1
  store i64 %29, ptr %27, align 8, !tbaa !9
  %30 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 2
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = getelementptr inbounds %"class.TPCE::CAddressTable", ptr %3, i32 0, i32 11
  %33 = load i32, ptr %32, align 8, !tbaa !15
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds %"class.TPCE::CAddressTable", ptr %3, i32 0, i32 10
  %36 = load i64, ptr %35, align 8, !tbaa !19
  %37 = add nsw i64 %34, %36
  %38 = icmp sge i64 %31, %37
  %39 = getelementptr inbounds %"class.TPCE::CAddressTable", ptr %3, i32 0, i32 9
  %40 = zext i1 %38 to i8
  store i8 %40, ptr %39, align 1, !tbaa !20
  %41 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 2
  %42 = load i64, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds %"class.TPCE::CAddressTable", ptr %3, i32 0, i32 12
  %44 = load i64, ptr %43, align 8, !tbaa !21
  %45 = icmp slt i64 %42, %44
  %46 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 3
  %47 = zext i1 %45 to i8
  store i8 %47, ptr %46, align 8, !tbaa !22
  %48 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 2
  %49 = load i64, ptr %48, align 8, !tbaa !9
  %50 = add nsw i64 %49, 4300000000
  %51 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 1
  %52 = getelementptr inbounds %"struct.TPCE::ADDRESS_ROW", ptr %51, i32 0, i32 0
  store i64 %50, ptr %52, align 8, !tbaa !23
  %53 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 1
  %54 = getelementptr inbounds %"struct.TPCE::ADDRESS_ROW", ptr %53, i32 0, i32 0
  %55 = load i64, ptr %54, align 8, !tbaa !23
  ret i64 %55
}

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

!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, !18, i64 376}
!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 = !{!16, !12, i64 368}
!20 = !{!16, !13, i64 361}
!21 = !{!16, !12, i64 384}
!22 = !{!10, !13, i64 280}
!23 = !{!10, !12, i64 8}


; 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
declare dso_local void @_ZN4TPCE13CAddressTable16InitNextLoadUnitEv(ptr noundef nonnull align 8 dereferenceable(416)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i64 -9223372032554775808, -9223372036854775808) i64 @_ZN4TPCE13CAddressTable17GenerateNextAD_IDEv(ptr noundef nonnull align 8 dereferenceable(416) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 272
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 376
  %5 = load i32, ptr %4, align 8, !tbaa !13
  %6 = zext i32 %5 to i64
  %7 = getelementptr inbounds i8, ptr %0, i64 368
  %8 = load i64, ptr %7, align 8, !tbaa !18
  %9 = add nsw i64 %8, %6
  %10 = icmp sgt i64 %3, %9
  br i1 %10, label %11, label %16

11:                                               ; preds = %1
  %12 = sub nsw i64 %3, %9
  %13 = srem i64 %12, 1000
  %14 = icmp eq i64 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  tail call void @_ZN4TPCE13CAddressTable16InitNextLoadUnitEv(ptr noundef nonnull align 8 dereferenceable(416) %0)
  %.pre = load i64, ptr %2, align 8, !tbaa !5
  %.pre2 = load i32, ptr %4, align 8, !tbaa !13
  %.pre3 = load i64, ptr %7, align 8, !tbaa !18
  %.pre4 = zext i32 %.pre2 to i64
  %.pre5 = add nsw i64 %.pre3, %.pre4
  br label %16

16:                                               ; preds = %15, %11, %1
  %.pre-phi6 = phi i64 [ %.pre5, %15 ], [ %9, %11 ], [ %9, %1 ]
  %17 = phi i64 [ %.pre, %15 ], [ %3, %11 ], [ %3, %1 ]
  %18 = add nsw i64 %17, 1
  store i64 %18, ptr %2, align 8, !tbaa !5
  %19 = icmp sge i64 %18, %.pre-phi6
  %20 = getelementptr inbounds i8, ptr %0, i64 361
  %21 = zext i1 %19 to i8
  store i8 %21, ptr %20, align 1, !tbaa !19
  %22 = getelementptr inbounds i8, ptr %0, i64 384
  %23 = load i64, ptr %22, align 8, !tbaa !20
  %24 = icmp slt i64 %18, %23
  %25 = getelementptr inbounds i8, ptr %0, i64 280
  %26 = zext i1 %24 to i8
  store i8 %26, ptr %25, align 8, !tbaa !21
  %27 = add nsw i64 %17, 4300000001
  %28 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %27, ptr %28, align 8, !tbaa !22
  ret i64 %27
}

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

!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, !16, i64 376}
!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 = !{!14, !8, i64 368}
!19 = !{!14, !11, i64 361}
!20 = !{!14, !8, i64 384}
!21 = !{!6, !11, i64 280}
!22 = !{!6, !8, i64 8}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,SROAPass,TailCallElimPass