; 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 }
%struct.schem = type { i8, i8, i64, i64, i64, ptr }

@.str.2 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [6 x i8], align 1
@__PRETTY_FUNCTION__.db_next = external hidden unnamed_addr constant [66 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [36 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

32:                                               ; preds = %4
  br label %34

33:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str.17, ptr noundef @.str.2, i32 noundef 641, ptr noundef @__PRETTY_FUNCTION__.db_next) #4
  unreachable

34:                                               ; preds = %32
  %35 = load i64, ptr %9, align 8, !tbaa !9
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.DBID, ptr %36, i32 0, i32 4
  %38 = load i64, ptr %37, align 8, !tbaa !16
  %39 = icmp sle i64 %35, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %34
  br label %42

41:                                               ; preds = %34
  call void @__assert_fail(ptr noundef @.str.18, ptr noundef @.str.2, i32 noundef 642, ptr noundef @__PRETTY_FUNCTION__.db_next) #4
  unreachable

42:                                               ; preds = %40
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.DBID, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !13
  %46 = load i64, ptr %9, align 8, !tbaa !9
  %47 = getelementptr inbounds [0 x %struct.schem], ptr %45, i64 0, i64 %46
  %48 = getelementptr inbounds %struct.schem, ptr %47, i32 0, i32 0
  %49 = load i8, ptr %48, align 8, !tbaa !17
  %50 = sext i8 %49 to i32
  %51 = icmp ne i32 %50, 110
  br i1 %51, label %52, label %53

52:                                               ; preds = %42
  br label %54

53:                                               ; preds = %42
  call void @__assert_fail(ptr noundef @.str.19, ptr noundef @.str.2, i32 noundef 643, ptr noundef @__PRETTY_FUNCTION__.db_next) #4
  unreachable

54:                                               ; preds = %52
  br label %55

55:                                               ; preds = %60, %54
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.DBID, ptr %56, i32 0, i32 8
  %58 = load i64, ptr %57, align 8, !tbaa !18
  %59 = icmp ne i64 %58, 0
  br i1 %59, label %60, label %61

60:                                               ; preds = %55
  br label %55, !llvm.loop !19

61:                                               ; preds = %55
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %62, i64 8
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = load i64, ptr %64, align 8, !tbaa !9
  %66 = load i64, ptr %13, align 8, !tbaa !9
  %67 = mul nsw i64 %65, %66
  %68 = getelementptr inbounds ptr, ptr %63, i64 %67
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %69, ptr %70, align 8, !tbaa !5
  %71 = icmp ne ptr %69, null
  br i1 %71, label %72, label %73

72:                                               ; preds = %61
  store i32 2, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %74

73:                                               ; preds = %61
  store i32 5, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %74

74:                                               ; preds = %73, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %75 = load i32, ptr %5, align 4
  ret i32 %75
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { nounwind }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 40}
!12 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !6, i64 56, !10, i64 64}
!13 = !{!12, !6, i64 0}
!14 = !{!15, !10, i64 24}
!15 = !{!"schem", !7, i64 0, !7, i64 1, !10, i64 8, !10, i64 16, !10, i64 24, !6, i64 32}
!16 = !{!12, !10, i64 32}
!17 = !{!15, !7, i64 0}
!18 = !{!12, !10, i64 64}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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

@.str.2 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [6 x i8], align 1
@__PRETTY_FUNCTION__.db_next = external hidden unnamed_addr constant [66 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [36 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 2, 6) i32 @db_next(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, i64 noundef %3) local_unnamed_addr #1 {
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load i64, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %0, align 8, !tbaa !12
  %9 = getelementptr inbounds [0 x %struct.schem], ptr %8, i64 0, i64 %3
  %10 = getelementptr inbounds i8, ptr %9, i64 24
  %11 = load i64, ptr %10, align 8, !tbaa !13
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %12, label %13

12:                                               ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.17, ptr noundef nonnull @.str.2, i32 noundef 641, ptr noundef nonnull @__PRETTY_FUNCTION__.db_next) #2
  unreachable

13:                                               ; preds = %4
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %15 = load i64, ptr %14, align 8, !tbaa !15
  %.not16 = icmp slt i64 %15, %3
  br i1 %.not16, label %16, label %17

16:                                               ; preds = %13
  tail call void @__assert_fail(ptr noundef nonnull @.str.18, ptr noundef nonnull @.str.2, i32 noundef 642, ptr noundef nonnull @__PRETTY_FUNCTION__.db_next) #2
  unreachable

17:                                               ; preds = %13
  %18 = load i8, ptr %9, align 8, !tbaa !16
  %.not17 = icmp eq i8 %18, 110
  br i1 %.not17, label %21, label %.preheader

.preheader:                                       ; preds = %17
  %19 = getelementptr inbounds i8, ptr %0, i64 64
  %20 = load i64, ptr %19, align 8, !tbaa !17
  %.not18 = icmp eq i64 %20, 0
  br i1 %.not18, label %22, label %.preheader.split, !llvm.loop !18

21:                                               ; preds = %17
  tail call void @__assert_fail(ptr noundef nonnull @.str.19, ptr noundef nonnull @.str.2, i32 noundef 643, ptr noundef nonnull @__PRETTY_FUNCTION__.db_next) #2
  unreachable

.preheader.split:                                 ; preds = %.preheader, %.preheader.split
  br label %.preheader.split

22:                                               ; preds = %.preheader
  %23 = getelementptr inbounds i8, ptr %5, i64 %7
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  %25 = load i64, ptr %23, align 8, !tbaa !20
  %26 = mul nsw i64 %25, %11
  %27 = getelementptr inbounds ptr, ptr %24, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  store ptr %28, ptr %2, align 8, !tbaa !5
  %.not19 = icmp eq ptr %28, null
  %. = select i1 %.not19, i32 5, i32 2
  ret i32 %.
}

attributes #0 = { 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 #1 = { 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 #2 = { 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/C++ TBAA"}
!9 = !{!10, !11, i64 40}
!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 = !{!10, !6, i64 0}
!13 = !{!14, !11, i64 24}
!14 = !{!"schem", !7, i64 0, !7, i64 1, !11, i64 8, !11, i64 16, !11, i64 24, !6, i64 32}
!15 = !{!10, !11, i64 32}
!16 = !{!14, !7, i64 0}
!17 = !{!10, !11, i64 64}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass