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

; 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.Pager = type { ptr, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, i64, i64, ptr, ptr, i32, i32, [16 x i8], i32, i64, ptr, i16, i16, i32, i32, i32, i32, i64, ptr, ptr, ptr, ptr, [3 x i32], ptr, ptr, ptr, ptr, ptr, ptr }
%struct.sqlite3_file = 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
declare hidden i32 @pager_error(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @setGetterMethod(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @pager_playback(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @pager_end_transaction(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @sqlite3PagerRollback(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.Pager, ptr %8, i32 0, i32 14
  %10 = load i8, ptr %9, align 1, !tbaa !11
  %11 = zext i8 %10 to i32
  %12 = icmp eq i32 %11, 6
  br i1 %12, label %13, label %17

13:                                               ; preds = %1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Pager, ptr %14, i32 0, i32 26
  %16 = load i32, ptr %15, align 8, !tbaa !15
  store i32 %16, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %89

17:                                               ; preds = %1
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.Pager, ptr %18, i32 0, i32 14
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = zext i8 %20 to i32
  %22 = icmp sle i32 %21, 1
  br i1 %22, label %23, label %24

23:                                               ; preds = %17
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %89

24:                                               ; preds = %17
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Pager, ptr %25, i32 0, i32 60
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %43

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = call i32 @sqlite3PagerSavepoint(ptr noundef %30, i32 noundef 2, i32 noundef -1)
  store i32 %31, ptr %4, align 4, !tbaa !9
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Pager, ptr %33, i32 0, i32 17
  %35 = load i8, ptr %34, align 8, !tbaa !17
  %36 = zext i8 %35 to i32
  %37 = call i32 @pager_end_transaction(ptr noundef %32, i32 noundef %36, i32 noundef 0)
  store i32 %37, ptr %6, align 4, !tbaa !9
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %42

40:                                               ; preds = %29
  %41 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %41, ptr %4, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %40, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %85

43:                                               ; preds = %24
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Pager, ptr %44, i32 0, i32 32
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = getelementptr inbounds %struct.sqlite3_file, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !19
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %56

50:                                               ; preds = %43
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.Pager, ptr %51, i32 0, i32 14
  %53 = load i8, ptr %52, align 1, !tbaa !11
  %54 = zext i8 %53 to i32
  %55 = icmp eq i32 %54, 2
  br i1 %55, label %56, label %81

56:                                               ; preds = %50, %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.Pager, ptr %57, i32 0, i32 14
  %59 = load i8, ptr %58, align 1, !tbaa !11
  %60 = zext i8 %59 to i32
  store i32 %60, ptr %7, align 4, !tbaa !9
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = call i32 @pager_end_transaction(ptr noundef %61, i32 noundef 0, i32 noundef 0)
  store i32 %62, ptr %4, align 4, !tbaa !9
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Pager, ptr %63, i32 0, i32 13
  %65 = load i8, ptr %64, align 4, !tbaa !21
  %66 = icmp ne i8 %65, 0
  br i1 %66, label %77, label %67

67:                                               ; preds = %56
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = icmp sgt i32 %68, 2
  br i1 %69, label %70, label %77

70:                                               ; preds = %67
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.Pager, ptr %71, i32 0, i32 26
  store i32 4, ptr %72, align 8, !tbaa !15
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.Pager, ptr %73, i32 0, i32 14
  store i8 6, ptr %74, align 1, !tbaa !11
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  call void @setGetterMethod(ptr noundef %75)
  %76 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %76, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %78

77:                                               ; preds = %67, %56
  store i32 0, ptr %5, align 4
  br label %78

78:                                               ; preds = %77, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %79 = load i32, ptr %5, align 4
  switch i32 %79, label %89 [
    i32 0, label %80
  ]

80:                                               ; preds = %78
  br label %84

81:                                               ; preds = %50
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = call i32 @pager_playback(ptr noundef %82, i32 noundef 0)
  store i32 %83, ptr %4, align 4, !tbaa !9
  br label %84

84:                                               ; preds = %81, %80
  br label %85

85:                                               ; preds = %84, %42
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = load i32, ptr %4, align 4, !tbaa !9
  %88 = call i32 @pager_error(ptr noundef %86, i32 noundef %87)
  store i32 %88, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %89

89:                                               ; preds = %85, %78, %23, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %90 = load i32, ptr %2, align 4
  ret i32 %90
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @sqlite3PagerSavepoint(ptr noundef, i32 noundef, i32 noundef) #1

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 21}
!12 = !{!"Pager", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 19, !7, i64 20, !7, i64 21, !7, i64 22, !7, i64 23, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !7, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !13, i64 96, !13, i64 104, !6, i64 112, !6, i64 120, !10, i64 128, !10, i64 132, !7, i64 136, !10, i64 152, !13, i64 160, !6, i64 168, !14, i64 176, !14, i64 178, !10, i64 180, !10, i64 184, !10, i64 188, !10, i64 192, !13, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !7, i64 240, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !10, i64 48}
!16 = !{!12, !6, i64 288}
!17 = !{!12, !7, i64 24}
!18 = !{!12, !6, i64 80}
!19 = !{!20, !6, i64 0}
!20 = !{!"sqlite3_file", !6, i64 0}
!21 = !{!12, !7, i64 20}


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

; Function Attrs: nounwind uwtable
declare hidden void @setGetterMethod(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @pager_playback(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @pager_end_transaction(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @sqlite3PagerRollback(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 21
  %3 = load i8, ptr %2, align 1, !tbaa !5
  %4 = icmp eq i8 %3, 6
  br i1 %4, label %5, label %8

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %7 = load i32, ptr %6, align 8, !tbaa !13
  br label %35

8:                                                ; preds = %1
  %9 = icmp ult i8 %3, 2
  br i1 %9, label %35, label %10

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %0, i64 288
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %20, label %13

13:                                               ; preds = %10
  %14 = tail call i32 @sqlite3PagerSavepoint(ptr noundef nonnull %0, i32 noundef 2, i32 noundef -1)
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load i8, ptr %15, align 8, !tbaa !15
  %17 = zext i8 %16 to i32
  %18 = tail call i32 @pager_end_transaction(ptr noundef nonnull %0, i32 noundef %17, i32 noundef 0)
  %19 = icmp eq i32 %14, 0
  %spec.select = select i1 %19, i32 %18, i32 %14
  br label %.critedge

20:                                               ; preds = %10
  %21 = getelementptr inbounds i8, ptr %0, i64 80
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = load ptr, ptr %22, align 8, !tbaa !17
  %.not28 = icmp eq ptr %23, null
  %24 = icmp eq i8 %3, 2
  %or.cond = or i1 %24, %.not28
  br i1 %or.cond, label %25, label %32

25:                                               ; preds = %20
  %26 = tail call i32 @pager_end_transaction(ptr noundef nonnull %0, i32 noundef 0, i32 noundef 0)
  %27 = getelementptr inbounds i8, ptr %0, i64 20
  %28 = load i8, ptr %27, align 4, !tbaa !19
  %29 = icmp ne i8 %28, 0
  %or.cond.not = or i1 %24, %29
  br i1 %or.cond.not, label %.critedge, label %30

30:                                               ; preds = %25
  %31 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 4, ptr %31, align 8, !tbaa !13
  store i8 6, ptr %2, align 1, !tbaa !5
  tail call void @setGetterMethod(ptr noundef nonnull %0)
  br label %35

32:                                               ; preds = %20
  %33 = tail call i32 @pager_playback(ptr noundef nonnull %0, i32 noundef 0)
  br label %.critedge

.critedge:                                        ; preds = %25, %32, %13
  %.125 = phi i32 [ %spec.select, %13 ], [ %33, %32 ], [ %26, %25 ]
  %34 = tail call i32 @pager_error(ptr noundef nonnull %0, i32 noundef %.125)
  br label %35

35:                                               ; preds = %30, %8, %.critedge, %5
  %.1 = phi i32 [ %7, %5 ], [ %34, %.critedge ], [ %26, %30 ], [ 0, %8 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @sqlite3PagerSavepoint(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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, !8, i64 21}
!6 = !{!"Pager", !7, i64 0, !8, i64 8, !8, i64 9, !8, i64 10, !8, i64 11, !8, i64 12, !8, i64 13, !8, i64 14, !8, i64 15, !8, i64 16, !8, i64 17, !8, i64 18, !8, i64 19, !8, i64 20, !8, i64 21, !8, i64 22, !8, i64 23, !8, i64 24, !8, i64 25, !8, i64 26, !8, i64 27, !8, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !11, i64 96, !11, i64 104, !7, i64 112, !7, i64 120, !10, i64 128, !10, i64 132, !8, i64 136, !10, i64 152, !11, i64 160, !7, i64 168, !12, i64 176, !12, i64 178, !10, i64 180, !10, i64 184, !10, i64 188, !10, i64 192, !11, i64 200, !7, i64 208, !7, i64 216, !7, i64 224, !7, i64 232, !8, i64 240, !7, i64 256, !7, i64 264, !7, i64 272, !7, i64 280, !7, i64 288, !7, i64 296}
!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 = !{!6, !10, i64 48}
!14 = !{!6, !7, i64 288}
!15 = !{!6, !8, i64 24}
!16 = !{!6, !7, i64 80}
!17 = !{!18, !7, i64 0}
!18 = !{!"sqlite3_file", !7, i64 0}
!19 = !{!6, !8, i64 20}


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