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

; 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_parameter_t = type { i32, i64 }
%class.UpscaleDatabase = type { %class.Database, ptr, ptr, %struct.ups_env_metrics_t, ptr }
%class.Database = type { ptr, i32, 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 }

@_ZN15UpscaleDatabase6ms_envE = external dso_local global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [43 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

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL12compare_keysP8ups_db_tPKhjS2_j(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef) #3

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN15UpscaleDatabase10do_open_dbEi(ptr noundef nonnull align 8 dereferenceable(712) %0, i32 noundef %1) unnamed_addr #5 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [6 x %struct.ups_parameter_t], align 16
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 96, ptr %5) #6
  call void @llvm.memset.p0.i64(ptr align 16 %5, i8 0, i64 96, i1 false)
  %8 = call i32 @ups_register_compare(ptr noundef @.str.11, ptr noundef @_ZL12compare_keysP8ups_db_tPKhjS2_j)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %9 = getelementptr inbounds %class.UpscaleDatabase, ptr %7, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %15

12:                                               ; preds = %2
  %13 = getelementptr inbounds %class.UpscaleDatabase, ptr %7, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  br label %17

15:                                               ; preds = %2
  %16 = load ptr, ptr @_ZN15UpscaleDatabase6ms_envE, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %15, %12
  %18 = phi ptr [ %14, %12 ], [ %16, %15 ]
  %19 = getelementptr inbounds %class.UpscaleDatabase, ptr %7, i32 0, i32 2
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = add nsw i32 1, %20
  %22 = trunc i32 %21 to i16
  %23 = getelementptr inbounds [6 x %struct.ups_parameter_t], ptr %5, i64 0, i64 0
  %24 = call i32 @ups_env_open_db(ptr noundef %18, ptr noundef %19, i16 noundef zeroext %22, i32 noundef 0, ptr noundef %23)
  store i32 %24, ptr %6, align 4, !tbaa !9
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %36

27:                                               ; preds = %17
  br label %28

28:                                               ; preds = %27
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = call ptr @ups_strerror(i32 noundef %31)
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.13, i32 noundef %30, ptr noundef %32)
  br label %34

34:                                               ; preds = %28
  br label %35

35:                                               ; preds = %34
  call void @exit(i32 noundef -1) #7
  unreachable

36:                                               ; preds = %17
  %37 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 96, ptr %5) #6
  ret i32 %37
}

declare i32 @ups_env_open_db(ptr noundef, ptr noundef, i16 noundef zeroext, i32 noundef, ptr 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 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 = { noreturn 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { noreturn 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 24}
!12 = !{!"_ZTS15UpscaleDatabase", !13, i64 0, !6, i64 24, !6, i64 32, !14, i64 40, !6, i64 704}
!13 = !{!"_ZTS8Database", !10, i64 8, !6, i64 16}
!14 = !{!"_ZTS17ups_env_metrics_t", !15, 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, !17, i64 224, !17, i64 440, !10, i64 656}
!15 = !{!"short", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!"_ZTS15btree_metrics_t", !15, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !10, i64 32, !18, i64 36, !18, i64 56, !18, i64 76, !18, i64 96, !18, i64 116, !18, i64 136, !18, i64 156, !18, i64 176, !18, i64 196}
!18 = !{!"_ZTS17min_max_avg_u32_t", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 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"

%struct.ups_parameter_t = type { i32, i64 }

@_ZN15UpscaleDatabase6ms_envE = external dso_local local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [43 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

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL12compare_keysP8ups_db_tPKhjS2_j(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef) #4

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #5

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN15UpscaleDatabase10do_open_dbEi(ptr noundef nonnull align 8 dereferenceable(712) %0, i32 noundef %1) unnamed_addr #6 align 2 {
  %3 = alloca [6 x %struct.ups_parameter_t], align 16
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %3) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(96) %3, i8 0, i64 96, i1 false)
  %4 = tail call i32 @ups_register_compare(ptr noundef nonnull @.str.11, ptr noundef nonnull @_ZL12compare_keysP8ups_db_tPKhjS2_j)
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  %7 = load ptr, ptr @_ZN15UpscaleDatabase6ms_envE, align 8
  %8 = select i1 %.not, ptr %7, ptr %6
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = trunc i32 %1 to i16
  %11 = add i16 %10, 1
  %12 = call i32 @ups_env_open_db(ptr noundef %8, ptr noundef nonnull %9, i16 noundef zeroext %11, i32 noundef 0, ptr noundef nonnull %3)
  %.not6 = icmp eq i32 %12, 0
  br i1 %.not6, label %17, label %13

13:                                               ; preds = %2
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %15 = call ptr @ups_strerror(i32 noundef %12)
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13, i32 noundef %12, ptr noundef %15)
  call void @exit(i32 noundef -1) #8
  unreachable

17:                                               ; preds = %2
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %3) #7
  ret i32 0
}

declare i32 @ups_env_open_db(ptr noundef, ptr noundef, i16 noundef zeroext, i32 noundef, ptr 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 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 = { noreturn 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { noreturn 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, !11, i64 24}
!6 = !{!"_ZTS15UpscaleDatabase", !7, i64 0, !11, i64 24, !11, i64 32, !12, i64 40, !11, i64 704}
!7 = !{!"_ZTS8Database", !8, i64 8, !11, i64 16}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"_ZTS17ups_env_metrics_t", !13, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !14, i64 88, !14, i64 96, !14, i64 104, !14, i64 112, !14, i64 120, !14, i64 128, !14, i64 136, !14, i64 144, !14, i64 152, !14, i64 160, !14, i64 168, !14, i64 176, !14, i64 184, !14, i64 192, !14, i64 200, !14, i64 208, !14, i64 216, !15, i64 224, !15, i64 440, !8, i64 656}
!13 = !{!"short", !9, i64 0}
!14 = !{!"long", !9, i64 0}
!15 = !{!"_ZTS15btree_metrics_t", !13, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !8, i64 32, !16, i64 36, !16, i64 56, !16, i64 76, !16, i64 96, !16, i64 116, !16, i64 136, !16, i64 156, !16, i64 176, !16, i64 196}
!16 = !{!"_ZTS17min_max_avg_u32_t", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !8, i64 16}


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