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

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

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare void @store_copy(ptr noundef, i64 noundef, i64 noundef, i64 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare void @store_write_ui64(ptr noundef, i64 noundef, i64 noundef) #2

declare void @store_free(ptr noundef, i64 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @edges_remove(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) #3 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %4
  store i64 0, ptr %5, align 8
  br label %89

20:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 8, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 8, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = call i64 @store_read_ui64(ptr noundef %21, i64 noundef %22)
  store i64 %23, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %24 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %24, ptr %13, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %39, %20
  %26 = load i64, ptr %13, align 8, !tbaa !9
  %27 = load i64, ptr %12, align 8, !tbaa !9
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %29, label %43

29:                                               ; preds = %25
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = load i64, ptr %13, align 8, !tbaa !9
  %33 = add i64 %31, %32
  %34 = call i64 @store_read_ui64(ptr noundef %30, i64 noundef %33)
  %35 = load i64, ptr %9, align 8, !tbaa !9
  %36 = icmp eq i64 %34, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %29
  br label %43

38:                                               ; preds = %29
  br label %39

39:                                               ; preds = %38
  %40 = load i64, ptr %11, align 8, !tbaa !9
  %41 = load i64, ptr %13, align 8, !tbaa !9
  %42 = add i64 %41, %40
  store i64 %42, ptr %13, align 8, !tbaa !9
  br label %25, !llvm.loop !11

43:                                               ; preds = %37, %25
  %44 = load i64, ptr %13, align 8, !tbaa !9
  %45 = load i64, ptr %12, align 8, !tbaa !9
  %46 = icmp uge i64 %44, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %43
  %48 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %48, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %88

49:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %50 = load i64, ptr %12, align 8, !tbaa !9
  %51 = load i64, ptr %11, align 8, !tbaa !9
  %52 = sub i64 %50, %51
  store i64 %52, ptr %15, align 8, !tbaa !9
  %53 = load i64, ptr %15, align 8, !tbaa !9
  %54 = icmp slt i64 %53, 0
  br i1 %54, label %55, label %57

55:                                               ; preds = %49
  %56 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %56, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %87

57:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load i64, ptr %15, align 8, !tbaa !9
  %60 = call i64 @store_alloc(ptr noundef %58, i64 noundef %59)
  store i64 %60, ptr %16, align 8, !tbaa !9
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load i64, ptr %16, align 8, !tbaa !9
  %63 = load i64, ptr %7, align 8, !tbaa !9
  %64 = load i64, ptr %13, align 8, !tbaa !9
  call void @store_copy(ptr noundef %61, i64 noundef %62, i64 noundef %63, i64 noundef %64)
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load i64, ptr %16, align 8, !tbaa !9
  %67 = load i64, ptr %13, align 8, !tbaa !9
  %68 = add i64 %66, %67
  %69 = load i64, ptr %7, align 8, !tbaa !9
  %70 = load i64, ptr %13, align 8, !tbaa !9
  %71 = add i64 %69, %70
  %72 = load i64, ptr %11, align 8, !tbaa !9
  %73 = add i64 %71, %72
  %74 = load i64, ptr %12, align 8, !tbaa !9
  %75 = load i64, ptr %13, align 8, !tbaa !9
  %76 = sub i64 %74, %75
  %77 = load i64, ptr %11, align 8, !tbaa !9
  %78 = sub i64 %76, %77
  call void @store_copy(ptr noundef %65, i64 noundef %68, i64 noundef %73, i64 noundef %78)
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load i64, ptr %16, align 8, !tbaa !9
  %81 = load i64, ptr %12, align 8, !tbaa !9
  %82 = load i64, ptr %11, align 8, !tbaa !9
  %83 = sub i64 %81, %82
  call void @store_write_ui64(ptr noundef %79, i64 noundef %80, i64 noundef %83)
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = load i64, ptr %7, align 8, !tbaa !9
  call void @store_free(ptr noundef %84, i64 noundef %85)
  %86 = load i64, ptr %16, align 8, !tbaa !9
  store i64 %86, ptr %5, align 8
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  br label %87

87:                                               ; preds = %57, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %88

88:                                               ; preds = %87, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %89

89:                                               ; preds = %88, %19
  %90 = load i64, ptr %5, align 8
  ret i64 %90
}

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 = { 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 #3 = { 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 = distinct !{!11, !12}
!12 = !{!"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"

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

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

; Function Attrs: inlinehint nounwind uwtable
declare void @store_copy(ptr noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare void @store_write_ui64(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

declare void @store_free(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @edges_remove(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #2 {
  %5 = icmp eq i64 %1, 0
  br i1 %5, label %.loopexit, label %6

6:                                                ; preds = %4
  %7 = tail call i64 @store_read_ui64(ptr noundef %0, i64 noundef %1)
  %8 = icmp ugt i64 %7, 8
  br i1 %8, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %6, %12
  %.04146 = phi i64 [ %13, %12 ], [ 8, %6 ]
  %9 = add i64 %.04146, %1
  %10 = tail call i64 @store_read_ui64(ptr noundef %0, i64 noundef %9)
  %11 = icmp eq i64 %10, %3
  br i1 %11, label %15, label %12

12:                                               ; preds = %.lr.ph
  %13 = add i64 %.04146, 8
  %14 = icmp ult i64 %13, %7
  br i1 %14, label %.lr.ph, label %.loopexit, !llvm.loop !5

15:                                               ; preds = %.lr.ph
  %16 = add i64 %7, -8
  %17 = icmp slt i64 %16, 0
  br i1 %17, label %.loopexit, label %18

18:                                               ; preds = %15
  %19 = tail call i64 @store_alloc(ptr noundef %0, i64 noundef %16) #3
  tail call void @store_copy(ptr noundef %0, i64 noundef %19, i64 noundef %1, i64 noundef %.04146)
  %20 = add i64 %19, %.04146
  %21 = add i64 %1, 8
  %22 = add i64 %21, %.04146
  %23 = sub i64 %16, %.04146
  tail call void @store_copy(ptr noundef %0, i64 noundef %20, i64 noundef %22, i64 noundef %23)
  tail call void @store_write_ui64(ptr noundef %0, i64 noundef %19, i64 noundef %16)
  tail call void @store_free(ptr noundef %0, i64 noundef %1) #3
  br label %.loopexit

.loopexit:                                        ; preds = %12, %6, %15, %18, %4
  %.2 = phi i64 [ 0, %4 ], [ %19, %18 ], [ %1, %15 ], [ %1, %6 ], [ %1, %12 ]
  ret i64 %.2
}

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 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass