; LLVM IR from cruppstahl/upscaledb :: tools/ups_bench/upscaledb.ll (ZN15UpscaleDatabase9do_insertEPmP9ups_key_tP12ups_record_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"

%struct.ups_key_t = type { i16, ptr, i32, i32 }
%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] }
%class.UpscaleDatabase = type { %class.Database, ptr, ptr, %struct.ups_env_metrics_t, ptr }
%struct.ups_env_metrics_t = type { i16, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, %struct.btree_metrics_t, %struct.btree_metrics_t, i32 }
%struct.btree_metrics_t = type { i16, i64, i64, i64, i32, %struct.min_max_avg_u32_t, %struct.min_max_avg_u32_t, %struct.min_max_avg_u32_t, %struct.min_max_avg_u32_t, %struct.min_max_avg_u32_t, %struct.min_max_avg_u32_t, %struct.min_max_avg_u32_t, %struct.min_max_avg_u32_t, %struct.min_max_avg_u32_t }
%struct.min_max_avg_u32_t = type { i32, i32, i32, i32, i32 }

@.str.14 = external hidden unnamed_addr constant [27 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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

declare ptr @ups_strerror(i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN15UpscaleDatabase9do_insertEPmP9ups_key_tP12ups_record_t(ptr noundef nonnull align 8 dereferenceable(712) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) unnamed_addr #3 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.ups_key_t, align 8
  %11 = 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
  store ptr %3, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  %13 = getelementptr inbounds %class.Database, ptr %12, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds %struct.Configuration, ptr %14, i32 0, i32 31
  %16 = load i8, ptr %15, align 8, !tbaa !13, !range !19, !noundef !20
  %17 = trunc i8 %16 to i1
  br i1 %17, label %18, label %21

18:                                               ; preds = %4
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = or i32 %19, 1
  store i32 %20, ptr %9, align 4, !tbaa !9
  br label %31

21:                                               ; preds = %4
  %22 = getelementptr inbounds %class.Database, ptr %12, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = getelementptr inbounds %struct.Configuration, ptr %23, i32 0, i32 30
  %25 = load i32, ptr %24, align 4, !tbaa !21
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %30

27:                                               ; preds = %21
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = or i32 %28, 2
  store i32 %29, ptr %9, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %27, %21
  br label %31

31:                                               ; preds = %30, %18
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #4
  call void @llvm.memset.p0.i64(ptr align 8 %10, i8 0, i64 24, i1 false)
  %32 = getelementptr inbounds %class.Database, ptr %12, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = getelementptr inbounds %struct.Configuration, ptr %33, i32 0, i32 61
  %35 = load i8, ptr %34, align 2, !tbaa !22, !range !19, !noundef !20
  %36 = trunc i8 %35 to i1
  br i1 %36, label %43, label %37

37:                                               ; preds = %31
  %38 = getelementptr inbounds %class.Database, ptr %12, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = getelementptr inbounds %struct.Configuration, ptr %39, i32 0, i32 62
  %41 = load i8, ptr %40, align 1, !tbaa !23, !range !19, !noundef !20
  %42 = trunc i8 %41 to i1
  br i1 %42, label %43, label %44

43:                                               ; preds = %37, %31
  store ptr %10, ptr %7, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %43, %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %45 = getelementptr inbounds %class.UpscaleDatabase, ptr %12, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !24
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = call i32 @ups_db_insert(ptr noundef %46, ptr noundef %47, ptr noundef %48, ptr noundef %49, i32 noundef %50)
  store i32 %51, ptr %11, align 4, !tbaa !9
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %67

54:                                               ; preds = %44
  br label %55

55:                                               ; preds = %54
  %56 = getelementptr inbounds %class.Database, ptr %12, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = getelementptr inbounds %struct.Configuration, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !30
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %66

61:                                               ; preds = %55
  %62 = load i32, ptr %11, align 4, !tbaa !9
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = call ptr @ups_strerror(i32 noundef %63)
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.14, i32 noundef %62, ptr noundef %64)
  br label %66

66:                                               ; preds = %61, %55
  br label %67

67:                                               ; preds = %66, %44
  %68 = load i32, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret i32 %68
}

declare i32 @ups_db_insert(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 #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++ 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, !15, i64 136}
!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}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!14, !10, i64 132}
!22 = !{!14, !15, i64 238}
!23 = !{!14, !15, i64 239}
!24 = !{!25, !6, i64 32}
!25 = !{!"_ZTS15UpscaleDatabase", !12, i64 0, !6, i64 24, !6, i64 32, !26, i64 40, !6, i64 704}
!26 = !{!"_ZTS17ups_env_metrics_t", !27, i64 0, !18, i64 8, !18, i64 16, !18, i64 24, !18, i64 32, !18, i64 40, !18, i64 48, !18, i64 56, !18, i64 64, !18, i64 72, !18, i64 80, !18, i64 88, !18, i64 96, !18, i64 104, !18, i64 112, !18, i64 120, !18, i64 128, !18, i64 136, !18, i64 144, !18, i64 152, !18, i64 160, !18, i64 168, !18, i64 176, !18, i64 184, !18, i64 192, !18, i64 200, !18, i64 208, !18, i64 216, !28, i64 224, !28, i64 440, !10, i64 656}
!27 = !{!"short", !7, i64 0}
!28 = !{!"_ZTS15btree_metrics_t", !27, i64 0, !18, i64 8, !18, i64 16, !18, i64 24, !10, i64 32, !29, i64 36, !29, i64 56, !29, i64 76, !29, i64 96, !29, i64 116, !29, i64 136, !29, i64 156, !29, i64 176, !29, i64 196}
!29 = !{!"_ZTS17min_max_avg_u32_t", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!30 = !{!14, !10, i64 4}


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

%struct.ups_key_t = type { i16, ptr, i32, i32 }

@.str.14 = external hidden unnamed_addr constant [27 x i8], align 1

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

declare ptr @ups_strerror(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN15UpscaleDatabase9do_insertEPmP9ups_key_tP12ups_record_t(ptr nocapture noundef nonnull readonly align 8 dereferenceable(712) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) unnamed_addr #4 align 2 {
  %5 = alloca %struct.ups_key_t, align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 136
  %9 = load i8, ptr %8, align 8, !tbaa !11, !range !17, !noundef !18
  %10 = trunc nuw i8 %9 to i1
  br i1 %10, label %14, label %11

11:                                               ; preds = %4
  %12 = getelementptr inbounds i8, ptr %7, i64 132
  %13 = load i32, ptr %12, align 4, !tbaa !19
  %.not = icmp eq i32 %13, 0
  %spec.select = select i1 %.not, i32 0, i32 2
  br label %14

14:                                               ; preds = %11, %4
  %.010 = phi i32 [ 1, %4 ], [ %spec.select, %11 ]
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %5, i8 0, i64 24, i1 false)
  %15 = getelementptr inbounds i8, ptr %7, i64 238
  %16 = load i8, ptr %15, align 2, !tbaa !20, !range !17, !noundef !18
  %17 = trunc nuw i8 %16 to i1
  br i1 %17, label %22, label %18

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %7, i64 239
  %20 = load i8, ptr %19, align 1, !tbaa !21, !range !17, !noundef !18
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %22, label %23

22:                                               ; preds = %18, %14
  br label %23

23:                                               ; preds = %22, %18
  %.0 = phi ptr [ %5, %22 ], [ %2, %18 ]
  %24 = getelementptr inbounds i8, ptr %0, i64 32
  %25 = load ptr, ptr %24, align 8, !tbaa !22
  %26 = call i32 @ups_db_insert(ptr noundef %25, ptr noundef %1, ptr noundef %.0, ptr noundef %3, i32 noundef %.010)
  %.not12 = icmp eq i32 %26, 0
  br i1 %.not12, label %34, label %27

27:                                               ; preds = %23
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 4
  %30 = load i32, ptr %29, align 4, !tbaa !28
  %.not13 = icmp eq i32 %30, 0
  br i1 %.not13, label %34, label %31

31:                                               ; preds = %27
  %32 = call ptr @ups_strerror(i32 noundef %26)
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14, i32 noundef %26, ptr noundef %32)
  br label %34

34:                                               ; preds = %27, %31, %23
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #5
  ret i32 %26
}

declare i32 @ups_db_insert(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { "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 = { 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 #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, !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, !13, i64 136}
!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}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!12, !7, i64 132}
!20 = !{!12, !13, i64 238}
!21 = !{!12, !13, i64 239}
!22 = !{!23, !10, i64 32}
!23 = !{!"_ZTS15UpscaleDatabase", !6, i64 0, !10, i64 24, !10, i64 32, !24, i64 40, !10, i64 704}
!24 = !{!"_ZTS17ups_env_metrics_t", !25, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !16, i64 32, !16, i64 40, !16, i64 48, !16, i64 56, !16, i64 64, !16, i64 72, !16, i64 80, !16, i64 88, !16, i64 96, !16, i64 104, !16, i64 112, !16, i64 120, !16, i64 128, !16, i64 136, !16, i64 144, !16, i64 152, !16, i64 160, !16, i64 168, !16, i64 176, !16, i64 184, !16, i64 192, !16, i64 200, !16, i64 208, !16, i64 216, !26, i64 224, !26, i64 440, !7, i64 656}
!25 = !{!"short", !8, i64 0}
!26 = !{!"_ZTS15btree_metrics_t", !25, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !7, i64 32, !27, i64 36, !27, i64 56, !27, i64 76, !27, i64 96, !27, i64 116, !27, i64 136, !27, i64 156, !27, i64 176, !27, i64 196}
!27 = !{!"_ZTS17min_max_avg_u32_t", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16}
!28 = !{!12, !7, i64 4}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass