; LLVM IR from cruppstahl/upscaledb :: tools/ups_bench/upscaledb.ll (ZN15UpscaleDatabase15do_cursor_eraseEPmP9ups_key_t)

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

%class.Database = type { ptr, i32, ptr }
%struct.Configuration = type <{ i8, [3 x i8], i32, i8, i8, i8, [5 x i8], %"class.std::__cxx11::basic_string", i8, [3 x i8], i32, i32, i32, i8, [3 x i8], i32, i64, i64, i64, i64, i32, i8, [3 x i8], i32, i32, i32, i32, i8, i8, [2 x i8], i32, i8, [3 x i8], i32, i8, i8, i8, i8, i8, [3 x i8], i32, i32, i32, i8, i8, i8, i8, i32, i32, %"class.std::__cxx11::basic_string", i32, i32, i32, i8, i8, [2 x i8], i32, i32, i32, i8, i8, i8, i8, i32, i8, i8, [2 x i8] }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@.str.23 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [33 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 i32 @printf(ptr noundef, ...) #1

declare ptr @ups_strerror(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN15UpscaleDatabase15do_cursor_eraseEPmP9ups_key_t(ptr noundef nonnull align 8 dereferenceable(712) %0, ptr noundef %1, ptr noundef %2) unnamed_addr #2 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = call i32 @ups_cursor_find(ptr noundef %11, ptr noundef %12, ptr noundef null, i32 noundef 0)
  store i32 %13, ptr %8, align 4, !tbaa !9
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %30

16:                                               ; preds = %3
  br label %17

17:                                               ; preds = %16
  %18 = getelementptr inbounds %class.Database, ptr %10, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.Configuration, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !13
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %28

23:                                               ; preds = %17
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = call ptr @ups_strerror(i32 noundef %25)
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.23, i32 noundef %24, ptr noundef %26)
  br label %28

28:                                               ; preds = %23, %17
  %29 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %29, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %50

30:                                               ; preds = %3
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = call i32 @ups_cursor_erase(ptr noundef %31, i32 noundef 0)
  store i32 %32, ptr %8, align 4, !tbaa !9
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %48

35:                                               ; preds = %30
  br label %36

36:                                               ; preds = %35
  %37 = getelementptr inbounds %class.Database, ptr %10, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = getelementptr inbounds %struct.Configuration, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 4, !tbaa !13
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %47

42:                                               ; preds = %36
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = call ptr @ups_strerror(i32 noundef %44)
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.24, i32 noundef %43, ptr noundef %45)
  br label %47

47:                                               ; preds = %42, %36
  br label %48

48:                                               ; preds = %47, %30
  %49 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %49, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %50

50:                                               ; preds = %48, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %51 = load i32, ptr %4, align 4
  ret i32 %51
}

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

declare i32 @ups_cursor_erase(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 = { mustprogress 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 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS8Database", !10, i64 8, !6, i64 16}
!13 = !{!14, !10, i64 4}
!14 = !{!"_ZTS13Configuration", !15, i64 0, !10, i64 4, !15, i64 8, !15, i64 9, !15, i64 10, !16, i64 16, !15, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !15, i64 64, !10, i64 68, !18, i64 72, !18, i64 80, !18, i64 88, !18, i64 96, !10, i64 104, !15, i64 108, !10, i64 112, !10, i64 116, !10, i64 120, !10, i64 124, !15, i64 128, !15, i64 129, !10, i64 132, !15, i64 136, !10, i64 140, !15, i64 144, !15, i64 145, !15, i64 146, !15, i64 147, !15, i64 148, !10, i64 152, !10, i64 156, !10, i64 160, !15, i64 164, !15, i64 165, !15, i64 166, !10, i64 168, !10, i64 172, !16, i64 176, !10, i64 208, !10, i64 212, !10, i64 216, !15, i64 220, !15, i64 221, !10, i64 224, !10, i64 228, !10, i64 232, !15, i64 236, !15, i64 237, !15, i64 238, !15, i64 239, !10, i64 240, !15, i64 244, !15, i64 245}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !17, i64 0, !18, i64 8, !7, i64 16}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!18 = !{!"long", !7, i64 0}


; 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.23 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [33 x i8], align 1

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

declare ptr @ups_strerror(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN15UpscaleDatabase15do_cursor_eraseEPmP9ups_key_t(ptr nocapture noundef nonnull readonly align 8 dereferenceable(712) %0, ptr noundef %1, ptr noundef %2) unnamed_addr #2 align 2 {
  %4 = tail call i32 @ups_cursor_find(ptr noundef %1, ptr noundef %2, ptr noundef null, i32 noundef 0)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %13, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %.not16 = icmp eq i32 %9, 0
  br i1 %.not16, label %23, label %10

10:                                               ; preds = %5
  %11 = tail call ptr @ups_strerror(i32 noundef %4)
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.23, i32 noundef %4, ptr noundef %11)
  br label %23

13:                                               ; preds = %3
  %14 = tail call i32 @ups_cursor_erase(ptr noundef %1, i32 noundef 0)
  %.not14 = icmp eq i32 %14, 0
  br i1 %.not14, label %23, label %15

15:                                               ; preds = %13
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %.not15 = icmp eq i32 %19, 0
  br i1 %.not15, label %23, label %20

20:                                               ; preds = %15
  %21 = tail call ptr @ups_strerror(i32 noundef %14)
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.24, i32 noundef %14, ptr noundef %21)
  br label %23

23:                                               ; preds = %13, %20, %15, %5, %10
  %.0 = phi i32 [ %4, %10 ], [ %4, %5 ], [ %14, %15 ], [ %14, %20 ], [ 0, %13 ]
  ret i32 %.0
}

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

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

attributes #0 = { 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 #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 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" }

!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, !10, i64 16}
!6 = !{!"_ZTS8Database", !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !7, i64 4}
!12 = !{!"_ZTS13Configuration", !13, i64 0, !7, i64 4, !13, i64 8, !13, i64 9, !13, i64 10, !14, i64 16, !13, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !13, i64 64, !7, i64 68, !16, i64 72, !16, i64 80, !16, i64 88, !16, i64 96, !7, i64 104, !13, i64 108, !7, i64 112, !7, i64 116, !7, i64 120, !7, i64 124, !13, i64 128, !13, i64 129, !7, i64 132, !13, i64 136, !7, i64 140, !13, i64 144, !13, i64 145, !13, i64 146, !13, i64 147, !13, i64 148, !7, i64 152, !7, i64 156, !7, i64 160, !13, i64 164, !13, i64 165, !13, i64 166, !7, i64 168, !7, i64 172, !14, i64 176, !7, i64 208, !7, i64 212, !7, i64 216, !13, i64 220, !13, i64 221, !7, i64 224, !7, i64 228, !7, i64 232, !13, i64 236, !13, i64 237, !13, i64 238, !13, i64 239, !7, i64 240, !13, i64 244, !13, i64 245}
!13 = !{!"bool", !8, i64 0}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !15, i64 0, !16, i64 8, !8, i64 16}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !10, i64 0}
!16 = !{!"long", !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass