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

; Function Attrs: nounwind uwtable
define dso_local i32 @sqlite3ExprImpliesExpr(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  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
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = call i32 @sqlite3ExprCompare(ptr noundef %10, ptr noundef %11, i32 noundef %12)
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store i32 1, ptr %4, align 4
  br label %75

16:                                               ; preds = %3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Expr, ptr %17, i32 0, i32 0
  %19 = load i8, ptr %18, align 8, !tbaa !11
  %20 = zext i8 %19 to i32
  %21 = icmp eq i32 %20, 27
  br i1 %21, label %22, label %39

22:                                               ; preds = %16
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Expr, ptr %24, i32 0, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = call i32 @sqlite3ExprImpliesExpr(ptr noundef %23, ptr noundef %26, i32 noundef %27)
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %38, label %30

30:                                               ; preds = %22
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Expr, ptr %32, i32 0, i32 5
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = call i32 @sqlite3ExprImpliesExpr(ptr noundef %31, ptr noundef %34, i32 noundef %35)
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %30, %22
  store i32 1, ptr %4, align 4
  br label %75

39:                                               ; preds = %30, %16
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.Expr, ptr %40, i32 0, i32 0
  %42 = load i8, ptr %41, align 8, !tbaa !11
  %43 = zext i8 %42 to i32
  %44 = icmp eq i32 %43, 35
  br i1 %44, label %45, label %74

45:                                               ; preds = %39
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Expr, ptr %46, i32 0, i32 0
  %48 = load i8, ptr %47, align 8, !tbaa !11
  %49 = zext i8 %48 to i32
  %50 = icmp ne i32 %49, 34
  br i1 %50, label %51, label %74

51:                                               ; preds = %45
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Expr, ptr %52, i32 0, i32 0
  %54 = load i8, ptr %53, align 8, !tbaa !11
  %55 = zext i8 %54 to i32
  %56 = icmp ne i32 %55, 29
  br i1 %56, label %57, label %74

57:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.Expr, ptr %58, i32 0, i32 4
  %60 = load ptr, ptr %59, align 8, !tbaa !14
  %61 = call ptr @sqlite3ExprSkipCollate(ptr noundef %60)
  store ptr %61, ptr %8, align 8, !tbaa !5
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Expr, ptr %63, i32 0, i32 4
  %65 = load ptr, ptr %64, align 8, !tbaa !14
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = call i32 @sqlite3ExprCompare(ptr noundef %62, ptr noundef %65, i32 noundef %66)
  %68 = icmp eq i32 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %57
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %71

70:                                               ; preds = %57
  store i32 0, ptr %9, align 4
  br label %71

71:                                               ; preds = %70, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %72 = load i32, ptr %9, align 4
  switch i32 %72, label %77 [
    i32 0, label %73
    i32 1, label %75
  ]

73:                                               ; preds = %71
  br label %74

74:                                               ; preds = %73, %51, %45, %39
  store i32 0, ptr %4, align 4
  br label %75

75:                                               ; preds = %74, %71, %38, %15
  %76 = load i32, ptr %4, align 4
  ret i32 %76

77:                                               ; preds = %71
  unreachable
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"Expr", !7, i64 0, !7, i64 1, !10, i64 4, !7, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !13, i64 48, !13, i64 50, !13, i64 52, !7, i64 54, !6, i64 56, !6, i64 64}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !6, i64 24}


; 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 @sqlite3ExprCompare(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @sqlite3ExprImpliesExpr(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @sqlite3ExprCompare(ptr noundef %0, ptr noundef %1, i32 noundef %2)
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %30, label %6

6:                                                ; preds = %3
  %7 = load i8, ptr %1, align 8, !tbaa !5
  %8 = icmp eq i8 %7, 27
  br i1 %8, label %9, label %17

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = tail call i32 @sqlite3ExprImpliesExpr(ptr noundef %0, ptr noundef %11, i32 noundef %2)
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %30

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %1, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = tail call i32 @sqlite3ExprImpliesExpr(ptr noundef %0, ptr noundef %15, i32 noundef %2)
  %.not20 = icmp eq i32 %16, 0
  br i1 %.not20, label %thread-pre-split, label %30

thread-pre-split:                                 ; preds = %13
  %.pr = load i8, ptr %1, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %thread-pre-split, %6
  %18 = phi i8 [ %.pr, %thread-pre-split ], [ %7, %6 ]
  %19 = icmp eq i8 %18, 35
  br i1 %19, label %20, label %29

20:                                               ; preds = %17
  %21 = load i8, ptr %0, align 8, !tbaa !5
  switch i8 %21, label %22 [
    i8 34, label %29
    i8 29, label %29
  ]

22:                                               ; preds = %20
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = tail call ptr @sqlite3ExprSkipCollate(ptr noundef %24)
  %26 = getelementptr inbounds i8, ptr %1, i64 16
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %28 = tail call i32 @sqlite3ExprCompare(ptr noundef %25, ptr noundef %27, i32 noundef %2)
  %.not23 = icmp eq i32 %28, 0
  br i1 %.not23, label %30, label %29

29:                                               ; preds = %22, %20, %20, %17
  br label %30

30:                                               ; preds = %22, %9, %13, %3, %29
  %.1 = phi i32 [ 1, %22 ], [ 0, %29 ], [ 1, %3 ], [ 1, %13 ], [ 1, %9 ]
  ret i32 %.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" }

!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 = !{!"Expr", !7, i64 0, !7, i64 1, !9, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !9, i64 40, !9, i64 44, !11, i64 48, !11, i64 50, !11, i64 52, !7, i64 54, !10, i64 56, !10, i64 64}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!6, !10, i64 16}
!13 = !{!6, !10, i64 24}


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