; LLVM IR from adventure-db/adventure :: src/db (adv)

; 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.adv_db = type { ptr, %struct.adv_meta, ptr, ptr }
%struct.adv_meta = type { [10 x i64], i64, i64, i64, i64, i64 }

@.str.8 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [2 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

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

declare i64 @nodes_edges_from(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @adv_debug_print(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %54, %1
  %9 = load i64, ptr %3, align 8, !tbaa !9
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.adv_db, ptr %10, i32 0, i32 2
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = call i64 @nodes_count(ptr noundef %12)
  %14 = icmp ult i64 %9, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %8
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %57

16:                                               ; preds = %8
  %17 = load i64, ptr %3, align 8, !tbaa !9
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, i64 noundef %17)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.adv_db, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = load i64, ptr %3, align 8, !tbaa !9
  %23 = call i64 @nodes_edges_from(ptr noundef %21, i64 noundef %22)
  store i64 %23, ptr %5, align 8, !tbaa !9
  %24 = load i64, ptr %5, align 8, !tbaa !9
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %52

26:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.adv_db, ptr %27, i32 0, i32 3
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = call i64 @store_read_ui64(ptr noundef %29, i64 noundef %30)
  store i64 %31, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = add i64 %32, 8
  store i64 %33, ptr %7, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %48, %26
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = load i64, ptr %6, align 8, !tbaa !9
  %38 = add i64 %36, %37
  %39 = icmp ult i64 %35, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %34
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %51

41:                                               ; preds = %34
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.adv_db, ptr %42, i32 0, i32 3
  %44 = load ptr, ptr %43, align 8, !tbaa !14
  %45 = load i64, ptr %7, align 8, !tbaa !9
  %46 = call i64 @store_read_ui64(ptr noundef %44, i64 noundef %45)
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, i64 noundef %46)
  br label %48

48:                                               ; preds = %41
  %49 = load i64, ptr %7, align 8, !tbaa !9
  %50 = add i64 %49, 8
  store i64 %50, ptr %7, align 8, !tbaa !9
  br label %34, !llvm.loop !15

51:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %52

52:                                               ; preds = %51, %16
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %54

54:                                               ; preds = %52
  %55 = load i64, ptr %3, align 8, !tbaa !9
  %56 = add i64 %55, 1
  store i64 %56, ptr %3, align 8, !tbaa !9
  br label %8, !llvm.loop !17

57:                                               ; preds = %15
  ret void
}

declare i64 @nodes_count(ptr noundef) #1

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: inlinehint nounwind uwtable
declare i64 @store_read_ui64(ptr noundef, i64 noundef) #3

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 = { inlinehint 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 #4 = { 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 128}
!12 = !{!"adv_db", !6, i64 0, !13, i64 8, !6, i64 128, !6, i64 136}
!13 = !{!"adv_meta", !7, i64 0, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112}
!14 = !{!12, !6, i64 136}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !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"

@.str.8 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [2 x i8], align 1

declare i64 @nodes_edges_from(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @adv_debug_print(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 128
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = tail call i64 @nodes_count(ptr noundef %3) #4
  %.not21 = icmp eq i64 %4, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph20

.lr.ph20:                                         ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 136
  br label %6

._crit_edge:                                      ; preds = %.loopexit, %1
  ret void

6:                                                ; preds = %.lr.ph20, %.loopexit
  %.01519 = phi i64 [ 0, %.lr.ph20 ], [ %20, %.loopexit ]
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, i64 noundef %.01519)
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = tail call i64 @nodes_edges_from(ptr noundef %8, i64 noundef %.01519) #4
  %.not = icmp eq i64 %9, 0
  br i1 %.not, label %.loopexit, label %10

10:                                               ; preds = %6
  %11 = load ptr, ptr %5, align 8, !tbaa !12
  %12 = tail call i64 @store_read_ui64(ptr noundef %11, i64 noundef %9)
  %13 = add i64 %12, %9
  %.017 = add i64 %9, 8
  %14 = icmp ult i64 %.017, %13
  br i1 %14, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %10, %.lr.ph
  %.018 = phi i64 [ %.0, %.lr.ph ], [ %.017, %10 ]
  %15 = load ptr, ptr %5, align 8, !tbaa !12
  %16 = tail call i64 @store_read_ui64(ptr noundef %15, i64 noundef %.018)
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, i64 noundef %16)
  %.0 = add i64 %.018, 8
  %18 = icmp ult i64 %.0, %13
  br i1 %18, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph, %10, %6
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  %20 = add nuw i64 %.01519, 1
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = tail call i64 @nodes_count(ptr noundef %21) #4
  %23 = icmp ult i64 %20, %22
  br i1 %23, label %6, label %._crit_edge, !llvm.loop !15
}

declare i64 @nodes_count(ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare i64 @store_read_ui64(ptr noundef, i64 noundef) local_unnamed_addr #3

attributes #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 = { 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 #2 = { 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 #3 = { inlinehint 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 #4 = { 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, !7, i64 128}
!6 = !{!"adv_db", !7, i64 0, !10, i64 8, !7, i64 128, !7, i64 136}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"adv_meta", !8, i64 0, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !7, i64 136}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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