; LLVM IR from sfu-dis/mosaicdb :: benchmarks/egen/CustomerTable.ll (ZN4TPCE14CCustomerTable16GenerateNextC_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::CUSTOMER_ROW", i64, i8, %"class.TPCE::CRandom" }
%"struct.TPCE::CUSTOMER_ROW" = type <{ i64, [21 x i8], [5 x i8], [26 x i8], [21 x i8], [2 x i8], i8, i8, [3 x i8], %"class.TPCE::CDateTime", i64, [4 x i8], [4 x i8], [11 x i8], [6 x i8], [4 x i8], [4 x i8], [11 x i8], [6 x i8], [4 x i8], [4 x i8], [11 x i8], [6 x i8], [51 x i8], [51 x i8], [7 x i8] }>
%"class.TPCE::CDateTime" = type { i32, i32, ptr }
%"class.TPCE::CRandom" = type { i64 }
%"class.TPCE::CCustomerTable" = type { %"class.TPCE::TableTemplate", i64, %"class.TPCE::CPerson", ptr, i64, i64, i64, i32, ptr, %"class.TPCE::CCustomerSelection" }
%"class.TPCE::CPerson" = type { ptr, ptr, ptr, %"class.TPCE::CRandom", i8, i32, i64, ptr, ptr }
%"class.TPCE::CCustomerSelection" = type { ptr, i64, i64, i8, i32, i64, i64 }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4TPCE14CCustomerTable16InitNextLoadUnitEv(ptr noundef nonnull align 8 dereferenceable(496)) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN4TPCE14CCustomerTable16GenerateNextC_IDEv(ptr noundef nonnull align 8 dereferenceable(496) %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 = srem i64 %5, 1000
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  call void @_ZN4TPCE14CCustomerTable16InitNextLoadUnitEv(ptr noundef nonnull align 8 dereferenceable(496) %3)
  br label %9

9:                                                ; preds = %8, %1
  %10 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 2
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %12 = add nsw i64 %11, 1
  store i64 %12, ptr %10, align 8, !tbaa !9
  %13 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 2
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds %"class.TPCE::CCustomerTable", ptr %3, i32 0, i32 1
  %16 = load i64, ptr %15, align 8, !tbaa !17
  %17 = icmp slt i64 %14, %16
  %18 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 3
  %19 = zext i1 %17 to i8
  store i8 %19, ptr %18, align 8, !tbaa !21
  %20 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 2
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds %"class.TPCE::CCustomerTable", ptr %3, i32 0, i32 4
  %23 = load i64, ptr %22, align 8, !tbaa !22
  %24 = add nsw i64 %21, %23
  %25 = sub nsw i64 %24, 1
  %26 = add nsw i64 %25, 4300000000
  %27 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 1
  %28 = getelementptr inbounds %"struct.TPCE::CUSTOMER_ROW", ptr %27, i32 0, i32 0
  store i64 %26, ptr %28, align 8, !tbaa !23
  %29 = getelementptr inbounds %"class.TPCE::TableTemplate", ptr %3, i32 0, i32 1
  %30 = getelementptr inbounds %"struct.TPCE::CUSTOMER_ROW", ptr %29, i32 0, i32 0
  %31 = load i64, ptr %30, align 8, !tbaa !23
  ret i64 %31
}

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 304}
!10 = !{!"_ZTSN4TPCE13TableTemplateINS_12CUSTOMER_ROWEEE", !11, i64 8, !12, i64 304, !15, i64 312, !16, i64 320}
!11 = !{!"_ZTSN4TPCE12CUSTOMER_ROWE", !12, i64 0, !7, i64 8, !7, i64 29, !7, i64 34, !7, i64 60, !7, i64 81, !7, i64 83, !7, i64 84, !13, i64 88, !12, i64 104, !7, i64 112, !7, i64 116, !7, i64 120, !7, i64 131, !7, i64 137, !7, i64 141, !7, i64 145, !7, i64 156, !7, i64 162, !7, i64 166, !7, i64 170, !7, i64 181, !7, i64 187, !7, i64 238}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"_ZTSN4TPCE9CDateTimeE", !14, i64 0, !14, i64 4, !6, i64 8}
!14 = !{!"int", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTSN4TPCE7CRandomE", !12, i64 0}
!17 = !{!18, !12, i64 328}
!18 = !{!"_ZTSN4TPCE14CCustomerTableE", !10, i64 0, !12, i64 328, !19, i64 336, !6, i64 400, !12, i64 408, !12, i64 416, !12, i64 424, !14, i64 432, !6, i64 440, !20, i64 448}
!19 = !{!"_ZTSN4TPCE7CPersonE", !6, i64 0, !6, i64 8, !6, i64 16, !16, i64 24, !15, i64 32, !14, i64 36, !12, i64 40, !6, i64 48, !6, i64 56}
!20 = !{!"_ZTSN4TPCE18CCustomerSelectionE", !6, i64 0, !12, i64 8, !12, i64 16, !15, i64 24, !14, i64 28, !12, i64 32, !12, i64 40}
!21 = !{!10, !15, i64 312}
!22 = !{!18, !12, i64 408}
!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 @_ZN4TPCE14CCustomerTable16InitNextLoadUnitEv(ptr noundef nonnull align 8 dereferenceable(496)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i64 -9223372032554775808, -9223372036854775808) i64 @_ZN4TPCE14CCustomerTable16GenerateNextC_IDEv(ptr noundef nonnull align 8 dereferenceable(496) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 304
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = srem i64 %3, 1000
  %5 = icmp eq i64 %4, 0
  br i1 %5, label %6, label %7

6:                                                ; preds = %1
  tail call void @_ZN4TPCE14CCustomerTable16InitNextLoadUnitEv(ptr noundef nonnull align 8 dereferenceable(496) %0)
  %.pre = load i64, ptr %2, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %6, %1
  %8 = phi i64 [ %.pre, %6 ], [ %3, %1 ]
  %9 = add nsw i64 %8, 1
  store i64 %9, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 328
  %11 = load i64, ptr %10, align 8, !tbaa !16
  %12 = icmp slt i64 %9, %11
  %13 = getelementptr inbounds i8, ptr %0, i64 312
  %14 = zext i1 %12 to i8
  store i8 %14, ptr %13, align 8, !tbaa !20
  %15 = getelementptr inbounds i8, ptr %0, i64 408
  %16 = load i64, ptr %15, align 8, !tbaa !21
  %17 = add i64 %8, 4300000000
  %18 = add i64 %17, %16
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %18, ptr %19, align 8, !tbaa !22
  ret i64 %18
}

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 304}
!6 = !{!"_ZTSN4TPCE13TableTemplateINS_12CUSTOMER_ROWEEE", !7, i64 8, !8, i64 304, !14, i64 312, !15, i64 320}
!7 = !{!"_ZTSN4TPCE12CUSTOMER_ROWE", !8, i64 0, !9, i64 8, !9, i64 29, !9, i64 34, !9, i64 60, !9, i64 81, !9, i64 83, !9, i64 84, !11, i64 88, !8, i64 104, !9, i64 112, !9, i64 116, !9, i64 120, !9, i64 131, !9, i64 137, !9, i64 141, !9, i64 145, !9, i64 156, !9, i64 162, !9, i64 166, !9, i64 170, !9, i64 181, !9, i64 187, !9, i64 238}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN4TPCE9CDateTimeE", !12, i64 0, !12, i64 4, !13, i64 8}
!12 = !{!"int", !9, i64 0}
!13 = !{!"any pointer", !9, i64 0}
!14 = !{!"bool", !9, i64 0}
!15 = !{!"_ZTSN4TPCE7CRandomE", !8, i64 0}
!16 = !{!17, !8, i64 328}
!17 = !{!"_ZTSN4TPCE14CCustomerTableE", !6, i64 0, !8, i64 328, !18, i64 336, !13, i64 400, !8, i64 408, !8, i64 416, !8, i64 424, !12, i64 432, !13, i64 440, !19, i64 448}
!18 = !{!"_ZTSN4TPCE7CPersonE", !13, i64 0, !13, i64 8, !13, i64 16, !15, i64 24, !14, i64 32, !12, i64 36, !8, i64 40, !13, i64 48, !13, i64 56}
!19 = !{!"_ZTSN4TPCE18CCustomerSelectionE", !13, i64 0, !8, i64 8, !8, i64 16, !14, i64 24, !12, i64 28, !8, i64 32, !8, i64 40}
!20 = !{!6, !14, i64 312}
!21 = !{!17, !8, i64 408}
!22 = !{!6, !8, i64 8}


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