; LLVM IR from ryanlayer/giggle :: test/unit (test_bulk_insert)

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

%struct.giggle_def = type { %struct.cache_handler, %struct.cache_handler, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.cache_handler = type { ptr, ptr, ptr }
%struct.giggle_index = type { ptr, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.file_index = type { ptr, ptr }
%struct.unordered_list = type { ptr, i32, i32 }
%struct.chrm_index = type { ptr, ptr }
%struct.ordered_set = type { ptr, i32, i32, ptr, ptr, ptr }
%struct.offset_index = type { ptr, ptr, i32, ptr, i32 }
%struct.file_id_offset_pairs = type { i64, i64, ptr }

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@giggle_data_handler = external dso_local global %struct.giggle_def, align 8
@.str.8 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [28 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare void @UnityAssertEqualNumber(i64 noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i32 @rmrf(ptr noundef) #1

declare void @giggle_index_destroy(ptr noundef) #1

declare i64 @giggle_bulk_insert(ptr noundef, ptr noundef, i32 noundef) #1

declare ptr @giggle_load(ptr noundef, ptr noundef) #1

declare void @uint64_t_ll_giggle_set_data_handler(...) #1

declare ptr @giggle_collect_intersection_data_in_block(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #1

declare void @leaf_data_map_intersection_to_offset_list(ptr noundef, ptr noundef, ptr noundef) #1

declare ptr @giggle_query(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @test_giggle_bulk_insert() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  store ptr @.str, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store ptr @.str.12, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = call i64 @giggle_bulk_insert(ptr noundef %6, ptr noundef %7, i32 noundef 1)
  store i64 %8, ptr %3, align 8, !tbaa !9
  %9 = load i64, ptr %3, align 8, !tbaa !9
  call void @UnityAssertEqualNumber(i64 noundef 21024, i64 noundef %9, ptr noundef null, i64 noundef 1972, i32 noundef 148)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call ptr @giggle_load(ptr noundef %10, ptr noundef @uint64_t_ll_giggle_set_data_handler)
  store ptr %11, ptr %4, align 8, !tbaa !5
  store ptr @giggle_collect_intersection_data_in_block, ptr getelementptr inbounds (%struct.giggle_def, ptr @giggle_data_handler, i32 0, i32 11), align 8, !tbaa !11
  store ptr @leaf_data_map_intersection_to_offset_list, ptr getelementptr inbounds (%struct.giggle_def, ptr @giggle_data_handler, i32 0, i32 12), align 8, !tbaa !14
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.giggle_index, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 8, !tbaa !15
  %15 = zext i32 %14 to i64
  call void @UnityAssertEqualNumber(i64 noundef 24, i64 noundef %15, ptr noundef null, i64 noundef 1982, i32 noundef 148)
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.giggle_index, ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 4, !tbaa !18
  %19 = zext i32 %18 to i64
  call void @UnityAssertEqualNumber(i64 noundef 24, i64 noundef %19, ptr noundef null, i64 noundef 1983, i32 noundef 148)
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.giggle_index, ptr %20, i32 0, i32 4
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  %23 = getelementptr inbounds %struct.file_index, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !20
  %25 = getelementptr inbounds %struct.unordered_list, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !22
  %27 = zext i32 %26 to i64
  call void @UnityAssertEqualNumber(i64 noundef 22, i64 noundef %27, ptr noundef null, i64 noundef 1984, i32 noundef 148)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.giggle_index, ptr %28, i32 0, i32 3
  %30 = load ptr, ptr %29, align 8, !tbaa !24
  %31 = getelementptr inbounds %struct.chrm_index, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !25
  %33 = getelementptr inbounds %struct.ordered_set, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !27
  %35 = zext i32 %34 to i64
  call void @UnityAssertEqualNumber(i64 noundef 24, i64 noundef %35, ptr noundef null, i64 noundef 1985, i32 noundef 148)
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.giggle_index, ptr %36, i32 0, i32 5
  %38 = load ptr, ptr %37, align 8, !tbaa !29
  %39 = getelementptr inbounds %struct.offset_index, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !30
  %41 = getelementptr inbounds %struct.file_id_offset_pairs, ptr %40, i32 0, i32 0
  %42 = load i64, ptr %41, align 8, !tbaa !32
  call void @UnityAssertEqualNumber(i64 noundef 21024, i64 noundef %42, ptr noundef null, i64 noundef 1986, i32 noundef 148)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = call ptr @giggle_query(ptr noundef %43, ptr noundef @.str.8, i32 noundef 5000000, i32 noundef 6200000, ptr noundef %44)
  store ptr %45, ptr %5, align 8, !tbaa !5
  call void @giggle_index_destroy(ptr noundef %4)
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = call i32 @rmrf(ptr noundef %46)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 120}
!12 = !{!"giggle_def", !13, i64 0, !13, i64 24, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128}
!13 = !{!"cache_handler", !6, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!12, !6, i64 128}
!15 = !{!16, !17, i64 8}
!16 = !{!"giggle_index", !6, i64 0, !17, i64 8, !17, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!17 = !{!"int", !7, i64 0}
!18 = !{!16, !17, i64 12}
!19 = !{!16, !6, i64 24}
!20 = !{!21, !6, i64 8}
!21 = !{!"file_index", !6, i64 0, !6, i64 8}
!22 = !{!23, !17, i64 8}
!23 = !{!"unordered_list", !6, i64 0, !17, i64 8, !17, i64 12}
!24 = !{!16, !6, i64 16}
!25 = !{!26, !6, i64 8}
!26 = !{!"chrm_index", !6, i64 0, !6, i64 8}
!27 = !{!28, !17, i64 8}
!28 = !{!"ordered_set", !6, i64 0, !17, i64 8, !17, i64 12, !6, i64 16, !6, i64 24, !6, i64 32}
!29 = !{!16, !6, i64 32}
!30 = !{!31, !6, i64 0}
!31 = !{!"offset_index", !6, i64 0, !6, i64 8, !17, i64 16, !6, i64 24, !17, i64 32}
!32 = !{!33, !10, i64 0}
!33 = !{!"file_id_offset_pairs", !10, i64 0, !10, i64 8, !6, i64 16}


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

%struct.giggle_def = type { %struct.cache_handler, %struct.cache_handler, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.cache_handler = type { ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@giggle_data_handler = external dso_local local_unnamed_addr global %struct.giggle_def, align 8
@.str.8 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [28 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare void @UnityAssertEqualNumber(i64 noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i32 @rmrf(ptr noundef) local_unnamed_addr #1

declare void @giggle_index_destroy(ptr noundef) local_unnamed_addr #1

declare i64 @giggle_bulk_insert(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare ptr @giggle_load(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @uint64_t_ll_giggle_set_data_handler(...) #1

declare ptr @giggle_collect_intersection_data_in_block(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #1

declare void @leaf_data_map_intersection_to_offset_list(ptr noundef, ptr noundef, ptr noundef) #1

declare ptr @giggle_query(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @test_giggle_bulk_insert() local_unnamed_addr #2 {
  %1 = alloca ptr, align 8
  %2 = tail call i64 @giggle_bulk_insert(ptr noundef nonnull @.str, ptr noundef nonnull @.str.12, i32 noundef 1) #3
  tail call void @UnityAssertEqualNumber(i64 noundef 21024, i64 noundef %2, ptr noundef null, i64 noundef 1972, i32 noundef 148) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  %3 = tail call ptr @giggle_load(ptr noundef nonnull @.str.12, ptr noundef nonnull @uint64_t_ll_giggle_set_data_handler) #3
  store ptr %3, ptr %1, align 8, !tbaa !5
  store ptr @giggle_collect_intersection_data_in_block, ptr getelementptr inbounds (i8, ptr @giggle_data_handler, i64 120), align 8, !tbaa !9
  store ptr @leaf_data_map_intersection_to_offset_list, ptr getelementptr inbounds (i8, ptr @giggle_data_handler, i64 128), align 8, !tbaa !12
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !13
  %6 = zext i32 %5 to i64
  tail call void @UnityAssertEqualNumber(i64 noundef 24, i64 noundef %6, ptr noundef null, i64 noundef 1982, i32 noundef 148) #3
  %7 = getelementptr inbounds i8, ptr %3, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !16
  %9 = zext i32 %8 to i64
  tail call void @UnityAssertEqualNumber(i64 noundef 24, i64 noundef %9, ptr noundef null, i64 noundef 1983, i32 noundef 148) #3
  %10 = getelementptr inbounds i8, ptr %3, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !17
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !18
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !20
  %16 = zext i32 %15 to i64
  tail call void @UnityAssertEqualNumber(i64 noundef 22, i64 noundef %16, ptr noundef null, i64 noundef 1984, i32 noundef 148) #3
  %17 = getelementptr inbounds i8, ptr %3, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !22
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !23
  %21 = getelementptr inbounds i8, ptr %20, i64 8
  %22 = load i32, ptr %21, align 8, !tbaa !25
  %23 = zext i32 %22 to i64
  tail call void @UnityAssertEqualNumber(i64 noundef 24, i64 noundef %23, ptr noundef null, i64 noundef 1985, i32 noundef 148) #3
  %24 = getelementptr inbounds i8, ptr %3, i64 32
  %25 = load ptr, ptr %24, align 8, !tbaa !27
  %26 = load ptr, ptr %25, align 8, !tbaa !28
  %27 = load i64, ptr %26, align 8, !tbaa !30
  tail call void @UnityAssertEqualNumber(i64 noundef 21024, i64 noundef %27, ptr noundef null, i64 noundef 1986, i32 noundef 148) #3
  %28 = tail call ptr @giggle_query(ptr noundef %3, ptr noundef nonnull @.str.8, i32 noundef 5000000, i32 noundef 6200000, ptr noundef null) #3
  call void @giggle_index_destroy(ptr noundef nonnull %1) #3
  %29 = call i32 @rmrf(ptr noundef nonnull @.str.12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { 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/C++ TBAA"}
!9 = !{!10, !6, i64 120}
!10 = !{!"giggle_def", !11, i64 0, !11, i64 24, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128}
!11 = !{!"cache_handler", !6, i64 0, !6, i64 8, !6, i64 16}
!12 = !{!10, !6, i64 128}
!13 = !{!14, !15, i64 8}
!14 = !{!"giggle_index", !6, i64 0, !15, i64 8, !15, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!15 = !{!"int", !7, i64 0}
!16 = !{!14, !15, i64 12}
!17 = !{!14, !6, i64 24}
!18 = !{!19, !6, i64 8}
!19 = !{!"file_index", !6, i64 0, !6, i64 8}
!20 = !{!21, !15, i64 8}
!21 = !{!"unordered_list", !6, i64 0, !15, i64 8, !15, i64 12}
!22 = !{!14, !6, i64 16}
!23 = !{!24, !6, i64 8}
!24 = !{!"chrm_index", !6, i64 0, !6, i64 8}
!25 = !{!26, !15, i64 8}
!26 = !{!"ordered_set", !6, i64 0, !15, i64 8, !15, i64 12, !6, i64 16, !6, i64 24, !6, i64 32}
!27 = !{!14, !6, i64 32}
!28 = !{!29, !6, i64 0}
!29 = !{!"offset_index", !6, i64 0, !6, i64 8, !15, i64 16, !6, i64 24, !15, i64 32}
!30 = !{!31, !32, i64 0}
!31 = !{!"file_id_offset_pairs", !32, i64 0, !32, i64 8, !6, i64 16}
!32 = !{!"long", !7, i64 0}


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