; LLVM IR from HassenSaidi/IC_sqlite :: src (sqlite3)

; 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.sqlite3 = type { ptr, ptr, ptr, ptr, ptr, i32, i32, i64, i64, i64, i32, 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, %union.anon, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %union.anon.0, %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, i32, i64, i64, ptr }
%struct.sqlite3InitInfo = type { i32, i8, i8, i8, ptr }
%union.anon = type { ptr }
%union.anon.0 = type { double }
%struct.Lookaside = type { i32, i16, i16, i8, i32, [3 x i32], ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.Hash = type { i32, i32, ptr, ptr }
%struct.BusyHandler = type { ptr, ptr, i32 }
%struct.Db = type { ptr, ptr, i8, i8, ptr }

@.str.27 = external hidden unnamed_addr constant [21 x i8], align 1

; 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 void @sqlite3_mutex_enter(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @sqlite3_mutex_leave(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 hidden void @sqlite3ErrorWithMsg(ptr noundef, i32 noundef, ptr noundef, ...) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sqlite3_wal_checkpoint_v2(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store i32 10, ptr %13, align 4, !tbaa !9
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %20

18:                                               ; preds = %5
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 -1, ptr %19, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %18, %5
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %25

23:                                               ; preds = %20
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 -1, ptr %24, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %23, %20
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %31, label %28

28:                                               ; preds = %25
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = icmp sgt i32 %29, 3
  br i1 %30, label %31, label %32

31:                                               ; preds = %28, %25
  store i32 21, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %83

32:                                               ; preds = %28
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.sqlite3, ptr %33, i32 0, i32 3
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  call void @sqlite3_mutex_enter(ptr noundef %35)
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %48

38:                                               ; preds = %32
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 0
  %41 = load i8, ptr %40, align 1, !tbaa !19
  %42 = sext i8 %41 to i32
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %48

44:                                               ; preds = %38
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = call i32 @sqlite3FindDbName(ptr noundef %45, ptr noundef %46)
  store i32 %47, ptr %13, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %44, %38, %32
  %49 = load i32, ptr %13, align 4, !tbaa !9
  %50 = icmp slt i32 %49, 0
  br i1 %50, label %51, label %54

51:                                               ; preds = %48
  store i32 1, ptr %12, align 4, !tbaa !9
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  call void (ptr, i32, ptr, ...) @sqlite3ErrorWithMsg(ptr noundef %52, i32 noundef 1, ptr noundef @.str.27, ptr noundef %53)
  br label %66

54:                                               ; preds = %48
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.sqlite3, ptr %55, i32 0, i32 74
  %57 = getelementptr inbounds %struct.BusyHandler, ptr %56, i32 0, i32 2
  store i32 0, ptr %57, align 8, !tbaa !20
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load i32, ptr %13, align 4, !tbaa !9
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = call i32 @sqlite3Checkpoint(ptr noundef %58, i32 noundef %59, i32 noundef %60, ptr noundef %61, ptr noundef %62)
  store i32 %63, ptr %12, align 4, !tbaa !9
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = load i32, ptr %12, align 4, !tbaa !9
  call void @sqlite3Error(ptr noundef %64, i32 noundef %65)
  br label %66

66:                                               ; preds = %54, %51
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = load i32, ptr %12, align 4, !tbaa !9
  %69 = call i32 @sqlite3ApiExit(ptr noundef %67, i32 noundef %68)
  store i32 %69, ptr %12, align 4, !tbaa !9
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.sqlite3, ptr %70, i32 0, i32 36
  %72 = load i32, ptr %71, align 8, !tbaa !21
  %73 = icmp eq i32 %72, 0
  br i1 %73, label %74, label %78

74:                                               ; preds = %66
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.sqlite3, ptr %75, i32 0, i32 60
  store i32 0, ptr %15, align 4, !tbaa !9
  %77 = load i32, ptr %15, align 4
  store atomic volatile i32 %77, ptr %76 monotonic, align 8
  br label %78

78:                                               ; preds = %74, %66
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.sqlite3, ptr %79, i32 0, i32 3
  %81 = load ptr, ptr %80, align 8, !tbaa !11
  call void @sqlite3_mutex_leave(ptr noundef %81)
  %82 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %82, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %83

83:                                               ; preds = %78, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %84 = load i32, ptr %6, align 4
  ret i32 %84
}

; Function Attrs: nounwind uwtable
declare hidden i32 @sqlite3Checkpoint(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr 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, !6, i64 24}
!12 = !{!"sqlite3", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !13, i64 48, !13, i64 56, !13, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !14, i64 92, !7, i64 94, !7, i64 95, !7, i64 96, !7, i64 97, !7, i64 98, !7, i64 99, !7, i64 100, !7, i64 101, !7, i64 102, !7, i64 103, !7, i64 104, !7, i64 105, !7, i64 106, !10, i64 108, !10, i64 112, !10, i64 116, !10, i64 120, !7, i64 124, !10, i64 172, !15, i64 176, !10, i64 192, !10, i64 196, !10, i64 200, !10, i64 204, !10, i64 208, !10, i64 212, !6, i64 216, !7, 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, !6, i64 336, !6, i64 344, !6, i64 352, !7, i64 360, !16, i64 368, !6, i64 456, !6, i64 464, !6, i64 472, !6, i64 480, !10, i64 488, !10, i64 492, !17, i64 496, !6, i64 520, !6, i64 528, !6, i64 536, !17, i64 544, !17, i64 568, !18, i64 592, !7, i64 616, !6, i64 680, !10, i64 688, !10, i64 692, !10, i64 696, !10, i64 700, !13, i64 704, !13, i64 712, !6, i64 720}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"sqlite3InitInfo", !10, i64 0, !7, i64 4, !7, i64 5, !10, i64 6, !10, i64 6, !10, i64 6, !6, i64 8}
!16 = !{!"Lookaside", !10, i64 0, !14, i64 4, !14, i64 6, !7, i64 8, !10, i64 12, !7, i64 16, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80}
!17 = !{!"Hash", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!18 = !{!"BusyHandler", !6, i64 0, !6, i64 8, !10, i64 16}
!19 = !{!7, !7, i64 0}
!20 = !{!12, !10, i64 608}
!21 = !{!12, !10, i64 192}


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

@.str.27 = external hidden unnamed_addr constant [21 x i8], align 1

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sqlite3_wal_checkpoint_v2(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %7, label %6

6:                                                ; preds = %5
  store i32 -1, ptr %3, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %6, %5
  %.not36 = icmp eq ptr %4, null
  br i1 %.not36, label %9, label %8

8:                                                ; preds = %7
  store i32 -1, ptr %4, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %8, %7
  %or.cond = icmp ugt i32 %2, 3
  br i1 %or.cond, label %30, label %10

10:                                               ; preds = %9
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  tail call void @sqlite3_mutex_enter(ptr noundef %12)
  %.not37 = icmp eq ptr %1, null
  br i1 %.not37, label %.thread, label %13

13:                                               ; preds = %10
  %14 = load i8, ptr %1, align 1, !tbaa !18
  %.not38 = icmp eq i8 %14, 0
  br i1 %.not38, label %.thread, label %15

15:                                               ; preds = %13
  %16 = tail call i32 @sqlite3FindDbName(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %.thread

18:                                               ; preds = %15
  tail call void (ptr, i32, ptr, ...) @sqlite3ErrorWithMsg(ptr noundef nonnull %0, i32 noundef 1, ptr noundef nonnull @.str.27, ptr noundef nonnull %1)
  br label %21

.thread:                                          ; preds = %10, %13, %15
  %.03040 = phi i32 [ %16, %15 ], [ 10, %13 ], [ 10, %10 ]
  %19 = getelementptr inbounds i8, ptr %0, i64 608
  store i32 0, ptr %19, align 8, !tbaa !19
  %20 = tail call i32 @sqlite3Checkpoint(ptr noundef nonnull %0, i32 noundef %.03040, i32 noundef %2, ptr noundef %3, ptr noundef %4)
  tail call void @sqlite3Error(ptr noundef nonnull %0, i32 noundef %20)
  br label %21

21:                                               ; preds = %.thread, %18
  %.031 = phi i32 [ 1, %18 ], [ %20, %.thread ]
  %22 = tail call i32 @sqlite3ApiExit(ptr noundef nonnull %0, i32 noundef %.031)
  %23 = getelementptr inbounds i8, ptr %0, i64 192
  %24 = load i32, ptr %23, align 8, !tbaa !20
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %21
  %27 = getelementptr inbounds i8, ptr %0, i64 360
  store atomic volatile i32 0, ptr %27 monotonic, align 8
  br label %28

28:                                               ; preds = %26, %21
  %29 = load ptr, ptr %11, align 8, !tbaa !9
  tail call void @sqlite3_mutex_leave(ptr noundef %29)
  br label %30

30:                                               ; preds = %9, %28
  %.0 = phi i32 [ %22, %28 ], [ 21, %9 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @sqlite3Checkpoint(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 24}
!10 = !{!"sqlite3", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !6, i64 40, !6, i64 44, !12, i64 48, !12, i64 56, !12, i64 64, !6, i64 72, !6, i64 76, !6, i64 80, !6, i64 84, !6, i64 88, !13, i64 92, !7, i64 94, !7, i64 95, !7, i64 96, !7, i64 97, !7, i64 98, !7, i64 99, !7, i64 100, !7, i64 101, !7, i64 102, !7, i64 103, !7, i64 104, !7, i64 105, !7, i64 106, !6, i64 108, !6, i64 112, !6, i64 116, !6, i64 120, !7, i64 124, !6, i64 172, !14, i64 176, !6, i64 192, !6, i64 196, !6, i64 200, !6, i64 204, !6, i64 208, !6, i64 212, !11, i64 216, !7, i64 224, !11, i64 232, !11, i64 240, !11, i64 248, !11, i64 256, !11, i64 264, !11, i64 272, !11, i64 280, !11, i64 288, !11, i64 296, !11, i64 304, !11, i64 312, !11, i64 320, !11, i64 328, !11, i64 336, !11, i64 344, !11, i64 352, !7, i64 360, !15, i64 368, !11, i64 456, !11, i64 464, !11, i64 472, !11, i64 480, !6, i64 488, !6, i64 492, !16, i64 496, !11, i64 520, !11, i64 528, !11, i64 536, !16, i64 544, !16, i64 568, !17, i64 592, !7, i64 616, !11, i64 680, !6, i64 688, !6, i64 692, !6, i64 696, !6, i64 700, !12, i64 704, !12, i64 712, !11, i64 720}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"sqlite3InitInfo", !6, i64 0, !7, i64 4, !7, i64 5, !6, i64 6, !6, i64 6, !6, i64 6, !11, i64 8}
!15 = !{!"Lookaside", !6, i64 0, !13, i64 4, !13, i64 6, !7, i64 8, !6, i64 12, !7, i64 16, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80}
!16 = !{!"Hash", !6, i64 0, !6, i64 4, !11, i64 8, !11, i64 16}
!17 = !{!"BusyHandler", !11, i64 0, !11, i64 8, !6, i64 16}
!18 = !{!7, !7, i64 0}
!19 = !{!10, !6, i64 608}
!20 = !{!10, !6, i64 192}


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