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

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

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

; 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 i32 @sqlite3ExprIsConstantNotJoin(ptr noundef) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sqlite3ExprCodeTemp(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = call ptr @sqlite3ExprSkipCollate(ptr noundef %9)
  store ptr %10, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.Parse, ptr %11, i32 0, i32 11
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = zext i8 %13 to i32
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %31

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Expr, ptr %17, i32 0, i32 0
  %19 = load i8, ptr %18, align 8, !tbaa !14
  %20 = zext i8 %19 to i32
  %21 = icmp ne i32 %20, 157
  br i1 %21, label %22, label %31

22:                                               ; preds = %16
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = call i32 @sqlite3ExprIsConstantNotJoin(ptr noundef %23)
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %31

26:                                               ; preds = %22
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %27, align 4, !tbaa !16
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call i32 @sqlite3ExprCodeAtInit(ptr noundef %28, ptr noundef %29, i32 noundef -1)
  store i32 %30, ptr %7, align 4, !tbaa !16
  br label %49

31:                                               ; preds = %22, %16, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = call i32 @sqlite3GetTempReg(ptr noundef %32)
  store i32 %33, ptr %8, align 4, !tbaa !16
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i32, ptr %8, align 4, !tbaa !16
  %37 = call i32 @sqlite3ExprCodeTarget(ptr noundef %34, ptr noundef %35, i32 noundef %36)
  store i32 %37, ptr %7, align 4, !tbaa !16
  %38 = load i32, ptr %7, align 4, !tbaa !16
  %39 = load i32, ptr %8, align 4, !tbaa !16
  %40 = icmp eq i32 %38, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %31
  %42 = load i32, ptr %8, align 4, !tbaa !16
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %42, ptr %43, align 4, !tbaa !16
  br label %48

44:                                               ; preds = %31
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i32, ptr %8, align 4, !tbaa !16
  call void @sqlite3ReleaseTempReg(ptr noundef %45, i32 noundef %46)
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %47, align 4, !tbaa !16
  br label %48

48:                                               ; preds = %44, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %49

49:                                               ; preds = %48, %26
  %50 = load i32, ptr %7, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i32 %50
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @sqlite3ExprCodeAtInit(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, !7, i64 35}
!10 = !{!"Parse", !6, i64 0, !6, i64 8, !6, i64 16, !11, 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, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !6, i64 88, !6, i64 96, !12, i64 104, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !11, i64 176, !11, i64 180, !11, i64 184, !11, i64 188, !7, i64 192, !7, i64 193, !7, i64 194, !7, i64 196, !7, i64 396, !12, i64 432, !12, i64 448, !13, i64 464, !7, i64 466, !7, i64 467, !7, i64 468, !11, i64 472, !11, i64 476, !11, i64 480, !11, i64 484, !6, i64 488, !6, i64 496, !6, i64 504, !6, i64 512, !6, i64 520, !6, i64 528, !12, i64 536, !6, i64 552, !6, i64 560, !6, i64 568, !6, i64 576, !6, i64 584}
!11 = !{!"int", !7, i64 0}
!12 = !{!"Token", !6, i64 0, !11, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !7, i64 0}
!15 = !{!"Expr", !7, i64 0, !7, i64 1, !11, i64 4, !7, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !11, i64 40, !11, i64 44, !13, i64 48, !13, i64 50, !13, i64 52, !7, i64 54, !6, i64 56, !6, i64 64}
!16 = !{!11, !11, 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 ptr @sqlite3ExprSkipCollate(ptr noundef) local_unnamed_addr #0

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sqlite3ExprCodeTemp(ptr noundef %0, ptr noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = tail call ptr @sqlite3ExprSkipCollate(ptr noundef %1)
  %5 = getelementptr inbounds i8, ptr %0, i64 35
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %13, label %7

7:                                                ; preds = %3
  %8 = load i8, ptr %4, align 8, !tbaa !13
  %.not19 = icmp eq i8 %8, -99
  br i1 %.not19, label %13, label %9

9:                                                ; preds = %7
  %10 = tail call i32 @sqlite3ExprIsConstantNotJoin(ptr noundef nonnull %4)
  %.not20 = icmp eq i32 %10, 0
  br i1 %.not20, label %13, label %11

11:                                               ; preds = %9
  store i32 0, ptr %2, align 4, !tbaa !15
  %12 = tail call i32 @sqlite3ExprCodeAtInit(ptr noundef nonnull %0, ptr noundef nonnull %4, i32 noundef -1)
  br label %19

13:                                               ; preds = %9, %7, %3
  %14 = tail call i32 @sqlite3GetTempReg(ptr noundef nonnull %0)
  %15 = tail call i32 @sqlite3ExprCodeTarget(ptr noundef nonnull %0, ptr noundef %4, i32 noundef %14)
  %16 = icmp eq i32 %15, %14
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  tail call void @sqlite3ReleaseTempReg(ptr noundef nonnull %0, i32 noundef %14)
  br label %18

18:                                               ; preds = %13, %17
  %storemerge = phi i32 [ 0, %17 ], [ %14, %13 ]
  store i32 %storemerge, ptr %2, align 4, !tbaa !15
  br label %19

19:                                               ; preds = %18, %11
  %.0 = phi i32 [ %12, %11 ], [ %15, %18 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @sqlite3ExprCodeAtInit(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, !8, i64 35}
!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, !8, i64 0}
!14 = !{!"Expr", !8, i64 0, !8, i64 1, !10, i64 4, !8, i64 8, !7, i64 16, !7, i64 24, !8, i64 32, !10, i64 40, !10, i64 44, !12, i64 48, !12, i64 50, !12, i64 52, !8, i64 54, !7, i64 56, !7, i64 64}
!15 = !{!10, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass