; LLVM IR from nbosb/simdal :: deps/sqlite/src (shell)

; 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.sqlite3expert = type { i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, ptr, i32, %struct.IdxHash, ptr }
%struct.IdxHash = type { ptr, [1023 x ptr] }
%struct.IdxStatement = type { i32, ptr, ptr, ptr, ptr }

; 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: nounwind uwtable
define dso_local ptr @sqlite3_expert_report(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.sqlite3expert, ptr %11, i32 0, i32 8
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %68

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.sqlite3expert, ptr %17, i32 0, i32 7
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  store ptr %19, ptr %9, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %32, %16
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %29

23:                                               ; preds = %20
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.IdxStatement, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !15
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = icmp ne i32 %26, %27
  br label %29

29:                                               ; preds = %23, %20
  %30 = phi i1 [ false, %20 ], [ %28, %23 ]
  br i1 %30, label %31, label %36

31:                                               ; preds = %29
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.IdxStatement, ptr %33, i32 0, i32 4
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  store ptr %35, ptr %9, align 8, !tbaa !5
  br label %20, !llvm.loop !18

36:                                               ; preds = %29
  %37 = load i32, ptr %7, align 4, !tbaa !9
  switch i32 %37, label %66 [
    i32 1, label %38
    i32 2, label %46
    i32 3, label %54
    i32 4, label %62
  ]

38:                                               ; preds = %36
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %45

41:                                               ; preds = %38
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.IdxStatement, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !20
  store ptr %44, ptr %8, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %41, %38
  br label %66

46:                                               ; preds = %36
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %53

49:                                               ; preds = %46
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.IdxStatement, ptr %50, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !21
  store ptr %52, ptr %8, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %49, %46
  br label %66

54:                                               ; preds = %36
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %61

57:                                               ; preds = %54
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.IdxStatement, ptr %58, i32 0, i32 3
  %60 = load ptr, ptr %59, align 8, !tbaa !22
  store ptr %60, ptr %8, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %57, %54
  br label %66

62:                                               ; preds = %36
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.sqlite3expert, ptr %63, i32 0, i32 12
  %65 = load ptr, ptr %64, align 8, !tbaa !23
  store ptr %65, ptr %8, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %62, %61, %53, %45, %36
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %67, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %68

68:                                               ; preds = %66, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %69 = load ptr, ptr %4, align 8
  ret ptr %69
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 64}
!12 = !{!"sqlite3expert", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !10, i64 64, !6, i64 72, !10, i64 80, !13, i64 88, !6, i64 8280}
!13 = !{!"IdxHash", !6, i64 0, !7, i64 8}
!14 = !{!12, !6, i64 56}
!15 = !{!16, !10, i64 0}
!16 = !{!"IdxStatement", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!17 = !{!16, !6, i64 32}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!16, !6, i64 8}
!21 = !{!16, !6, i64 16}
!22 = !{!16, !6, i64 24}
!23 = !{!12, !6, i64 8280}


; 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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @sqlite3_expert_report(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %24, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 56
  %.018 = load ptr, ptr %8, align 8, !tbaa !12
  %.not19 = icmp eq ptr %.018, null
  br i1 %.not19, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %7, %10
  %.020 = phi ptr [ %.0, %10 ], [ %.018, %7 ]
  %9 = load i32, ptr %.020, align 8, !tbaa !13
  %.not17.not = icmp ne i32 %9, %1
  br i1 %.not17.not, label %10, label %.critedge

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds i8, ptr %.020, i64 32
  %.0 = load ptr, ptr %11, align 8, !tbaa !12
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !15

.critedge:                                        ; preds = %.lr.ph, %10, %7
  %.0.lcssa = phi ptr [ null, %7 ], [ null, %10 ], [ %.020, %.lr.ph ]
  %.not.lcssa = phi i1 [ true, %7 ], [ %.not17.not, %10 ], [ %.not17.not, %.lr.ph ]
  switch i32 %2, label %24 [
    i32 1, label %12
    i32 2, label %15
    i32 3, label %18
    i32 4, label %21
  ]

12:                                               ; preds = %.critedge
  br i1 %.not.lcssa, label %24, label %13

13:                                               ; preds = %12
  %14 = getelementptr inbounds i8, ptr %.0.lcssa, i64 8
  br label %.sink.split

15:                                               ; preds = %.critedge
  br i1 %.not.lcssa, label %24, label %16

16:                                               ; preds = %15
  %17 = getelementptr inbounds i8, ptr %.0.lcssa, i64 16
  br label %.sink.split

18:                                               ; preds = %.critedge
  br i1 %.not.lcssa, label %24, label %19

19:                                               ; preds = %18
  %20 = getelementptr inbounds i8, ptr %.0.lcssa, i64 24
  br label %.sink.split

21:                                               ; preds = %.critedge
  %22 = getelementptr inbounds i8, ptr %0, i64 8280
  br label %.sink.split

.sink.split:                                      ; preds = %19, %16, %13, %21
  %.sink = phi ptr [ %22, %21 ], [ %14, %13 ], [ %17, %16 ], [ %20, %19 ]
  %23 = load ptr, ptr %.sink, align 8, !tbaa !12
  br label %24

24:                                               ; preds = %.sink.split, %.critedge, %12, %15, %18, %3
  %.016 = phi ptr [ null, %3 ], [ null, %.critedge ], [ null, %18 ], [ null, %15 ], [ null, %12 ], [ %23, %.sink.split ]
  ret ptr %.016
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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, !7, i64 64}
!6 = !{!"sqlite3expert", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !7, i64 64, !10, i64 72, !7, i64 80, !11, i64 88, !10, i64 8280}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"IdxHash", !10, i64 0, !8, i64 8}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"IdxStatement", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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