; LLVM IR from ryanlayer/giggle :: src (ll)

; 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.file_id_offset_pair = type { i32, i64 }
%struct.uint64_t_ll = type { i64, ptr, ptr }
%struct.giggle_index = type { ptr, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.uint64_t_ll_node = type { i64, ptr }
%struct.giggle_query_result = type { ptr, i32, ptr, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @uint64_t_ll_map_intersection_to_offset_list(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %struct.file_id_offset_pair, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %10, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %48

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.uint64_t_ll, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %8, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %20, %13
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %47

20:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #3
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.giggle_index, ptr %21, i32 0, i32 5
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.uint64_t_ll_node, ptr %24, i32 0, i32 0
  %26 = load i64, ptr %25, align 8, !tbaa !15
  %27 = call { i32, i64 } @offset_index_get(ptr noundef %23, i64 noundef %26)
  %28 = getelementptr inbounds { i32, i64 }, ptr %9, i32 0, i32 0
  %29 = extractvalue { i32, i64 } %27, 0
  store i32 %29, ptr %28, align 8
  %30 = getelementptr inbounds { i32, i64 }, ptr %9, i32 0, i32 1
  %31 = extractvalue { i32, i64 } %27, 1
  store i64 %31, ptr %30, align 8
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.giggle_query_result, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = getelementptr inbounds %struct.file_id_offset_pair, ptr %9, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !19
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds ptr, ptr %34, i64 %37
  %39 = getelementptr inbounds %struct.file_id_offset_pair, ptr %9, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !21
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.uint64_t_ll_node, ptr %41, i32 0, i32 0
  %43 = load i64, ptr %42, align 8, !tbaa !15
  call void @long_uint_ll_append(ptr noundef %38, i64 noundef %40, i64 noundef %43)
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.uint64_t_ll_node, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !22
  store ptr %46, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #3
  br label %17, !llvm.loop !23

47:                                               ; preds = %17
  call void @uint64_t_ll_free(ptr noundef %7)
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %48

48:                                               ; preds = %47, %3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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

declare { i32, i64 } @offset_index_get(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @long_uint_ll_append(ptr noundef, i64 noundef, i64 noundef) #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @uint64_t_ll_free(ptr noundef) #0

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 8}
!10 = !{!"uint64_t_ll", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 32}
!13 = !{!"giggle_index", !6, i64 0, !14, i64 8, !14, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !11, i64 0}
!16 = !{!"uint64_t_ll_node", !11, i64 0, !6, i64 8}
!17 = !{!18, !6, i64 16}
!18 = !{!"giggle_query_result", !6, i64 0, !14, i64 8, !6, i64 16, !14, i64 24}
!19 = !{!20, !14, i64 0}
!20 = !{!"file_id_offset_pair", !14, i64 0, !11, i64 8}
!21 = !{!20, !11, i64 8}
!22 = !{!16, !6, i64 8}
!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: nounwind uwtable
define dso_local void @uint64_t_ll_map_intersection_to_offset_list(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store ptr %2, ptr %4, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %17, label %.preheader

.preheader:                                       ; preds = %3
  %.0.in10 = getelementptr inbounds i8, ptr %2, i64 8
  %.011 = load ptr, ptr %.0.in10, align 8, !tbaa !5
  %.not912 = icmp eq ptr %.011, null
  br i1 %.not912, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  br label %7

7:                                                ; preds = %.lr.ph, %7
  %.013 = phi ptr [ %.011, %.lr.ph ], [ %.0, %7 ]
  %8 = load ptr, ptr %5, align 8, !tbaa !9
  %9 = load i64, ptr %.013, align 8, !tbaa !12
  %10 = tail call { i32, i64 } @offset_index_get(ptr noundef %8, i64 noundef %9) #3
  %11 = extractvalue { i32, i64 } %10, 0
  %12 = extractvalue { i32, i64 } %10, 1
  %13 = load ptr, ptr %6, align 8, !tbaa !15
  %14 = zext i32 %11 to i64
  %15 = getelementptr inbounds ptr, ptr %13, i64 %14
  %16 = load i64, ptr %.013, align 8, !tbaa !12
  tail call void @long_uint_ll_append(ptr noundef %15, i64 noundef %12, i64 noundef %16)
  %.0.in = getelementptr inbounds i8, ptr %.013, i64 8
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not9 = icmp eq ptr %.0, null
  br i1 %.not9, label %._crit_edge, label %7, !llvm.loop !17

._crit_edge:                                      ; preds = %7, %.preheader
  call void @uint64_t_ll_free(ptr noundef nonnull %4)
  br label %17

17:                                               ; preds = %._crit_edge, %3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret void
}

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

declare { i32, i64 } @offset_index_get(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @long_uint_ll_append(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @uint64_t_ll_free(ptr noundef) local_unnamed_addr #0

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 32}
!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 = !{!13, !14, i64 0}
!13 = !{!"uint64_t_ll_node", !14, i64 0, !6, i64 8}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !6, i64 16}
!16 = !{!"giggle_query_result", !6, i64 0, !11, i64 8, !6, i64 16, !11, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass