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

; 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

declare i32 @sqlite3VdbeAddOp3(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

declare i32 @sqlite3VdbeAddOp2(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @sqlite3ExprCodeGetColumnOfTable(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %13 = load i32, ptr %9, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %22, label %15

15:                                               ; preds = %5
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Table, ptr %17, i32 0, i32 10
  %19 = load i16, ptr %18, align 4, !tbaa !11
  %20 = sext i16 %19 to i32
  %21 = icmp eq i32 %16, %20
  br i1 %21, label %22, label %27

22:                                               ; preds = %15, %5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = call i32 @sqlite3VdbeAddOp2(ptr noundef %23, i32 noundef 123, i32 noundef %24, i32 noundef %25)
  br label %59

27:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Table, ptr %28, i32 0, i32 16
  %30 = load i32, ptr %29, align 4, !tbaa !14
  %31 = icmp ne i32 %30, 0
  %32 = zext i1 %31 to i64
  %33 = select i1 %31, i32 157, i32 98
  store i32 %33, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %34 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %34, ptr %12, align 4, !tbaa !9
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Table, ptr %35, i32 0, i32 9
  %37 = load i32, ptr %36, align 8, !tbaa !15
  %38 = and i32 %37, 32
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %52, label %40

40:                                               ; preds = %27
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Table, ptr %41, i32 0, i32 16
  %43 = load i32, ptr %42, align 4, !tbaa !14
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %52, label %45

45:                                               ; preds = %40
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = call ptr @sqlite3PrimaryKeyIndex(ptr noundef %46)
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = trunc i32 %48 to i16
  %50 = call signext i16 @sqlite3ColumnOfIndex(ptr noundef %47, i16 noundef signext %49)
  %51 = sext i16 %50 to i32
  store i32 %51, ptr %12, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %45, %40, %27
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = load i32, ptr %12, align 4, !tbaa !9
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = call i32 @sqlite3VdbeAddOp3(ptr noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef %56, i32 noundef %57)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %59

59:                                               ; preds = %52, %22
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = icmp sge i32 %60, 0
  br i1 %61, label %62, label %67

62:                                               ; preds = %59
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = load i32, ptr %10, align 4, !tbaa !9
  call void @sqlite3ColumnDefault(ptr noundef %63, ptr noundef %64, i32 noundef %65, i32 noundef %66)
  br label %67

67:                                               ; preds = %62, %59
  ret void
}

declare signext i16 @sqlite3ColumnOfIndex(ptr noundef, i16 noundef signext) #1

declare ptr @sqlite3PrimaryKeyIndex(ptr noundef) #1

declare void @sqlite3ColumnDefault(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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, !13, i64 68}
!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 = !{!12, !10, i64 84}
!15 = !{!12, !10, i64 64}


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

declare i32 @sqlite3VdbeAddOp3(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare i32 @sqlite3VdbeAddOp2(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @sqlite3ExprCodeGetColumnOfTable(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = icmp slt i32 %3, 0
  br i1 %6, label %27, label %7

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %1, i64 68
  %9 = load i16, ptr %8, align 4, !tbaa !5
  %10 = sext i16 %9 to i32
  %11 = icmp eq i32 %10, %3
  br i1 %11, label %.thread22, label %13

.thread22:                                        ; preds = %7
  %12 = tail call i32 @sqlite3VdbeAddOp2(ptr noundef %0, i32 noundef 123, i32 noundef %2, i32 noundef %4) #2
  br label %29

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %1, i64 84
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %.not = icmp ne i32 %15, 0
  %16 = select i1 %.not, i32 157, i32 98
  %17 = getelementptr inbounds i8, ptr %1, i64 64
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = and i32 %18, 32
  %20 = icmp eq i32 %19, 0
  %brmerge = select i1 %20, i1 true, i1 %.not
  br i1 %brmerge, label %.thread, label %21

21:                                               ; preds = %13
  %22 = tail call ptr @sqlite3PrimaryKeyIndex(ptr noundef nonnull %1) #2
  %23 = trunc i32 %3 to i16
  %24 = tail call signext i16 @sqlite3ColumnOfIndex(ptr noundef %22, i16 noundef signext %23) #2
  %25 = sext i16 %24 to i32
  br label %.thread

.thread:                                          ; preds = %21, %13
  %.0 = phi i32 [ %3, %13 ], [ %25, %21 ]
  %26 = tail call i32 @sqlite3VdbeAddOp3(ptr noundef %0, i32 noundef %16, i32 noundef %2, i32 noundef %.0, i32 noundef %4) #2
  br label %29

27:                                               ; preds = %5
  %28 = tail call i32 @sqlite3VdbeAddOp2(ptr noundef %0, i32 noundef 123, i32 noundef %2, i32 noundef %4) #2
  br label %30

29:                                               ; preds = %.thread22, %.thread
  tail call void @sqlite3ColumnDefault(ptr noundef %0, ptr noundef nonnull %1, i32 noundef %3, i32 noundef %4) #2
  br label %30

30:                                               ; preds = %27, %29
  ret void
}

declare signext i16 @sqlite3ColumnOfIndex(ptr noundef, i16 noundef signext) local_unnamed_addr #0

declare ptr @sqlite3PrimaryKeyIndex(ptr noundef) local_unnamed_addr #0

declare void @sqlite3ColumnDefault(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

attributes #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 = { 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, !11, i64 68}
!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 = !{!6, !10, i64 84}
!13 = !{!6, !10, i64 64}


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