; 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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }
%struct.giggle_index = type { ptr, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.pri_queue_t = type { ptr, i32, i32 }
%struct.offset_index = type { ptr, ptr, i32, ptr, i32 }
%struct.file_id_offset_pairs = type { i64, i64, ptr }
%struct.chrm_index = type { ptr, ptr }
%struct.ordered_set = type { ptr, i32, i32, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@OFFSET_INDEX_FILE_NAME = external dso_local global ptr, align 8
@CHRM_INDEX_FILE_NAME = external dso_local global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [46 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 i32 @giggle_bulk_insert_open_files(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

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

declare void @input_file_destroy(ptr noundef) #1

declare void @file_index_destroy(ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind
declare i32 @stat(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @mkdir(ptr noundef, i32 noundef) #2

declare i32 @rmrf(ptr noundef) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @asprintf(ptr noundef, ptr noundef, ...) #2

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

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

declare ptr @priq_new(i32 noundef) #1

declare void @giggle_bulk_insert_prime_pqs(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

declare void @priq_free(ptr noundef) #1

declare void @offset_index_destroy(ptr noundef) #1

declare void @chrm_index_destroy(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @test_giggle_bulk_insert_build_leaf_levels() #5 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca %struct.stat, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #6
  store ptr @.str, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  store ptr @.str.3, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 144, ptr %3) #6
  call void @llvm.memset.p0.i64(ptr align 8 %3, i8 0, i64 144, i1 false)
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = call i32 @stat(ptr noundef %14, ptr noundef %3) #6
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %17, label %20

17:                                               ; preds = %0
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = call i32 @mkdir(ptr noundef %18, i32 noundef 448) #6
  br label %25

20:                                               ; preds = %0
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = call i32 @rmrf(ptr noundef %21)
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = call i32 @mkdir(ptr noundef %23, i32 noundef 448) #6
  br label %25

25:                                               ; preds = %20, %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %26 = call noalias ptr @malloc(i64 noundef 64) #7
  store ptr %26, ptr %4, align 8, !tbaa !5
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = call noalias ptr @strdup(ptr noundef %27) #6
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.giggle_index, ptr %29, i32 0, i32 7
  store ptr %28, ptr %30, align 8, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.giggle_index, ptr %31, i32 0, i32 4
  store ptr null, ptr %32, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %33 = load ptr, ptr %1, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.giggle_index, ptr %34, i32 0, i32 7
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.giggle_index, ptr %37, i32 0, i32 4
  %39 = call i32 @giggle_bulk_insert_open_files(ptr noundef %33, ptr noundef %36, ptr noundef %5, ptr noundef %38)
  store i32 %39, ptr %6, align 4, !tbaa !13
  %40 = load i32, ptr %6, align 4, !tbaa !13
  %41 = zext i32 %40 to i64
  call void @UnityAssertEqualNumber(i64 noundef 22, i64 noundef %41, ptr noundef null, i64 noundef 913, i32 noundef 148)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.giggle_index, ptr %42, i32 0, i32 7
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = load ptr, ptr @OFFSET_INDEX_FILE_NAME, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef %7, ptr noundef @.str.2, ptr noundef %44, ptr noundef %45) #6
  store i32 %46, ptr %8, align 4, !tbaa !13
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = call ptr @offset_index_init(i32 noundef 1000, ptr noundef %47)
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.giggle_index, ptr %49, i32 0, i32 5
  store ptr %48, ptr %50, align 8, !tbaa !14
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %51) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  store ptr null, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.giggle_index, ptr %52, i32 0, i32 7
  %54 = load ptr, ptr %53, align 8, !tbaa !9
  %55 = load ptr, ptr @CHRM_INDEX_FILE_NAME, align 8, !tbaa !5
  %56 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef %9, ptr noundef @.str.2, ptr noundef %54, ptr noundef %55) #6
  store i32 %56, ptr %8, align 4, !tbaa !13
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = call ptr @chrm_index_init(i32 noundef 24, ptr noundef %57)
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.giggle_index, ptr %59, i32 0, i32 3
  store ptr %58, ptr %60, align 8, !tbaa !15
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %61) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %62 = load i32, ptr %6, align 4, !tbaa !13
  %63 = call ptr @priq_new(i32 noundef %62)
  store ptr %63, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %64 = load i32, ptr %6, align 4, !tbaa !13
  %65 = zext i32 %64 to i64
  %66 = mul i64 %65, 16
  %67 = call noalias ptr @malloc(i64 noundef %66) #7
  store ptr %67, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %68 = load i32, ptr %6, align 4, !tbaa !13
  %69 = call ptr @priq_new(i32 noundef %68)
  store ptr %69, ptr %12, align 8, !tbaa !5
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = load i32, ptr %6, align 4, !tbaa !13
  call void @giggle_bulk_insert_prime_pqs(ptr noundef %70, ptr noundef %10, ptr noundef %71, ptr noundef %12, ptr noundef %72, i32 noundef %73)
  %74 = load i32, ptr %6, align 4, !tbaa !13
  %75 = zext i32 %74 to i64
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.pri_queue_t, ptr %76, i32 0, i32 1
  %78 = load i32, ptr %77, align 8, !tbaa !16
  %79 = sub nsw i32 %78, 1
  %80 = sext i32 %79 to i64
  call void @UnityAssertEqualNumber(i64 noundef %75, i64 noundef %80, ptr noundef null, i64 noundef 950, i32 noundef 148)
  %81 = load i32, ptr %6, align 4, !tbaa !13
  %82 = zext i32 %81 to i64
  %83 = load ptr, ptr %12, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.pri_queue_t, ptr %83, i32 0, i32 1
  %85 = load i32, ptr %84, align 8, !tbaa !16
  %86 = sub nsw i32 %85, 1
  %87 = sext i32 %86 to i64
  call void @UnityAssertEqualNumber(i64 noundef %82, i64 noundef %87, ptr noundef null, i64 noundef 951, i32 noundef 148)
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = load ptr, ptr %11, align 8, !tbaa !5
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = load i32, ptr %6, align 4, !tbaa !13
  call void @giggle_bulk_insert_build_leaf_levels(ptr noundef %88, ptr noundef %10, ptr noundef %89, ptr noundef %12, ptr noundef %90, i32 noundef %91)
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.giggle_index, ptr %92, i32 0, i32 5
  %94 = load ptr, ptr %93, align 8, !tbaa !14
  %95 = getelementptr inbounds %struct.offset_index, ptr %94, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8, !tbaa !18
  %97 = getelementptr inbounds %struct.file_id_offset_pairs, ptr %96, i32 0, i32 0
  %98 = load i64, ptr %97, align 8, !tbaa !20
  call void @UnityAssertEqualNumber(i64 noundef 21024, i64 noundef %98, ptr noundef null, i64 noundef 960, i32 noundef 148)
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.giggle_index, ptr %99, i32 0, i32 3
  %101 = load ptr, ptr %100, align 8, !tbaa !15
  %102 = getelementptr inbounds %struct.chrm_index, ptr %101, i32 0, i32 1
  %103 = load ptr, ptr %102, align 8, !tbaa !23
  %104 = getelementptr inbounds %struct.ordered_set, ptr %103, i32 0, i32 1
  %105 = load i32, ptr %104, align 8, !tbaa !25
  %106 = zext i32 %105 to i64
  call void @UnityAssertEqualNumber(i64 noundef 24, i64 noundef %106, ptr noundef null, i64 noundef 961, i32 noundef 148)
  %107 = load ptr, ptr %10, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.pri_queue_t, ptr %107, i32 0, i32 1
  %109 = load i32, ptr %108, align 8, !tbaa !16
  %110 = sub nsw i32 %109, 1
  %111 = sext i32 %110 to i64
  call void @UnityAssertEqualNumber(i64 noundef 0, i64 noundef %111, ptr noundef null, i64 noundef 963, i32 noundef 148)
  %112 = load ptr, ptr %12, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.pri_queue_t, ptr %112, i32 0, i32 1
  %114 = load i32, ptr %113, align 8, !tbaa !16
  %115 = sub nsw i32 %114, 1
  %116 = sext i32 %115 to i64
  call void @UnityAssertEqualNumber(i64 noundef 0, i64 noundef %116, ptr noundef null, i64 noundef 964, i32 noundef 148)
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  store i32 0, ptr %13, align 4, !tbaa !13
  br label %117

117:                                              ; preds = %126, %25
  %118 = load i32, ptr %13, align 4, !tbaa !13
  %119 = load i32, ptr %6, align 4, !tbaa !13
  %120 = icmp ult i32 %118, %119
  br i1 %120, label %121, label %129

121:                                              ; preds = %117
  %122 = load ptr, ptr %5, align 8, !tbaa !5
  %123 = load i32, ptr %13, align 4, !tbaa !13
  %124 = zext i32 %123 to i64
  %125 = getelementptr inbounds ptr, ptr %122, i64 %124
  call void @input_file_destroy(ptr noundef %125)
  br label %126

126:                                              ; preds = %121
  %127 = load i32, ptr %13, align 4, !tbaa !13
  %128 = add i32 %127, 1
  store i32 %128, ptr %13, align 4, !tbaa !13
  br label %117, !llvm.loop !27

129:                                              ; preds = %117
  %130 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %130) #6
  %131 = load ptr, ptr %11, align 8, !tbaa !5
  call void @free(ptr noundef %131) #6
  %132 = load ptr, ptr %10, align 8, !tbaa !5
  call void @priq_free(ptr noundef %132)
  %133 = load ptr, ptr %12, align 8, !tbaa !5
  call void @priq_free(ptr noundef %133)
  %134 = load ptr, ptr %4, align 8, !tbaa !5
  %135 = getelementptr inbounds %struct.giggle_index, ptr %134, i32 0, i32 7
  %136 = load ptr, ptr %135, align 8, !tbaa !9
  call void @free(ptr noundef %136) #6
  %137 = load ptr, ptr %4, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.giggle_index, ptr %137, i32 0, i32 4
  call void @file_index_destroy(ptr noundef %138)
  %139 = load ptr, ptr %4, align 8, !tbaa !5
  %140 = getelementptr inbounds %struct.giggle_index, ptr %139, i32 0, i32 5
  call void @offset_index_destroy(ptr noundef %140)
  %141 = load ptr, ptr %4, align 8, !tbaa !5
  %142 = getelementptr inbounds %struct.giggle_index, ptr %141, i32 0, i32 3
  call void @chrm_index_destroy(ptr noundef %142)
  %143 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %143) #6
  %144 = load ptr, ptr %2, align 8, !tbaa !5
  %145 = call i32 @rmrf(ptr noundef %144)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 144, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #6
  ret void
}

declare void @giggle_bulk_insert_build_leaf_levels(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

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 "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind allocsize(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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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 48}
!10 = !{!"giggle_index", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 24}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 32}
!15 = !{!10, !6, i64 16}
!16 = !{!17, !11, i64 8}
!17 = !{!"", !6, i64 0, !11, i64 8, !11, i64 12}
!18 = !{!19, !6, i64 0}
!19 = !{!"offset_index", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !11, i64 32}
!20 = !{!21, !22, i64 0}
!21 = !{!"file_id_offset_pairs", !22, i64 0, !22, i64 8, !6, i64 16}
!22 = !{!"long", !7, i64 0}
!23 = !{!24, !6, i64 8}
!24 = !{!"chrm_index", !6, i64 0, !6, i64 8}
!25 = !{!26, !11, i64 8}
!26 = !{!"ordered_set", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32}
!27 = distinct !{!27, !28}
!28 = !{!"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"

%struct.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@OFFSET_INDEX_FILE_NAME = external dso_local local_unnamed_addr global ptr, align 8
@CHRM_INDEX_FILE_NAME = external dso_local local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [46 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 i32 @giggle_bulk_insert_open_files(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

declare void @input_file_destroy(ptr noundef) local_unnamed_addr #1

declare void @file_index_destroy(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nofree nounwind
declare noundef i32 @stat(ptr nocapture noundef readonly, ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @mkdir(ptr nocapture noundef readonly, i32 noundef) local_unnamed_addr #4

declare i32 @rmrf(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #5

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #6

; Function Attrs: nounwind
declare i32 @asprintf(ptr noundef, ptr noundef, ...) local_unnamed_addr #7

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

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

declare ptr @priq_new(i32 noundef) local_unnamed_addr #1

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

declare void @priq_free(ptr noundef) local_unnamed_addr #1

declare void @offset_index_destroy(ptr noundef) local_unnamed_addr #1

declare void @chrm_index_destroy(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @test_giggle_bulk_insert_build_leaf_levels() local_unnamed_addr #8 {
  %1 = alloca %struct.stat, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %1) #9
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(144) %1, i8 0, i64 144, i1 false)
  %7 = call i32 @stat(ptr noundef nonnull @.str.3, ptr noundef nonnull %1) #9
  %8 = icmp eq i32 %7, -1
  br i1 %8, label %11, label %9

9:                                                ; preds = %0
  %10 = tail call i32 @rmrf(ptr noundef nonnull @.str.3) #9
  br label %11

11:                                               ; preds = %0, %9
  %12 = tail call i32 @mkdir(ptr noundef nonnull @.str.3, i32 noundef 448) #9
  %13 = tail call noalias dereferenceable_or_null(64) ptr @malloc(i64 noundef 64) #10
  %14 = tail call noalias ptr @strdup(ptr noundef nonnull @.str.3) #9
  %15 = getelementptr inbounds i8, ptr %13, i64 48
  store ptr %14, ptr %15, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %13, i64 24
  store ptr null, ptr %16, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #9
  store ptr null, ptr %2, align 8, !tbaa !12
  %17 = call i32 @giggle_bulk_insert_open_files(ptr noundef nonnull @.str, ptr noundef %14, ptr noundef nonnull %2, ptr noundef nonnull %16) #9
  %18 = zext i32 %17 to i64
  call void @UnityAssertEqualNumber(i64 noundef 22, i64 noundef %18, ptr noundef null, i64 noundef 913, i32 noundef 148) #9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #9
  store ptr null, ptr %3, align 8, !tbaa !12
  %19 = load ptr, ptr %15, align 8, !tbaa !5
  %20 = load ptr, ptr @OFFSET_INDEX_FILE_NAME, align 8, !tbaa !12
  %21 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.2, ptr noundef %19, ptr noundef %20) #9
  %22 = load ptr, ptr %3, align 8, !tbaa !12
  %23 = call ptr @offset_index_init(i32 noundef 1000, ptr noundef %22) #9
  %24 = getelementptr inbounds i8, ptr %13, i64 32
  store ptr %23, ptr %24, align 8, !tbaa !13
  %25 = load ptr, ptr %3, align 8, !tbaa !12
  call void @free(ptr noundef %25) #9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #9
  store ptr null, ptr %4, align 8, !tbaa !12
  %26 = load ptr, ptr %15, align 8, !tbaa !5
  %27 = load ptr, ptr @CHRM_INDEX_FILE_NAME, align 8, !tbaa !12
  %28 = call i32 (ptr, ptr, ...) @asprintf(ptr noundef nonnull %4, ptr noundef nonnull @.str.2, ptr noundef %26, ptr noundef %27) #9
  %29 = load ptr, ptr %4, align 8, !tbaa !12
  %30 = call ptr @chrm_index_init(i32 noundef 24, ptr noundef %29) #9
  %31 = getelementptr inbounds i8, ptr %13, i64 16
  store ptr %30, ptr %31, align 8, !tbaa !14
  %32 = load ptr, ptr %4, align 8, !tbaa !12
  call void @free(ptr noundef %32) #9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #9
  %33 = call ptr @priq_new(i32 noundef %17) #9
  store ptr %33, ptr %5, align 8, !tbaa !12
  %34 = shl nuw nsw i64 %18, 4
  %35 = call noalias ptr @malloc(i64 noundef %34) #10
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #9
  %36 = call ptr @priq_new(i32 noundef %17) #9
  store ptr %36, ptr %6, align 8, !tbaa !12
  %37 = load ptr, ptr %2, align 8, !tbaa !12
  call void @giggle_bulk_insert_prime_pqs(ptr noundef %13, ptr noundef nonnull %5, ptr noundef %35, ptr noundef nonnull %6, ptr noundef %37, i32 noundef %17) #9
  %38 = load ptr, ptr %5, align 8, !tbaa !12
  %39 = getelementptr inbounds i8, ptr %38, i64 8
  %40 = load i32, ptr %39, align 8, !tbaa !15
  %41 = add nsw i32 %40, -1
  %42 = sext i32 %41 to i64
  call void @UnityAssertEqualNumber(i64 noundef %18, i64 noundef %42, ptr noundef null, i64 noundef 950, i32 noundef 148) #9
  %43 = load ptr, ptr %6, align 8, !tbaa !12
  %44 = getelementptr inbounds i8, ptr %43, i64 8
  %45 = load i32, ptr %44, align 8, !tbaa !15
  %46 = add nsw i32 %45, -1
  %47 = sext i32 %46 to i64
  call void @UnityAssertEqualNumber(i64 noundef %18, i64 noundef %47, ptr noundef null, i64 noundef 951, i32 noundef 148) #9
  %48 = load ptr, ptr %2, align 8, !tbaa !12
  call void @giggle_bulk_insert_build_leaf_levels(ptr noundef %13, ptr noundef nonnull %5, ptr noundef %35, ptr noundef nonnull %6, ptr noundef %48, i32 noundef %17) #9
  %49 = load ptr, ptr %24, align 8, !tbaa !13
  %50 = load ptr, ptr %49, align 8, !tbaa !17
  %51 = load i64, ptr %50, align 8, !tbaa !19
  call void @UnityAssertEqualNumber(i64 noundef 21024, i64 noundef %51, ptr noundef null, i64 noundef 960, i32 noundef 148) #9
  %52 = load ptr, ptr %31, align 8, !tbaa !14
  %53 = getelementptr inbounds i8, ptr %52, i64 8
  %54 = load ptr, ptr %53, align 8, !tbaa !22
  %55 = getelementptr inbounds i8, ptr %54, i64 8
  %56 = load i32, ptr %55, align 8, !tbaa !24
  %57 = zext i32 %56 to i64
  call void @UnityAssertEqualNumber(i64 noundef 24, i64 noundef %57, ptr noundef null, i64 noundef 961, i32 noundef 148) #9
  %58 = load ptr, ptr %5, align 8, !tbaa !12
  %59 = getelementptr inbounds i8, ptr %58, i64 8
  %60 = load i32, ptr %59, align 8, !tbaa !15
  %61 = add nsw i32 %60, -1
  %62 = sext i32 %61 to i64
  call void @UnityAssertEqualNumber(i64 noundef 0, i64 noundef %62, ptr noundef null, i64 noundef 963, i32 noundef 148) #9
  %63 = load ptr, ptr %6, align 8, !tbaa !12
  %64 = getelementptr inbounds i8, ptr %63, i64 8
  %65 = load i32, ptr %64, align 8, !tbaa !15
  %66 = add nsw i32 %65, -1
  %67 = sext i32 %66 to i64
  call void @UnityAssertEqualNumber(i64 noundef 0, i64 noundef %67, ptr noundef null, i64 noundef 964, i32 noundef 148) #9
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %11 ]
  %68 = load ptr, ptr %2, align 8, !tbaa !12
  %69 = getelementptr inbounds ptr, ptr %68, i64 %indvars.iv
  call void @input_file_destroy(ptr noundef %69) #9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %18
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !26

._crit_edge:                                      ; preds = %.lr.ph, %11
  %70 = load ptr, ptr %2, align 8, !tbaa !12
  call void @free(ptr noundef %70) #9
  call void @free(ptr noundef %35) #9
  %71 = load ptr, ptr %5, align 8, !tbaa !12
  call void @priq_free(ptr noundef %71) #9
  %72 = load ptr, ptr %6, align 8, !tbaa !12
  call void @priq_free(ptr noundef %72) #9
  %73 = load ptr, ptr %15, align 8, !tbaa !5
  call void @free(ptr noundef %73) #9
  call void @file_index_destroy(ptr noundef nonnull %16) #9
  call void @offset_index_destroy(ptr noundef nonnull %24) #9
  call void @chrm_index_destroy(ptr noundef nonnull %31) #9
  call void @free(ptr noundef %13) #9
  %74 = call i32 @rmrf(ptr noundef nonnull @.str.3) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #9
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %1) #9
  ret void
}

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

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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nofree nounwind "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 #5 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #6 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #7 = { nounwind "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 #8 = { 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 #9 = { nounwind }
attributes #10 = { nounwind allocsize(0) }

!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, !7, i64 48}
!6 = !{!"giggle_index", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 24}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !7, i64 32}
!14 = !{!6, !7, i64 16}
!15 = !{!16, !10, i64 8}
!16 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12}
!17 = !{!18, !7, i64 0}
!18 = !{!"offset_index", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !10, i64 32}
!19 = !{!20, !21, i64 0}
!20 = !{!"file_id_offset_pairs", !21, i64 0, !21, i64 8, !7, i64 16}
!21 = !{!"long", !8, i64 0}
!22 = !{!23, !7, i64 8}
!23 = !{!"chrm_index", !7, i64 0, !7, i64 8}
!24 = !{!25, !10, i64 8}
!25 = !{!"ordered_set", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 24, !7, i64 32}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass