; 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 }
%struct.ExprList = type { i32, ptr }
%struct.ExprList_item = type { ptr, ptr, ptr, i8, i8, %union.anon.1 }
%union.anon.1 = type { 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 ptr @sqlite3ExprDup(ptr noundef, ptr noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sqlite3ExprCodeAtInit(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %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 ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Parse, ptr %13, i32 0, i32 27
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  store ptr %15, ptr %8, align 8, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %60

18:                                               ; preds = %3
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %60

21:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ExprList, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  store ptr %24, ptr %9, align 8, !tbaa !5
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ExprList, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !17
  store i32 %27, ptr %10, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %51, %21
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %31, label %56

31:                                               ; preds = %28
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ExprList_item, ptr %32, i32 0, i32 4
  %34 = load i8, ptr %33, align 1
  %35 = lshr i8 %34, 2
  %36 = and i8 %35, 1
  %37 = zext i8 %36 to i32
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %50

39:                                               ; preds = %31
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ExprList_item, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = call i32 @sqlite3ExprCompare(ptr noundef %42, ptr noundef %43, i32 noundef -1)
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %50

46:                                               ; preds = %39
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ExprList_item, ptr %47, i32 0, i32 5
  %49 = load i32, ptr %48, align 4, !tbaa !20
  store i32 %49, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %57

50:                                               ; preds = %39, %31
  br label %51

51:                                               ; preds = %50
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.ExprList_item, ptr %52, i32 1
  store ptr %53, ptr %9, align 8, !tbaa !5
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr %10, align 4, !tbaa !9
  br label %28, !llvm.loop !21

56:                                               ; preds = %28
  store i32 0, ptr %11, align 4
  br label %57

57:                                               ; preds = %56, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %58 = load i32, ptr %11, align 4
  switch i32 %58, label %110 [
    i32 0, label %59
  ]

59:                                               ; preds = %57
  br label %60

60:                                               ; preds = %59, %18, %3
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.Parse, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !23
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = call ptr @sqlite3ExprDup(ptr noundef %63, ptr noundef %64, i32 noundef 0)
  store ptr %65, ptr %6, align 8, !tbaa !5
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = call ptr @sqlite3ExprListAppend(ptr noundef %66, ptr noundef %67, ptr noundef %68)
  store ptr %69, ptr %8, align 8, !tbaa !5
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %105

72:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.ExprList, ptr %73, i32 0, i32 1
  %75 = load ptr, ptr %74, align 8, !tbaa !15
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.ExprList, ptr %76, i32 0, i32 0
  %78 = load i32, ptr %77, align 8, !tbaa !17
  %79 = sub nsw i32 %78, 1
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds %struct.ExprList_item, ptr %75, i64 %80
  store ptr %81, ptr %12, align 8, !tbaa !5
  %82 = load i32, ptr %7, align 4, !tbaa !9
  %83 = icmp slt i32 %82, 0
  %84 = zext i1 %83 to i32
  %85 = load ptr, ptr %12, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.ExprList_item, ptr %85, i32 0, i32 4
  %87 = trunc i32 %84 to i8
  %88 = load i8, ptr %86, align 1
  %89 = and i8 %87, 1
  %90 = shl i8 %89, 2
  %91 = and i8 %88, -5
  %92 = or i8 %91, %90
  store i8 %92, ptr %86, align 1
  %93 = zext i8 %89 to i32
  %94 = load i32, ptr %7, align 4, !tbaa !9
  %95 = icmp slt i32 %94, 0
  br i1 %95, label %96, label %101

96:                                               ; preds = %72
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.Parse, ptr %97, i32 0, i32 18
  %99 = load i32, ptr %98, align 8, !tbaa !24
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %98, align 8, !tbaa !24
  store i32 %100, ptr %7, align 4, !tbaa !9
  br label %101

101:                                              ; preds = %96, %72
  %102 = load i32, ptr %7, align 4, !tbaa !9
  %103 = load ptr, ptr %12, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.ExprList_item, ptr %103, i32 0, i32 5
  store i32 %102, ptr %104, align 4, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %105

105:                                              ; preds = %101, %60
  %106 = load ptr, ptr %8, align 8, !tbaa !5
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.Parse, ptr %107, i32 0, i32 27
  store ptr %106, ptr %108, align 8, !tbaa !11
  %109 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %109, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %110

110:                                              ; preds = %105, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %111 = load i32, ptr %4, align 4
  ret i32 %111
}

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

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, !6, i64 96}
!12 = !{!"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, !13, 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, !13, i64 432, !13, i64 448, !14, 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, !13, i64 536, !6, i64 552, !6, i64 560, !6, i64 568, !6, i64 576, !6, i64 584}
!13 = !{!"Token", !6, i64 0, !10, i64 8}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !6, i64 8}
!16 = !{!"ExprList", !10, i64 0, !6, i64 8}
!17 = !{!16, !10, i64 0}
!18 = !{!19, !6, i64 0}
!19 = !{!"ExprList_item", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !10, i64 25, !10, i64 25, !10, i64 25, !7, i64 28}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!12, !6, i64 0}
!24 = !{!12, !10, i64 56}


; 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.ExprList_item = type { ptr, ptr, ptr, i8, i8, %union.anon.1 }
%union.anon.1 = type { i32 }

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sqlite3ExprCodeAtInit(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 96
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp slt i32 %2, 0
  %7 = icmp ne ptr %5, null
  %or.cond = select i1 %6, i1 %7, i1 false
  br i1 %or.cond, label %8, label %.thread

8:                                                ; preds = %3
  %9 = load i32, ptr %5, align 8, !tbaa !13
  %10 = icmp slt i32 %9, 1
  br i1 %10, label %.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %8
  %11 = getelementptr inbounds i8, ptr %5, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %20
  %.03243 = phi i32 [ %22, %20 ], [ %9, %.lr.ph.preheader ]
  %.03342 = phi ptr [ %21, %20 ], [ %12, %.lr.ph.preheader ]
  %13 = getelementptr inbounds i8, ptr %.03342, i64 25
  %14 = load i8, ptr %13, align 1
  %15 = and i8 %14, 4
  %.not = icmp eq i8 %15, 0
  br i1 %.not, label %20, label %16

16:                                               ; preds = %.lr.ph
  %17 = load ptr, ptr %.03342, align 8, !tbaa !16
  %18 = tail call i32 @sqlite3ExprCompare(ptr noundef %17, ptr noundef %1, i32 noundef -1)
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %24, label %20

20:                                               ; preds = %.lr.ph, %16
  %21 = getelementptr inbounds i8, ptr %.03342, i64 32
  %22 = add nsw i32 %.03243, -1
  %23 = icmp slt i32 %.03243, 2
  br i1 %23, label %.thread, label %.lr.ph, !llvm.loop !18

24:                                               ; preds = %16
  %25 = getelementptr inbounds i8, ptr %.03342, i64 28
  %26 = load i32, ptr %25, align 4, !tbaa !20
  br label %48

.thread:                                          ; preds = %20, %8, %3
  %27 = load ptr, ptr %0, align 8, !tbaa !21
  %28 = tail call ptr @sqlite3ExprDup(ptr noundef %27, ptr noundef %1, i32 noundef 0)
  %29 = tail call ptr @sqlite3ExprListAppend(ptr noundef nonnull %0, ptr noundef %5, ptr noundef %28)
  %.not39 = icmp eq ptr %29, null
  br i1 %.not39, label %47, label %30

30:                                               ; preds = %.thread
  %31 = getelementptr inbounds i8, ptr %29, i64 8
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = load i32, ptr %29, align 8, !tbaa !13
  %34 = sext i32 %33 to i64
  %35 = getelementptr %struct.ExprList_item, ptr %32, i64 %34
  %36 = getelementptr i8, ptr %35, i64 -7
  %37 = load i8, ptr %36, align 1
  %sh.diff = lshr i32 %2, 29
  %tr.sh.diff = trunc nuw nsw i32 %sh.diff to i8
  %38 = and i8 %tr.sh.diff, 4
  %39 = and i8 %37, -5
  %40 = or disjoint i8 %39, %38
  store i8 %40, ptr %36, align 1
  br i1 %6, label %41, label %45

41:                                               ; preds = %30
  %42 = getelementptr inbounds i8, ptr %0, i64 56
  %43 = load i32, ptr %42, align 8, !tbaa !22
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %42, align 8, !tbaa !22
  br label %45

45:                                               ; preds = %41, %30
  %.034 = phi i32 [ %44, %41 ], [ %2, %30 ]
  %46 = getelementptr i8, ptr %35, i64 -4
  store i32 %.034, ptr %46, align 4, !tbaa !20
  br label %47

47:                                               ; preds = %45, %.thread
  %.135 = phi i32 [ %.034, %45 ], [ %2, %.thread ]
  store ptr %29, ptr %4, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %24, %47
  %.1 = phi i32 [ %.135, %47 ], [ %26, %24 ]
  ret i32 %.1
}

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

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

!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 96}
!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 = !{!14, !10, i64 0}
!14 = !{!"ExprList", !10, i64 0, !7, i64 8}
!15 = !{!14, !7, i64 8}
!16 = !{!17, !7, i64 0}
!17 = !{!"ExprList_item", !7, i64 0, !7, i64 8, !7, i64 16, !8, i64 24, !10, i64 25, !10, i64 25, !10, i64 25, !8, i64 28}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!8, !8, i64 0}
!21 = !{!6, !7, i64 0}
!22 = !{!6, !10, i64 56}


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