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

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

; Function Attrs: nounwind uwtable
define dso_local void @sqlite3ColumnDefault(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  %11 = 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
  store i32 %3, ptr %8, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Table, ptr %12, i32 0, i32 3
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = icmp ne ptr %14, null
  br i1 %15, label %43, label %16

16:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call ptr @sqlite3VdbeDb(ptr noundef %17)
  %19 = getelementptr inbounds %struct.sqlite3, ptr %18, i32 0, i32 14
  %20 = load i8, ptr %19, align 2, !tbaa !14
  store i8 %20, ptr %10, align 1, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Table, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !22
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds %struct.Column, ptr %23, i64 %25
  store ptr %26, ptr %11, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = call ptr @sqlite3VdbeDb(ptr noundef %27)
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Column, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !23
  %32 = load i8, ptr %10, align 1, !tbaa !21
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Column, ptr %33, i32 0, i32 4
  %35 = load i8, ptr %34, align 1, !tbaa !25
  %36 = call i32 @sqlite3ValueFromExpr(ptr noundef %28, ptr noundef %31, i8 noundef zeroext %32, i8 noundef zeroext %35, ptr noundef %9)
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %42

39:                                               ; preds = %16
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  call void @sqlite3VdbeAppendP4(ptr noundef %40, ptr noundef %41, i32 noundef -7)
  br label %42

42:                                               ; preds = %39, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %43

43:                                               ; preds = %42, %4
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Table, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !22
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds %struct.Column, ptr %46, i64 %48
  %50 = getelementptr inbounds %struct.Column, ptr %49, i32 0, i32 4
  %51 = load i8, ptr %50, align 1, !tbaa !25
  %52 = sext i8 %51 to i32
  %53 = icmp eq i32 %52, 69
  br i1 %53, label %54, label %58

54:                                               ; preds = %43
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = call i32 @sqlite3VdbeAddOp1(ptr noundef %55, i32 noundef 93, i32 noundef %56)
  br label %58

58:                                               ; preds = %54, %43
  ret void
}

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

declare ptr @sqlite3VdbeDb(ptr noundef) #2

declare i32 @sqlite3ValueFromExpr(ptr noundef, ptr noundef, i8 noundef zeroext, i8 noundef zeroext, ptr noundef) #2

declare void @sqlite3VdbeAppendP4(ptr noundef, ptr noundef, i32 noundef) #2

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 24}
!12 = !{!"Table", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !13, i64 68, !13, i64 70, !13, i64 72, !13, i64 74, !7, i64 76, !10, i64 80, !10, i64 84, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !7, i64 82}
!15 = !{!"sqlite3", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !16, i64 48, !16, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !13, 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, !17, 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, !18, i64 344, !6, i64 400, !6, i64 408, !6, i64 416, !6, i64 424, !10, i64 432, !10, i64 436, !19, i64 440, !6, i64 464, !6, i64 472, !6, i64 480, !19, i64 488, !19, i64 512, !20, i64 536, !7, i64 560, !6, i64 624, !10, i64 632, !10, i64 636, !10, i64 640, !16, i64 648, !16, i64 656, !6, i64 664}
!16 = !{!"long long", !7, i64 0}
!17 = !{!"sqlite3InitInfo", !10, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7}
!18 = !{!"Lookaside", !10, i64 0, !13, i64 4, !7, i64 6, !10, i64 8, !10, i64 12, !7, i64 16, !6, i64 32, !6, i64 40, !6, i64 48}
!19 = !{!"Hash", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!20 = !{!"BusyHandler", !6, i64 0, !6, i64 8, !10, i64 16}
!21 = !{!7, !7, i64 0}
!22 = !{!12, !6, i64 8}
!23 = !{!24, !6, i64 8}
!24 = !{!"Column", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27}
!25 = !{!24, !7, i64 25}


; 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.Column = type { ptr, ptr, ptr, i8, i8, i8, i8 }

; Function Attrs: nounwind uwtable
define dso_local void @sqlite3ColumnDefault(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca ptr, align 8
  %6 = getelementptr inbounds i8, ptr %1, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %8, label %._crit_edge

._crit_edge:                                      ; preds = %4
  %.pre = sext i32 %2 to i64
  br label %25

8:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  store ptr null, ptr %5, align 8, !tbaa !12
  %9 = tail call ptr @sqlite3VdbeDb(ptr noundef %0) #3
  %10 = getelementptr inbounds i8, ptr %9, i64 82
  %11 = load i8, ptr %10, align 2, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !20
  %14 = sext i32 %2 to i64
  %15 = getelementptr inbounds %struct.Column, ptr %13, i64 %14
  %16 = tail call ptr @sqlite3VdbeDb(ptr noundef %0) #3
  %17 = getelementptr inbounds i8, ptr %15, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !21
  %19 = getelementptr inbounds i8, ptr %15, i64 25
  %20 = load i8, ptr %19, align 1, !tbaa !23
  %21 = call i32 @sqlite3ValueFromExpr(ptr noundef %16, ptr noundef %18, i8 noundef zeroext %11, i8 noundef zeroext %20, ptr noundef nonnull %5) #3
  %22 = load ptr, ptr %5, align 8, !tbaa !12
  %.not12 = icmp eq ptr %22, null
  br i1 %.not12, label %24, label %23

23:                                               ; preds = %8
  call void @sqlite3VdbeAppendP4(ptr noundef %0, ptr noundef nonnull %22, i32 noundef -7) #3
  br label %24

24:                                               ; preds = %23, %8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  br label %25

25:                                               ; preds = %._crit_edge, %24
  %.pre-phi = phi i64 [ %.pre, %._crit_edge ], [ %14, %24 ]
  %26 = getelementptr inbounds i8, ptr %1, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !20
  %28 = getelementptr inbounds %struct.Column, ptr %27, i64 %.pre-phi, i32 4
  %29 = load i8, ptr %28, align 1, !tbaa !23
  %30 = icmp eq i8 %29, 69
  br i1 %30, label %31, label %33

31:                                               ; preds = %25
  %32 = call i32 @sqlite3VdbeAddOp1(ptr noundef %0, i32 noundef 93, i32 noundef %3) #3
  br label %33

33:                                               ; preds = %31, %25
  ret void
}

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

declare ptr @sqlite3VdbeDb(ptr noundef) local_unnamed_addr #2

declare i32 @sqlite3ValueFromExpr(ptr noundef, ptr noundef, i8 noundef zeroext, i8 noundef zeroext, ptr noundef) local_unnamed_addr #2

declare void @sqlite3VdbeAppendP4(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

declare i32 @sqlite3VdbeAddOp1(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 24}
!6 = !{!"Table", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !11, i64 68, !11, i64 70, !11, i64 72, !11, i64 74, !8, i64 76, !10, i64 80, !10, i64 84, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !8, i64 82}
!14 = !{!"sqlite3", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !15, i64 48, !15, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !11, 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, !16, 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, !17, i64 344, !7, i64 400, !7, i64 408, !7, i64 416, !7, i64 424, !10, i64 432, !10, i64 436, !18, i64 440, !7, i64 464, !7, i64 472, !7, i64 480, !18, i64 488, !18, i64 512, !19, i64 536, !8, i64 560, !7, i64 624, !10, i64 632, !10, i64 636, !10, i64 640, !15, i64 648, !15, i64 656, !7, i64 664}
!15 = !{!"long long", !8, i64 0}
!16 = !{!"sqlite3InitInfo", !10, i64 0, !8, i64 4, !8, i64 5, !8, i64 6, !8, i64 7}
!17 = !{!"Lookaside", !10, i64 0, !11, i64 4, !8, i64 6, !10, i64 8, !10, i64 12, !8, i64 16, !7, i64 32, !7, i64 40, !7, i64 48}
!18 = !{!"Hash", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 16}
!19 = !{!"BusyHandler", !7, i64 0, !7, i64 8, !10, i64 16}
!20 = !{!6, !7, i64 8}
!21 = !{!22, !7, i64 8}
!22 = !{!"Column", !7, i64 0, !7, i64 8, !7, i64 16, !8, i64 24, !8, i64 25, !8, i64 26, !8, i64 27}
!23 = !{!22, !8, i64 25}


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