; LLVM IR from ibr-ds/STANlite :: Enclave/sqlite (expr)

; 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.Parse = type { ptr, ptr, ptr, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, %struct.Token, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i8, i8, i8, [10 x %struct.yColCache], [8 x i32], %struct.Token, %struct.Token, i16, i8, i8, i8, i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, %struct.Token, ptr, ptr, ptr, ptr, ptr }
%struct.yColCache = type { i32, i16, i8, i32, i32, i32 }
%struct.Token = type { ptr, i32 }

; 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
declare dso_local void @sqlite3ExprCacheStore(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @sqlite3ExprCodeGetColumnOfTable(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @sqlite3ExprCodeGetColumn(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i8 noundef zeroext %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i8, align 1
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store i8 %5, ptr %13, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.Parse, ptr %18, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  store ptr %20, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  store i32 0, ptr %15, align 4, !tbaa !9
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Parse, ptr %21, i32 0, i32 46
  %23 = getelementptr inbounds [10 x %struct.yColCache], ptr %22, i64 0, i64 0
  store ptr %23, ptr %16, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %59, %6
  %25 = load i32, ptr %15, align 4, !tbaa !9
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Parse, ptr %26, i32 0, i32 13
  %28 = load i8, ptr %27, align 1, !tbaa !16
  %29 = zext i8 %28 to i32
  %30 = icmp slt i32 %25, %29
  br i1 %30, label %31, label %64

31:                                               ; preds = %24
  %32 = load ptr, ptr %16, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.yColCache, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 4, !tbaa !17
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = icmp eq i32 %34, %35
  br i1 %36, label %37, label %58

37:                                               ; preds = %31
  %38 = load ptr, ptr %16, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.yColCache, ptr %38, i32 0, i32 1
  %40 = load i16, ptr %39, align 4, !tbaa !19
  %41 = sext i16 %40 to i32
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = icmp eq i32 %41, %42
  br i1 %43, label %44, label %58

44:                                               ; preds = %37
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Parse, ptr %45, i32 0, i32 24
  %47 = load i32, ptr %46, align 8, !tbaa !20
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %46, align 8, !tbaa !20
  %49 = load ptr, ptr %16, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.yColCache, ptr %49, i32 0, i32 5
  store i32 %47, ptr %50, align 4, !tbaa !21
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = load ptr, ptr %16, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.yColCache, ptr %52, i32 0, i32 4
  %54 = load i32, ptr %53, align 4, !tbaa !22
  call void @sqlite3ExprCachePinRegister(ptr noundef %51, i32 noundef %54)
  %55 = load ptr, ptr %16, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.yColCache, ptr %55, i32 0, i32 4
  %57 = load i32, ptr %56, align 4, !tbaa !22
  store i32 %57, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %83

58:                                               ; preds = %37, %31
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %15, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %15, align 4, !tbaa !9
  %62 = load ptr, ptr %16, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.yColCache, ptr %62, i32 1
  store ptr %63, ptr %16, align 8, !tbaa !5
  br label %24, !llvm.loop !23

64:                                               ; preds = %24
  %65 = load ptr, ptr %14, align 8, !tbaa !5
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = load i32, ptr %11, align 4, !tbaa !9
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = load i32, ptr %12, align 4, !tbaa !9
  call void @sqlite3ExprCodeGetColumnOfTable(ptr noundef %65, ptr noundef %66, i32 noundef %67, i32 noundef %68, i32 noundef %69)
  %70 = load i8, ptr %13, align 1, !tbaa !11
  %71 = icmp ne i8 %70, 0
  br i1 %71, label %72, label %76

72:                                               ; preds = %64
  %73 = load ptr, ptr %14, align 8, !tbaa !5
  %74 = load i8, ptr %13, align 1, !tbaa !11
  %75 = zext i8 %74 to i16
  call void @sqlite3VdbeChangeP5(ptr noundef %73, i16 noundef zeroext %75)
  br label %81

76:                                               ; preds = %64
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = load i32, ptr %11, align 4, !tbaa !9
  %79 = load i32, ptr %10, align 4, !tbaa !9
  %80 = load i32, ptr %12, align 4, !tbaa !9
  call void @sqlite3ExprCacheStore(ptr noundef %77, i32 noundef %78, i32 noundef %79, i32 noundef %80)
  br label %81

81:                                               ; preds = %76, %72
  %82 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %82, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %83

83:                                               ; preds = %81, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %84 = load i32, ptr %7, align 4
  ret i32 %84
}

; Function Attrs: nounwind uwtable
declare hidden void @sqlite3ExprCachePinRegister(ptr noundef, i32 noundef) #1

declare void @sqlite3VdbeChangeP5(ptr noundef, i16 noundef zeroext) #2

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 = { "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 }

!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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"Parse", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !7, i64 28, !7, i64 29, !7, i64 30, !7, i64 31, !7, i64 32, !7, i64 33, !7, i64 34, !7, i64 35, !7, i64 36, !7, i64 37, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !6, i64 88, !6, i64 96, !14, i64 104, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !10, i64 176, !10, i64 180, !10, i64 184, !10, i64 188, !7, i64 192, !7, i64 193, !7, i64 194, !7, i64 196, !7, i64 396, !14, i64 432, !14, i64 448, !15, i64 464, !7, i64 466, !7, i64 467, !7, i64 468, !10, i64 472, !10, i64 476, !10, i64 480, !10, i64 484, !6, i64 488, !6, i64 496, !6, i64 504, !6, i64 512, !6, i64 520, !6, i64 528, !14, i64 536, !6, i64 552, !6, i64 560, !6, i64 568, !6, i64 576, !6, i64 584}
!14 = !{!"Token", !6, i64 0, !10, i64 8}
!15 = !{!"short", !7, i64 0}
!16 = !{!13, !7, i64 37}
!17 = !{!18, !10, i64 0}
!18 = !{!"yColCache", !10, i64 0, !15, i64 4, !7, i64 6, !10, i64 8, !10, i64 12, !10, i64 16}
!19 = !{!18, !15, i64 4}
!20 = !{!13, !10, i64 80}
!21 = !{!18, !10, i64 16}
!22 = !{!18, !10, i64 12}
!23 = distinct !{!23, !24}
!24 = !{!"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"

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sqlite3ExprCodeGetColumn(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i8 noundef zeroext %5) local_unnamed_addr #0 {
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 37
  %10 = load i8, ptr %9, align 1, !tbaa !13
  %11 = zext i8 %10 to i32
  %.not34 = icmp eq i8 %10, 0
  br i1 %.not34, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %6
  %12 = getelementptr inbounds i8, ptr %0, i64 196
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %28
  %.033 = phi ptr [ %30, %28 ], [ %12, %.lr.ph.preheader ]
  %.02832 = phi i32 [ %29, %28 ], [ 0, %.lr.ph.preheader ]
  %13 = load i32, ptr %.033, align 4, !tbaa !14
  %14 = icmp eq i32 %13, %3
  br i1 %14, label %15, label %28

15:                                               ; preds = %.lr.ph
  %16 = getelementptr inbounds i8, ptr %.033, i64 4
  %17 = load i16, ptr %16, align 4, !tbaa !16
  %18 = sext i16 %17 to i32
  %19 = icmp eq i32 %18, %2
  br i1 %19, label %20, label %28

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %0, i64 80
  %22 = load i32, ptr %21, align 8, !tbaa !17
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %21, align 8, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %.033, i64 16
  store i32 %22, ptr %24, align 4, !tbaa !18
  %25 = getelementptr inbounds i8, ptr %.033, i64 12
  %26 = load i32, ptr %25, align 4, !tbaa !19
  tail call void @sqlite3ExprCachePinRegister(ptr noundef nonnull %0, i32 noundef %26)
  %27 = load i32, ptr %25, align 4, !tbaa !19
  br label %34

28:                                               ; preds = %.lr.ph, %15
  %29 = add nuw nsw i32 %.02832, 1
  %30 = getelementptr inbounds i8, ptr %.033, i64 20
  %exitcond.not = icmp eq i32 %29, %11
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !20

._crit_edge:                                      ; preds = %28, %6
  tail call void @sqlite3ExprCodeGetColumnOfTable(ptr noundef %8, ptr noundef %1, i32 noundef %3, i32 noundef %2, i32 noundef %4)
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %33, label %31

31:                                               ; preds = %._crit_edge
  %32 = zext i8 %5 to i16
  tail call void @sqlite3VdbeChangeP5(ptr noundef %8, i16 noundef zeroext %32) #2
  br label %34

33:                                               ; preds = %._crit_edge
  tail call void @sqlite3ExprCacheStore(ptr noundef nonnull %0, i32 noundef %3, i32 noundef %2, i32 noundef %4)
  br label %34

34:                                               ; preds = %31, %33, %20
  %.029 = phi i32 [ %27, %20 ], [ %4, %33 ], [ %4, %31 ]
  ret i32 %.029
}

; Function Attrs: nounwind uwtable
declare hidden void @sqlite3ExprCachePinRegister(ptr noundef, i32 noundef) local_unnamed_addr #0

declare void @sqlite3VdbeChangeP5(ptr noundef, i16 noundef zeroext) local_unnamed_addr #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 = { "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, !7, i64 16}
!6 = !{!"Parse", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !8, i64 28, !8, i64 29, !8, i64 30, !8, i64 31, !8, i64 32, !8, i64 33, !8, i64 34, !8, i64 35, !8, i64 36, !8, i64 37, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !7, i64 88, !7, i64 96, !11, i64 104, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !7, i64 144, !7, i64 152, !7, i64 160, !7, i64 168, !10, i64 176, !10, i64 180, !10, i64 184, !10, i64 188, !8, i64 192, !8, i64 193, !8, i64 194, !8, i64 196, !8, i64 396, !11, i64 432, !11, i64 448, !12, i64 464, !8, i64 466, !8, i64 467, !8, i64 468, !10, i64 472, !10, i64 476, !10, i64 480, !10, i64 484, !7, i64 488, !7, i64 496, !7, i64 504, !7, i64 512, !7, i64 520, !7, i64 528, !11, i64 536, !7, i64 552, !7, i64 560, !7, i64 568, !7, i64 576, !7, i64 584}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"Token", !7, i64 0, !10, i64 8}
!12 = !{!"short", !8, i64 0}
!13 = !{!6, !8, i64 37}
!14 = !{!15, !10, i64 0}
!15 = !{!"yColCache", !10, i64 0, !12, i64 4, !8, i64 6, !10, i64 8, !10, i64 12, !10, i64 16}
!16 = !{!15, !12, i64 4}
!17 = !{!6, !10, i64 80}
!18 = !{!15, !10, i64 16}
!19 = !{!15, !10, i64 12}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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