; LLVM IR from erthink/libmdbx :: test/extra/pcrf (pcrf_test)

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

@opt_db_path = external dso_local global [4096 x i8], align 16
@obj_id = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [4096 x i8], align 16
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4096, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %18 = getelementptr inbounds [4096 x i8], ptr %6, i64 0, i64 0
  %19 = call ptr @strcpy(ptr noundef %18, ptr noundef @opt_db_path) #5
  %20 = getelementptr inbounds [4096 x i8], ptr %6, i64 0, i64 0
  %21 = call ptr @strcat(ptr noundef %20, ptr noundef @.str) #5
  %22 = getelementptr inbounds [4096 x i8], ptr %6, i64 0, i64 0
  %23 = call i32 @remove(ptr noundef %22) #5
  %24 = getelementptr inbounds [4096 x i8], ptr %6, i64 0, i64 0
  %25 = call ptr @strcpy(ptr noundef %24, ptr noundef @opt_db_path) #5
  %26 = getelementptr inbounds [4096 x i8], ptr %6, i64 0, i64 0
  %27 = call ptr @strcat(ptr noundef %26, ptr noundef @.str.1) #5
  %28 = getelementptr inbounds [4096 x i8], ptr %6, i64 0, i64 0
  %29 = call i32 @remove(ptr noundef %28) #5
  %30 = call i32 @puts(ptr noundef @.str.2)
  call void @db_connect()
  %31 = call i32 @puts(ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %32 = call i64 @getClockUs()
  store i64 %32, ptr %8, align 8, !tbaa !11
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %54, %2
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = icmp slt i32 %34, 10240000
  br i1 %35, label %36, label %57

36:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %37 = load i64, ptr @obj_id, align 8, !tbaa !11
  %38 = add nsw i64 %37, 1
  store i64 %38, ptr @obj_id, align 8, !tbaa !11
  store i64 %37, ptr %9, align 8, !tbaa !11
  %39 = load i64, ptr %9, align 8, !tbaa !11
  call void @create_record(i64 noundef %39)
  %40 = load i64, ptr %9, align 8, !tbaa !11
  call void @add_id_to_pool(i64 noundef %40)
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = srem i32 %41, 1000
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %53

44:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %45 = call i64 @getClockUs()
  store i64 %45, ptr %10, align 8, !tbaa !11
  %46 = load i64, ptr %10, align 8, !tbaa !11
  %47 = load i64, ptr %8, align 8, !tbaa !11
  %48 = sub nsw i64 %46, %47
  %49 = icmp sgt i64 %48, 1000000
  br i1 %49, label %50, label %52

50:                                               ; preds = %44
  call void @periodic_stat()
  %51 = load i64, ptr %10, align 8, !tbaa !11
  store i64 %51, ptr %8, align 8, !tbaa !11
  br label %52

52:                                               ; preds = %50, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %53

53:                                               ; preds = %52, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %7, align 4, !tbaa !5
  br label %33, !llvm.loop !13

57:                                               ; preds = %33
  call void @periodic_stat()
  br label %58

58:                                               ; preds = %97, %57
  br label %59

59:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %70, %59
  %61 = load i32, ptr %11, align 4, !tbaa !5
  %62 = icmp slt i32 %61, 1000
  br i1 %62, label %63, label %73

63:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %64 = load i64, ptr @obj_id, align 8, !tbaa !11
  %65 = add nsw i64 %64, 1
  store i64 %65, ptr @obj_id, align 8, !tbaa !11
  store i64 %64, ptr %12, align 8, !tbaa !11
  %66 = load i64, ptr %12, align 8, !tbaa !11
  call void @create_record(i64 noundef %66)
  %67 = load i64, ptr %12, align 8, !tbaa !11
  call void @add_id_to_pool(i64 noundef %67)
  %68 = call i64 @get_id_from_pool()
  store i64 %68, ptr %12, align 8, !tbaa !11
  %69 = load i64, ptr %12, align 8, !tbaa !11
  call void @delete_record(i64 noundef %69)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %70

70:                                               ; preds = %63
  %71 = load i32, ptr %11, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %11, align 4, !tbaa !5
  br label %60, !llvm.loop !15

73:                                               ; preds = %60
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %82, %73
  %75 = load i32, ptr %11, align 4, !tbaa !5
  %76 = icmp slt i32 %75, 50
  br i1 %76, label %77, label %85

77:                                               ; preds = %74
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %78 = load i64, ptr @obj_id, align 8, !tbaa !11
  %79 = add nsw i64 %78, 1
  store i64 %79, ptr @obj_id, align 8, !tbaa !11
  store i64 %78, ptr %13, align 8, !tbaa !11
  %80 = load i64, ptr %13, align 8, !tbaa !11
  call void @create_record(i64 noundef %80)
  %81 = load i64, ptr %13, align 8, !tbaa !11
  call void @add_id_to_pool(i64 noundef %81)
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %82

82:                                               ; preds = %77
  %83 = load i32, ptr %11, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %11, align 4, !tbaa !5
  br label %74, !llvm.loop !16

85:                                               ; preds = %74
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %86 = load i64, ptr @obj_id, align 8, !tbaa !11
  %87 = add nsw i64 %86, 1
  store i64 %87, ptr @obj_id, align 8, !tbaa !11
  store i64 %86, ptr %14, align 8, !tbaa !11
  %88 = load i64, ptr %14, align 8, !tbaa !11
  call void @create_record(i64 noundef %88)
  %89 = load i64, ptr %14, align 8, !tbaa !11
  call void @add_id_to_pool(i64 noundef %89)
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %90 = call i64 @getClockUs()
  store i64 %90, ptr %15, align 8, !tbaa !11
  %91 = load i64, ptr %15, align 8, !tbaa !11
  %92 = load i64, ptr %8, align 8, !tbaa !11
  %93 = sub nsw i64 %91, %92
  %94 = icmp sgt i64 %93, 10000000
  br i1 %94, label %95, label %97

95:                                               ; preds = %85
  call void @periodic_stat()
  %96 = load i64, ptr %15, align 8, !tbaa !11
  store i64 %96, ptr %8, align 8, !tbaa !11
  br label %97

97:                                               ; preds = %95, %85
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %58
}

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

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

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

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

declare i32 @puts(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @getClockUs() #4

; Function Attrs: nounwind uwtable
declare hidden void @create_record(i64 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @add_id_to_pool(i64 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @periodic_stat() #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 hidden void @delete_record(i64 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @db_connect() #0

; Function Attrs: nounwind uwtable
declare hidden i64 @get_id_from_pool() #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 = { 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 = { "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 = { 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 #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@opt_db_path = external dso_local global [4096 x i8], align 16
@obj_id = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca [4096 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %3) #6
  %4 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @opt_db_path) #6
  %5 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str) #6
  %6 = call i32 @remove(ptr noundef nonnull %3) #6
  %7 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @opt_db_path) #6
  %8 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str.1) #6
  %9 = call i32 @remove(ptr noundef nonnull %3) #6
  %10 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  call void @db_connect()
  %11 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  %12 = call i64 @getClockUs()
  br label %13

13:                                               ; preds = %2, %23
  %.027 = phi i32 [ 0, %2 ], [ %24, %23 ]
  %.02326 = phi i64 [ %12, %2 ], [ %.2, %23 ]
  %14 = load i64, ptr @obj_id, align 8, !tbaa !5
  %15 = add nsw i64 %14, 1
  store i64 %15, ptr @obj_id, align 8, !tbaa !5
  call void @create_record(i64 noundef %14)
  call void @add_id_to_pool(i64 noundef %14)
  %16 = urem i32 %.027, 1000
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %23

18:                                               ; preds = %13
  %19 = call i64 @getClockUs()
  %20 = sub nsw i64 %19, %.02326
  %21 = icmp sgt i64 %20, 1000000
  br i1 %21, label %22, label %23

22:                                               ; preds = %18
  call void @periodic_stat()
  br label %23

23:                                               ; preds = %18, %22, %13
  %.2 = phi i64 [ %.02326, %13 ], [ %19, %22 ], [ %.02326, %18 ]
  %24 = add nuw nsw i32 %.027, 1
  %exitcond.not = icmp eq i32 %24, 10240000
  br i1 %exitcond.not, label %.sink.split, label %13, !llvm.loop !9

.sink.split:                                      ; preds = %34, %23
  %.3.ph = phi i64 [ %.2, %23 ], [ %37, %34 ]
  call void @periodic_stat()
  br label %25

25:                                               ; preds = %.sink.split, %34
  br label %26

26:                                               ; preds = %25, %26
  %.02428 = phi i32 [ 0, %25 ], [ %30, %26 ]
  %27 = load i64, ptr @obj_id, align 8, !tbaa !5
  %28 = add nsw i64 %27, 1
  store i64 %28, ptr @obj_id, align 8, !tbaa !5
  call void @create_record(i64 noundef %27)
  call void @add_id_to_pool(i64 noundef %27)
  %29 = call i64 @get_id_from_pool()
  call void @delete_record(i64 noundef %29)
  %30 = add nuw nsw i32 %.02428, 1
  %exitcond30.not = icmp eq i32 %30, 1000
  br i1 %exitcond30.not, label %.preheader, label %26, !llvm.loop !11

.preheader:                                       ; preds = %26, %.preheader
  %.12529 = phi i32 [ %33, %.preheader ], [ 0, %26 ]
  %31 = load i64, ptr @obj_id, align 8, !tbaa !5
  %32 = add nsw i64 %31, 1
  store i64 %32, ptr @obj_id, align 8, !tbaa !5
  call void @create_record(i64 noundef %31)
  call void @add_id_to_pool(i64 noundef %31)
  %33 = add nuw nsw i32 %.12529, 1
  %exitcond31.not = icmp eq i32 %33, 50
  br i1 %exitcond31.not, label %34, label %.preheader, !llvm.loop !12

34:                                               ; preds = %.preheader
  %35 = load i64, ptr @obj_id, align 8, !tbaa !5
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr @obj_id, align 8, !tbaa !5
  call void @create_record(i64 noundef %35)
  call void @add_id_to_pool(i64 noundef %35)
  %37 = call i64 @getClockUs()
  %38 = sub nsw i64 %37, %.3.ph
  %39 = icmp sgt i64 %38, 10000000
  br i1 %39, label %.sink.split, label %25
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcat(ptr noalias noundef returned, ptr noalias nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @remove(ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @getClockUs() local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden void @create_record(i64 noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare hidden void @add_id_to_pool(i64 noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare hidden void @periodic_stat() local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare hidden void @delete_record(i64 noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare hidden void @db_connect() local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare hidden i64 @get_id_from_pool() local_unnamed_addr #5

attributes #0 = { noreturn 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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 = { 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 #4 = { 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 #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 }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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