; 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: 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 i32 @sqlite3ExprIsInteger(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %48

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Expr, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = and i32 %15, 1024
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %23

18:                                               ; preds = %12
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Expr, ptr %19, i32 0, i32 3
  %21 = load i32, ptr %20, align 8, !tbaa !14
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %21, ptr %22, align 4, !tbaa !9
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %48

23:                                               ; preds = %12
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Expr, ptr %24, i32 0, i32 0
  %26 = load i8, ptr %25, align 8, !tbaa !15
  %27 = zext i8 %26 to i32
  switch i32 %27, label %45 [
    i32 156, label %28
    i32 155, label %34
  ]

28:                                               ; preds = %23
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Expr, ptr %29, i32 0, i32 4
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = call i32 @sqlite3ExprIsInteger(ptr noundef %31, ptr noundef %32)
  store i32 %33, ptr %6, align 4, !tbaa !9
  br label %46

34:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Expr, ptr %35, i32 0, i32 4
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = call i32 @sqlite3ExprIsInteger(ptr noundef %37, ptr noundef %8)
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %44

40:                                               ; preds = %34
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = sub nsw i32 0, %41
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %42, ptr %43, align 4, !tbaa !9
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %40, %34
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %46

45:                                               ; preds = %23
  br label %46

46:                                               ; preds = %45, %44, %28
  %47 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %47, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %48

48:                                               ; preds = %46, %18, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %49 = load i32, ptr %3, align 4
  ret i32 %49
}

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, !10, i64 4}
!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 = !{!7, !7, i64 0}
!15 = !{!12, !7, i64 0}
!16 = !{!12, !6, i64 16}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nofree nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @sqlite3ExprIsInteger(ptr noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #1 {
  %3 = alloca i32, align 4
  %4 = icmp eq ptr %0, null
  br i1 %4, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %2, %tailrecurse
  %.tr16 = phi ptr [ %14, %tailrecurse ], [ %0, %2 ]
  %5 = getelementptr inbounds i8, ptr %.tr16, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = and i32 %6, 1024
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %11, label %8

8:                                                ; preds = %.lr.ph
  %9 = getelementptr inbounds i8, ptr %.tr16, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !12
  store i32 %10, ptr %1, align 4, !tbaa !13
  br label %.loopexit

11:                                               ; preds = %.lr.ph
  %12 = load i8, ptr %.tr16, align 8, !tbaa !14
  switch i8 %12, label %.loopexit [
    i8 -100, label %tailrecurse
    i8 -101, label %16
  ]

tailrecurse:                                      ; preds = %11
  %13 = getelementptr inbounds i8, ptr %.tr16, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = icmp eq ptr %14, null
  br i1 %15, label %.loopexit, label %.lr.ph

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  %17 = getelementptr inbounds i8, ptr %.tr16, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = call i32 @sqlite3ExprIsInteger(ptr noundef %18, ptr noundef nonnull %3)
  %.not12 = icmp eq i32 %19, 0
  br i1 %.not12, label %23, label %20

20:                                               ; preds = %16
  %21 = load i32, ptr %3, align 4, !tbaa !13
  %22 = sub nsw i32 0, %21
  store i32 %22, ptr %1, align 4, !tbaa !13
  br label %23

23:                                               ; preds = %20, %16
  %.0 = phi i32 [ 1, %20 ], [ 0, %16 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  br label %.loopexit

.loopexit:                                        ; preds = %tailrecurse, %11, %2, %23, %8
  %.010 = phi i32 [ 1, %8 ], [ %.0, %23 ], [ 0, %2 ], [ 0, %11 ], [ 0, %tailrecurse ]
  ret i32 %.010
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !9, i64 4}
!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 = !{!7, !7, i64 0}
!13 = !{!9, !9, i64 0}
!14 = !{!6, !7, i64 0}
!15 = !{!6, !10, i64 16}


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