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

; 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.sqlite3 = type { ptr, ptr, ptr, ptr, ptr, i32, i32, i64, i64, i32, i32, i32, i32, i16, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i32, i32, i32, [12 x i32], i32, %struct.sqlite3InitInfo, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %union.anon, %struct.Lookaside, ptr, ptr, ptr, ptr, i32, i32, %struct.Hash, ptr, ptr, ptr, %struct.Hash, %struct.Hash, %struct.BusyHandler, [2 x %struct.Db], ptr, i32, i32, i32, i64, i64, ptr }
%struct.sqlite3InitInfo = type { i32, i8, i8, i8, i8 }
%union.anon = type { double }
%struct.Lookaside = type { i32, i16, i8, i32, i32, [3 x i32], ptr, ptr, ptr }
%struct.Hash = type { i32, i32, ptr, ptr }
%struct.BusyHandler = type { ptr, ptr, i32 }
%struct.Db = type { ptr, ptr, i8, i8, ptr }
%struct.Module = type { ptr, ptr, ptr, ptr, ptr }

@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [7 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: nounwind uwtable
declare dso_local ptr @sqlite3FindTable(ptr noundef, ptr noundef, ptr noundef) #1

declare ptr @sqlite3HashFind(ptr noundef, ptr noundef) #2

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

17:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %99

18:                                               ; preds = %4
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Parse, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = call ptr @sqlite3FindTable(ptr noundef %21, ptr noundef %22, ptr noundef %23)
  store ptr %24, ptr %10, align 8, !tbaa !5
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %97

27:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = and i32 %28, 1
  %30 = icmp ne i32 %29, 0
  %31 = zext i1 %30 to i64
  %32 = select i1 %30, ptr @.str.2, ptr @.str.3
  store ptr %32, ptr %12, align 8, !tbaa !5
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Parse, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = call i32 @sqlite3FindDbName(ptr noundef %35, ptr noundef %36)
  %38 = icmp slt i32 %37, 1
  br i1 %38, label %39, label %74

39:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.Parse, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = getelementptr inbounds %struct.sqlite3, ptr %42, i32 0, i32 65
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = call ptr @sqlite3HashFind(ptr noundef %43, ptr noundef %44)
  store ptr %45, ptr %13, align 8, !tbaa !5
  %46 = load ptr, ptr %13, align 8, !tbaa !5
  %47 = icmp eq ptr %46, null
  br i1 %47, label %48, label %58

48:                                               ; preds = %39
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = call i32 @sqlite3_strnicmp(ptr noundef %49, ptr noundef @.str.4, i32 noundef 7)
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %52, label %58

52:                                               ; preds = %48
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.Parse, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !11
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = call ptr @sqlite3PragmaVtabRegister(ptr noundef %55, ptr noundef %56)
  store ptr %57, ptr %13, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %52, %48, %39
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %70

61:                                               ; preds = %58
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %13, align 8, !tbaa !5
  %64 = call i32 @sqlite3VtabEponymousTableInit(ptr noundef %62, ptr noundef %63)
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %70

66:                                               ; preds = %61
  %67 = load ptr, ptr %13, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.Module, ptr %67, i32 0, i32 4
  %69 = load ptr, ptr %68, align 8, !tbaa !15
  store ptr %69, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %71

70:                                               ; preds = %61, %58
  store i32 0, ptr %11, align 4
  br label %71

71:                                               ; preds = %70, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  %72 = load i32, ptr %11, align 4
  switch i32 %72, label %94 [
    i32 0, label %73
  ]

73:                                               ; preds = %71
  br label %74

74:                                               ; preds = %73, %27
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = and i32 %75, 2
  %77 = icmp eq i32 %76, 0
  br i1 %77, label %78, label %93

78:                                               ; preds = %74
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  %80 = icmp ne ptr %79, null
  br i1 %80, label %81, label %86

81:                                               ; preds = %78
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = load ptr, ptr %12, align 8, !tbaa !5
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  call void (ptr, ptr, ...) @sqlite3ErrorMsg(ptr noundef %82, ptr noundef @.str.5, ptr noundef %83, ptr noundef %84, ptr noundef %85)
  br label %90

86:                                               ; preds = %78
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = load ptr, ptr %12, align 8, !tbaa !5
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  call void (ptr, ptr, ...) @sqlite3ErrorMsg(ptr noundef %87, ptr noundef @.str.6, ptr noundef %88, ptr noundef %89)
  br label %90

90:                                               ; preds = %86, %81
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.Parse, ptr %91, i32 0, i32 5
  store i8 1, ptr %92, align 1, !tbaa !17
  br label %93

93:                                               ; preds = %90, %74
  store i32 0, ptr %11, align 4
  br label %94

94:                                               ; preds = %93, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %95 = load i32, ptr %11, align 4
  switch i32 %95, label %99 [
    i32 0, label %96
  ]

96:                                               ; preds = %94
  br label %97

97:                                               ; preds = %96, %18
  %98 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %98, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %99

99:                                               ; preds = %97, %94, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %100 = load ptr, ptr %5, align 8
  ret ptr %100
}

declare i32 @sqlite3ReadSchema(ptr noundef) #2

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

declare i32 @sqlite3_strnicmp(ptr noundef, ptr noundef, i32 noundef) #2

declare ptr @sqlite3PragmaVtabRegister(ptr noundef, ptr noundef) #2

declare i32 @sqlite3VtabEponymousTableInit(ptr noundef, ptr noundef) #2

declare void @sqlite3ErrorMsg(ptr noundef, ptr noundef, ...) #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 = !{!12, !6, i64 0}
!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 32}
!16 = !{!"Module", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!17 = !{!12, !7, i64 29}


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

@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [7 x i8], align 1

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

declare ptr @sqlite3HashFind(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @sqlite3LocateTable(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = tail call i32 @sqlite3ReadSchema(ptr noundef %0) #2
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %.thread52

6:                                                ; preds = %4
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = tail call ptr @sqlite3FindTable(ptr noundef %7, ptr noundef %2, ptr noundef %3)
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %.thread52

10:                                               ; preds = %6
  %11 = and i32 %1, 1
  %.not38 = icmp eq i32 %11, 0
  %12 = select i1 %.not38, ptr @.str.3, ptr @.str.2
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  %14 = tail call i32 @sqlite3FindDbName(ptr noundef %13, ptr noundef %3)
  %15 = icmp slt i32 %14, 1
  br i1 %15, label %16, label %.thread48

16:                                               ; preds = %10
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 440
  %19 = tail call ptr @sqlite3HashFind(ptr noundef nonnull %18, ptr noundef %2) #2
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %.thread44

21:                                               ; preds = %16
  %22 = tail call i32 @sqlite3_strnicmp(ptr noundef %2, ptr noundef nonnull @.str.4, i32 noundef 7) #2
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %.thread48

24:                                               ; preds = %21
  %25 = load ptr, ptr %0, align 8, !tbaa !5
  %26 = tail call ptr @sqlite3PragmaVtabRegister(ptr noundef %25, ptr noundef %2) #2
  %.not39 = icmp eq ptr %26, null
  br i1 %.not39, label %.thread48, label %.thread44

.thread44:                                        ; preds = %16, %24
  %.047 = phi ptr [ %26, %24 ], [ %19, %16 ]
  %27 = tail call i32 @sqlite3VtabEponymousTableInit(ptr noundef nonnull %0, ptr noundef nonnull %.047) #2
  %.not40 = icmp eq i32 %27, 0
  br i1 %.not40, label %.thread48, label %35

.thread48:                                        ; preds = %21, %24, %.thread44, %10
  %28 = and i32 %1, 2
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %.thread52

30:                                               ; preds = %.thread48
  %.not41 = icmp eq ptr %3, null
  br i1 %.not41, label %32, label %31

31:                                               ; preds = %30
  tail call void (ptr, ptr, ...) @sqlite3ErrorMsg(ptr noundef nonnull %0, ptr noundef nonnull @.str.5, ptr noundef nonnull %12, ptr noundef nonnull %3, ptr noundef %2) #2
  br label %33

32:                                               ; preds = %30
  tail call void (ptr, ptr, ...) @sqlite3ErrorMsg(ptr noundef nonnull %0, ptr noundef nonnull @.str.6, ptr noundef nonnull %12, ptr noundef %2) #2
  br label %33

33:                                               ; preds = %32, %31
  %34 = getelementptr inbounds i8, ptr %0, i64 29
  store i8 1, ptr %34, align 1, !tbaa !13
  br label %.thread52

35:                                               ; preds = %.thread44
  %36 = getelementptr inbounds i8, ptr %.047, i64 32
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  br label %.thread52

.thread52:                                        ; preds = %.thread48, %33, %6, %35, %4
  %.3 = phi ptr [ %37, %35 ], [ null, %4 ], [ %8, %6 ], [ null, %33 ], [ null, %.thread48 ]
  ret ptr %.3
}

declare i32 @sqlite3ReadSchema(ptr noundef) local_unnamed_addr #1

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

declare i32 @sqlite3_strnicmp(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare ptr @sqlite3PragmaVtabRegister(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @sqlite3VtabEponymousTableInit(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @sqlite3ErrorMsg(ptr noundef, ptr noundef, ...) 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 0}
!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 29}
!14 = !{!15, !7, i64 32}
!15 = !{!"Module", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}


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