; LLVM IR from mbheinen/bpa-ipf-tsp :: libgui (dmgr)

; 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.DBID = type { ptr, i64, i64, i64, i64, i64, i64, ptr, i64 }

; Function Attrs: nounwind uwtable
declare dso_local void @db_resetlock(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @db_setlock(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @db_init(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @db_destroy(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.DBID, ptr %10, i32 0, i32 3
  %12 = load i64, ptr %11, align 8, !tbaa !9
  store i64 %12, ptr %5, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.DBID, ptr %13, i32 0, i32 7
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  store ptr %15, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.DBID, ptr %16, i32 0, i32 5
  %18 = load i64, ptr %17, align 8, !tbaa !14
  %19 = add i64 %18, 8
  store i64 %19, ptr %9, align 8, !tbaa !12
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  call void @db_setlock(ptr noundef %20)
  br label %21

21:                                               ; preds = %52, %1
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %22, ptr %4, align 8, !tbaa !5
  %23 = load i64, ptr %5, align 8, !tbaa !12
  store i64 %23, ptr %3, align 8, !tbaa !12
  br label %24

24:                                               ; preds = %43, %21
  %25 = load i64, ptr %3, align 8, !tbaa !12
  %26 = add nsw i64 %25, -1
  store i64 %26, ptr %3, align 8, !tbaa !12
  %27 = icmp sge i64 %26, 0
  br i1 %27, label %28, label %46

28:                                               ; preds = %24
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds ptr, ptr %29, i64 -1
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  store ptr %31, ptr %8, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %36, %28
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = icmp ne ptr %33, %34
  br i1 %35, label %36, label %43

36:                                               ; preds = %32
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds ptr, ptr %37, i64 -3
  store ptr %38, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds ptr, ptr %39, i64 -1
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  store ptr %41, ptr %8, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %42) #4
  br label %32, !llvm.loop !15

43:                                               ; preds = %32
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds ptr, ptr %44, i64 -3
  store ptr %45, ptr %4, align 8, !tbaa !5
  br label %24, !llvm.loop !17

46:                                               ; preds = %24
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load i64, ptr %9, align 8, !tbaa !12
  %49 = getelementptr inbounds i8, ptr %47, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  store ptr %50, ptr %7, align 8, !tbaa !5
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %51) #4
  br label %52

52:                                               ; preds = %46
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %21, label %55, !llvm.loop !18

55:                                               ; preds = %52
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.DBID, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !19
  call void @llvm.memset.p0.i64(ptr align 1 %58, i8 0, i64 40, i1 false)
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  call void @db_resetlock(ptr noundef %59)
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.DBID, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !19
  call void @free(ptr noundef %62) #4
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  call void @db_init(ptr noundef %63)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret i32 0
}

; 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 void @free(ptr noundef) #2

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

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !11, i64 24}
!10 = !{!"", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !6, i64 56, !11, i64 64}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 56}
!14 = !{!10, !11, i64 40}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}
!19 = !{!10, !6, 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"

; Function Attrs: nounwind uwtable
declare dso_local void @db_resetlock(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @db_setlock(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @db_init(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @db_destroy(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 56
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load i64, ptr %6, align 8, !tbaa !12
  %8 = add i64 %7, 8
  tail call void @db_setlock(ptr noundef %0)
  %9 = icmp sgt i64 %3, 0
  br i1 %9, label %.lr.ph31.us, label %.split

.lr.ph31.us:                                      ; preds = %1, %._crit_edge32.us
  %.022.us = phi ptr [ %20, %._crit_edge32.us ], [ %5, %1 ]
  br label %10

10:                                               ; preds = %.lr.ph31.us, %._crit_edge.us
  %.in = phi i64 [ %3, %.lr.ph31.us ], [ %11, %._crit_edge.us ]
  %.02329.us = phi ptr [ %.022.us, %.lr.ph31.us ], [ %17, %._crit_edge.us ]
  %11 = add nsw i64 %.in, -1
  %12 = getelementptr inbounds i8, ptr %.02329.us, i64 -8
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %.not2627.us = icmp eq ptr %13, %.02329.us
  br i1 %.not2627.us, label %._crit_edge.us, label %.lr.ph.us

.lr.ph.us:                                        ; preds = %10, %.lr.ph.us
  %.02128.us = phi ptr [ %16, %.lr.ph.us ], [ %13, %10 ]
  %14 = getelementptr inbounds i8, ptr %.02128.us, i64 -24
  %15 = getelementptr inbounds i8, ptr %.02128.us, i64 -8
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  tail call void @free(ptr noundef nonnull %14) #3
  %.not26.us = icmp eq ptr %16, %.02329.us
  br i1 %.not26.us, label %._crit_edge.us, label %.lr.ph.us, !llvm.loop !14

._crit_edge.us:                                   ; preds = %.lr.ph.us, %10
  %17 = getelementptr inbounds i8, ptr %.02329.us, i64 -24
  %18 = icmp sgt i64 %.in, 1
  br i1 %18, label %10, label %._crit_edge32.us, !llvm.loop !16

._crit_edge32.us:                                 ; preds = %._crit_edge.us
  %19 = getelementptr inbounds i8, ptr %.022.us, i64 %8
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  tail call void @free(ptr noundef nonnull %17) #3
  %.not.us = icmp eq ptr %20, null
  br i1 %.not.us, label %.split34.us, label %.lr.ph31.us, !llvm.loop !17

.split:                                           ; preds = %1, %.split
  %.022 = phi ptr [ %22, %.split ], [ %5, %1 ]
  %21 = getelementptr inbounds i8, ptr %.022, i64 %8
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  tail call void @free(ptr noundef %.022) #3
  %.not = icmp eq ptr %22, null
  br i1 %.not, label %.split34.us, label %.split, !llvm.loop !17

.split34.us:                                      ; preds = %.split, %._crit_edge32.us
  %23 = load ptr, ptr %0, align 8, !tbaa !18
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(40) %23, i8 0, i64 40, i1 false)
  tail call void @db_resetlock(ptr noundef nonnull %0)
  %24 = load ptr, ptr %0, align 8, !tbaa !18
  tail call void @free(ptr noundef %24) #3
  tail call void @db_init(ptr noundef nonnull %0)
  ret i32 0
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

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

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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 24}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !7, i64 56, !10, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 56}
!12 = !{!6, !10, i64 40}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}
!18 = !{!6, !7, i64 0}


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