; 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.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.Schema = type { i32, i32, %struct.Hash, %struct.Hash, %struct.Hash, %struct.Hash, ptr, i8, i8, i16, i32 }

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [19 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
define dso_local ptr @sqlite3FindTable(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 ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  br label %12

12:                                               ; preds = %84, %3
  br label %13

13:                                               ; preds = %12
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %65, %13
  %15 = load i32, ptr %9, align 4, !tbaa !9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.sqlite3, ptr %16, i32 0, i32 5
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = icmp slt i32 %15, %18
  br i1 %19, label %20, label %68

20:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = icmp slt i32 %21, 2
  br i1 %22, label %23, label %26

23:                                               ; preds = %20
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = xor i32 %24, 1
  br label %28

26:                                               ; preds = %20
  %27 = load i32, ptr %9, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %26, %23
  %29 = phi i32 [ %25, %23 ], [ %27, %26 ]
  store i32 %29, ptr %10, align 4, !tbaa !9
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %44, label %32

32:                                               ; preds = %28
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.sqlite3, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !19
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds %struct.Db, ptr %36, i64 %38
  %40 = getelementptr inbounds %struct.Db, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !20
  %42 = call i32 @sqlite3StrICmp(ptr noundef %33, ptr noundef %41)
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %61

44:                                               ; preds = %32, %28
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.sqlite3, ptr %45, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !19
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds %struct.Db, ptr %47, i64 %49
  %51 = getelementptr inbounds %struct.Db, ptr %50, i32 0, i32 4
  %52 = load ptr, ptr %51, align 8, !tbaa !22
  %53 = getelementptr inbounds %struct.Schema, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = call ptr @sqlite3HashFind(ptr noundef %53, ptr noundef %54)
  store ptr %55, ptr %8, align 8, !tbaa !5
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %60

58:                                               ; preds = %44
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %59, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %62

60:                                               ; preds = %44
  br label %61

61:                                               ; preds = %60, %32
  store i32 0, ptr %11, align 4
  br label %62

62:                                               ; preds = %61, %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %63 = load i32, ptr %11, align 4
  switch i32 %63, label %86 [
    i32 0, label %64
  ]

64:                                               ; preds = %62
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %9, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %9, align 4, !tbaa !9
  br label %14, !llvm.loop !23

68:                                               ; preds = %14
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = call i32 @sqlite3StrICmp(ptr noundef %69, ptr noundef @.str)
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %73

72:                                               ; preds = %68
  br label %85

73:                                               ; preds = %68
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.sqlite3, ptr %75, i32 0, i32 4
  %77 = load ptr, ptr %76, align 8, !tbaa !19
  %78 = getelementptr inbounds %struct.Db, ptr %77, i64 1
  %79 = getelementptr inbounds %struct.Db, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !20
  %81 = call i32 @sqlite3_stricmp(ptr noundef %74, ptr noundef %80)
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %84

83:                                               ; preds = %73
  br label %85

84:                                               ; preds = %73
  store ptr @.str.1, ptr %6, align 8, !tbaa !5
  br label %12

85:                                               ; preds = %83, %72
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %86

86:                                               ; preds = %85, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %87 = load ptr, ptr %4, align 8
  ret ptr %87
}

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

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

declare i32 @sqlite3_stricmp(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, !10, i64 40}
!12 = !{!"sqlite3", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !13, i64 48, !13, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !14, i64 80, !7, i64 82, !7, i64 83, !7, i64 84, !7, i64 85, !7, i64 86, !7, i64 87, !7, i64 88, !7, i64 89, !7, i64 90, !7, i64 91, !7, i64 92, !7, i64 93, !7, i64 94, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !7, i64 112, !10, i64 160, !15, i64 164, !10, i64 172, !10, i64 176, !10, i64 180, !10, i64 184, !10, i64 188, !10, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !7, i64 336, !16, i64 344, !6, i64 400, !6, i64 408, !6, i64 416, !6, i64 424, !10, i64 432, !10, i64 436, !17, i64 440, !6, i64 464, !6, i64 472, !6, i64 480, !17, i64 488, !17, i64 512, !18, i64 536, !7, i64 560, !6, i64 624, !10, i64 632, !10, i64 636, !10, i64 640, !13, i64 648, !13, i64 656, !6, i64 664}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"sqlite3InitInfo", !10, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7}
!16 = !{!"Lookaside", !10, i64 0, !14, i64 4, !7, i64 6, !10, i64 8, !10, i64 12, !7, i64 16, !6, i64 32, !6, i64 40, !6, i64 48}
!17 = !{!"Hash", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!18 = !{!"BusyHandler", !6, i64 0, !6, i64 8, !10, i64 16}
!19 = !{!12, !6, i64 32}
!20 = !{!21, !6, i64 0}
!21 = !{!"Db", !6, i64 0, !6, i64 8, !7, i64 16, !7, i64 17, !6, i64 24}
!22 = !{!21, !6, i64 24}
!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"

%struct.Db = type { ptr, ptr, i8, i8, ptr }

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @sqlite3FindTable(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  %5 = icmp eq ptr %2, null
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  br i1 %5, label %.split.us, label %.split

.split.us:                                        ; preds = %3, %10
  %.021.us = phi ptr [ @.str.1, %10 ], [ %1, %3 ]
  %7 = load i32, ptr %4, align 8, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph.us, label %._crit_edge.split.us.us

._crit_edge.split.us.us:                          ; preds = %24, %.split.us
  %9 = tail call i32 @sqlite3StrICmp(ptr noundef %.021.us, ptr noundef nonnull @.str) #2
  %.not.us = icmp eq i32 %9, 0
  br i1 %.not.us, label %10, label %.loopexit

10:                                               ; preds = %._crit_edge.split.us.us
  %11 = load ptr, ptr %6, align 8, !tbaa !17
  %12 = getelementptr inbounds i8, ptr %11, i64 32
  %13 = load ptr, ptr %12, align 8, !tbaa !18
  %14 = tail call i32 @sqlite3_stricmp(ptr noundef null, ptr noundef %13) #2
  %.not24.us = icmp eq i32 %14, 0
  br i1 %.not24.us, label %.split.us, label %.loopexit

.lr.ph.us:                                        ; preds = %.split.us, %24
  %.02030.us.us = phi i32 [ %25, %24 ], [ 0, %.split.us ]
  %15 = icmp ult i32 %.02030.us.us, 2
  %16 = zext i1 %15 to i32
  %17 = xor i32 %.02030.us.us, %16
  %18 = load ptr, ptr %6, align 8, !tbaa !17
  %19 = zext nneg i32 %17 to i64
  %20 = getelementptr inbounds %struct.Db, ptr %18, i64 %19, i32 4
  %21 = load ptr, ptr %20, align 8, !tbaa !20
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = tail call ptr @sqlite3HashFind(ptr noundef nonnull %22, ptr noundef %.021.us) #2
  %.not25.us.us = icmp eq ptr %23, null
  br i1 %.not25.us.us, label %24, label %.loopexit

24:                                               ; preds = %.lr.ph.us
  %25 = add nuw nsw i32 %.02030.us.us, 1
  %26 = load i32, ptr %4, align 8, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %.lr.ph.us, label %._crit_edge.split.us.us, !llvm.loop !21

.split:                                           ; preds = %3, %50
  %.021 = phi ptr [ @.str.1, %50 ], [ %1, %3 ]
  %28 = load i32, ptr %4, align 8, !tbaa !5
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %.lr.ph, label %._crit_edge.split

.lr.ph:                                           ; preds = %.split, %45
  %.02030 = phi i32 [ %46, %45 ], [ 0, %.split ]
  %30 = icmp ult i32 %.02030, 2
  %31 = zext i1 %30 to i32
  %32 = xor i32 %.02030, %31
  %33 = load ptr, ptr %6, align 8, !tbaa !17
  %34 = zext nneg i32 %32 to i64
  %35 = getelementptr inbounds %struct.Db, ptr %33, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !18
  %37 = tail call i32 @sqlite3StrICmp(ptr noundef nonnull %2, ptr noundef %36) #2
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %45

39:                                               ; preds = %.lr.ph
  %40 = load ptr, ptr %6, align 8, !tbaa !17
  %41 = getelementptr inbounds %struct.Db, ptr %40, i64 %34, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !20
  %43 = getelementptr inbounds i8, ptr %42, i64 8
  %44 = tail call ptr @sqlite3HashFind(ptr noundef nonnull %43, ptr noundef %.021) #2
  %.not25 = icmp eq ptr %44, null
  br i1 %.not25, label %45, label %.loopexit

45:                                               ; preds = %.lr.ph, %39
  %46 = add nuw nsw i32 %.02030, 1
  %47 = load i32, ptr %4, align 8, !tbaa !5
  %48 = icmp slt i32 %46, %47
  br i1 %48, label %.lr.ph, label %._crit_edge.split, !llvm.loop !21

._crit_edge.split:                                ; preds = %45, %.split
  %49 = tail call i32 @sqlite3StrICmp(ptr noundef %.021, ptr noundef nonnull @.str) #2
  %.not = icmp eq i32 %49, 0
  br i1 %.not, label %50, label %.loopexit

50:                                               ; preds = %._crit_edge.split
  %51 = load ptr, ptr %6, align 8, !tbaa !17
  %52 = getelementptr inbounds i8, ptr %51, i64 32
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = tail call i32 @sqlite3_stricmp(ptr noundef nonnull %2, ptr noundef %53) #2
  %.not24 = icmp eq i32 %54, 0
  br i1 %.not24, label %.split, label %.loopexit

.loopexit:                                        ; preds = %50, %._crit_edge.split, %39, %10, %._crit_edge.split.us.us, %.lr.ph.us
  %.3 = phi ptr [ %23, %.lr.ph.us ], [ null, %._crit_edge.split.us.us ], [ null, %10 ], [ %44, %39 ], [ null, %._crit_edge.split ], [ null, %50 ]
  ret ptr %.3
}

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

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

declare i32 @sqlite3_stricmp(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, !10, i64 40}
!6 = !{!"sqlite3", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !11, i64 48, !11, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !12, i64 80, !8, i64 82, !8, i64 83, !8, i64 84, !8, i64 85, !8, i64 86, !8, i64 87, !8, i64 88, !8, i64 89, !8, i64 90, !8, i64 91, !8, i64 92, !8, i64 93, !8, i64 94, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !8, i64 112, !10, i64 160, !13, i64 164, !10, i64 172, !10, i64 176, !10, i64 180, !10, i64 184, !10, i64 188, !10, i64 192, !7, i64 200, !7, i64 208, !7, i64 216, !7, i64 224, !7, i64 232, !7, i64 240, !7, i64 248, !7, i64 256, !7, i64 264, !7, i64 272, !7, i64 280, !7, i64 288, !7, i64 296, !7, i64 304, !7, i64 312, !7, i64 320, !7, i64 328, !8, i64 336, !14, i64 344, !7, i64 400, !7, i64 408, !7, i64 416, !7, i64 424, !10, i64 432, !10, i64 436, !15, i64 440, !7, i64 464, !7, i64 472, !7, i64 480, !15, i64 488, !15, i64 512, !16, i64 536, !8, i64 560, !7, i64 624, !10, i64 632, !10, i64 636, !10, i64 640, !11, i64 648, !11, i64 656, !7, i64 664}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long long", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"sqlite3InitInfo", !10, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7}
!14 = !{!"Lookaside", !10, i64 0, !12, i64 4, !8, i64 6, !10, i64 8, !10, i64 12, !8, i64 16, !7, i64 32, !7, i64 40, !7, i64 48}
!15 = !{!"Hash", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 16}
!16 = !{!"BusyHandler", !7, i64 0, !7, i64 8, !10, i64 16}
!17 = !{!6, !7, i64 32}
!18 = !{!19, !7, i64 0}
!19 = !{!"Db", !7, i64 0, !7, i64 8, !8, i64 16, !8, i64 17, !7, i64 24}
!20 = !{!19, !7, i64 24}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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