; LLVM IR from ElsevierSoftwareX/SOFTX-D-20-00016 :: GameplayFootball/src/libs/sqlite3 (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, i32, ptr, i32, i32, i32, i32, i8, i8, i8, i8, i8, i8, i32, i32, ptr, i64, i32, i32, i32, ptr, [11 x i32], %struct.sqlite3InitInfo, i32, ptr, ptr, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %union.anon, %struct.Lookaside, ptr, ptr, ptr, ptr, i32, %struct.Hash, ptr, ptr, i32, ptr, %struct.FuncDefHash, %struct.Hash, %struct.BusyHandler, i32, [2 x %struct.Db], ptr, i32, i32, i8, i64, ptr }
%struct.sqlite3InitInfo = type { i32, i32, i8, i8 }
%union.anon = type { double }
%struct.Lookaside = type { i16, i8, i8, i32, i32, ptr, ptr, ptr }
%struct.FuncDefHash = type { [23 x ptr] }
%struct.Hash = type { i32, i32, ptr, ptr }
%struct.BusyHandler = type { ptr, ptr, i32 }
%struct.Db = type { ptr, ptr, i8, i8, ptr }

@.str.28 = 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: 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 void @sqlite3_mutex_enter(ptr noundef) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sqlite3_wal_checkpoint(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 10, ptr %6, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.sqlite3, ptr %7, i32 0, i32 20
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  call void @sqlite3_mutex_enter(ptr noundef %9)
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %22

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 0
  %15 = load i8, ptr %14, align 1, !tbaa !20
  %16 = sext i8 %15 to i32
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %22

18:                                               ; preds = %12
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call i32 @sqlite3FindDbName(ptr noundef %19, ptr noundef %20)
  store i32 %21, ptr %6, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %18, %12, %2
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %22
  store i32 1, ptr %5, align 4, !tbaa !9
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  call void (ptr, i32, ptr, ...) @sqlite3Error(ptr noundef %26, i32 noundef 1, ptr noundef @.str.28, ptr noundef %27)
  br label %34

28:                                               ; preds = %22
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = call i32 @sqlite3Checkpoint(ptr noundef %29, i32 noundef %30)
  store i32 %31, ptr %5, align 4, !tbaa !9
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !9
  call void (ptr, i32, ptr, ...) @sqlite3Error(ptr noundef %32, i32 noundef %33, ptr noundef null)
  br label %34

34:                                               ; preds = %28, %25
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = call i32 @sqlite3ApiExit(ptr noundef %35, i32 noundef %36)
  store i32 %37, ptr %5, align 4, !tbaa !9
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.sqlite3, ptr %38, i32 0, i32 20
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  call void @sqlite3_mutex_leave(ptr noundef %40)
  %41 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %41
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @sqlite3Checkpoint(ptr 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, !6, i64 88}
!12 = !{!"sqlite3", !6, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !7, i64 40, !7, i64 41, !7, i64 42, !7, i64 43, !7, i64 44, !7, i64 45, !10, i64 48, !10, i64 52, !6, i64 56, !13, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !6, i64 88, !7, i64 96, !14, i64 140, !10, i64 152, !6, i64 160, !6, i64 168, !10, i64 176, !10, i64 180, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, 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, !7, i64 328, !15, i64 336, !6, i64 376, !6, i64 384, !6, i64 392, !6, i64 400, !10, i64 408, !17, i64 416, !6, i64 440, !6, i64 448, !10, i64 456, !6, i64 464, !18, i64 472, !17, i64 656, !19, i64 680, !10, i64 704, !7, i64 712, !6, i64 776, !10, i64 784, !10, i64 788, !7, i64 792, !13, i64 800, !6, i64 808}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"sqlite3InitInfo", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 9}
!15 = !{!"Lookaside", !16, i64 0, !7, i64 2, !7, i64 3, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!16 = !{!"short", !7, i64 0}
!17 = !{!"Hash", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!18 = !{!"FuncDefHash", !7, i64 0}
!19 = !{!"BusyHandler", !6, i64 0, !6, i64 8, !10, i64 16}
!20 = !{!7, !7, i64 0}


; 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.28 = 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 @sqlite3Error(ptr noundef, i32 noundef, ptr 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
define dso_local i32 @sqlite3_wal_checkpoint(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 88
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @sqlite3_mutex_enter(ptr noundef %4)
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %.thread, label %5

5:                                                ; preds = %2
  %6 = load i8, ptr %1, align 1, !tbaa !18
  %.not17 = icmp eq i8 %6, 0
  br i1 %.not17, label %.thread, label %7

7:                                                ; preds = %5
  %8 = tail call i32 @sqlite3FindDbName(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %9 = icmp slt i32 %8, 0
  br i1 %9, label %10, label %.thread

10:                                               ; preds = %7
  tail call void (ptr, i32, ptr, ...) @sqlite3Error(ptr noundef nonnull %0, i32 noundef 1, ptr noundef nonnull @.str.28, ptr noundef nonnull %1)
  br label %12

.thread:                                          ; preds = %2, %5, %7
  %.019 = phi i32 [ %8, %7 ], [ 10, %5 ], [ 10, %2 ]
  %11 = tail call i32 @sqlite3Checkpoint(ptr noundef nonnull %0, i32 noundef %.019)
  tail call void (ptr, i32, ptr, ...) @sqlite3Error(ptr noundef nonnull %0, i32 noundef %11, ptr noundef null)
  br label %12

12:                                               ; preds = %.thread, %10
  %.015 = phi i32 [ 1, %10 ], [ %11, %.thread ]
  %13 = tail call i32 @sqlite3ApiExit(ptr noundef nonnull %0, i32 noundef %.015)
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @sqlite3_mutex_leave(ptr noundef %14)
  ret i32 %13
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @sqlite3Checkpoint(ptr 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, !7, i64 88}
!6 = !{!"sqlite3", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !8, i64 40, !8, i64 41, !8, i64 42, !8, i64 43, !8, i64 44, !8, i64 45, !10, i64 48, !10, i64 52, !7, i64 56, !11, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !7, i64 88, !8, i64 96, !12, i64 140, !10, i64 152, !7, i64 160, !7, i64 168, !10, i64 176, !10, i64 180, !7, i64 184, !7, i64 192, !7, i64 200, !7, i64 208, !7, i64 216, !7, i64 224, !7, i64 232, !7, i64 240, !7, i64 248, !7, i64 256, !7, i64 264, !7, i64 272, !7, i64 280, !7, i64 288, !7, i64 296, !7, i64 304, !7, i64 312, !7, i64 320, !8, i64 328, !13, i64 336, !7, i64 376, !7, i64 384, !7, i64 392, !7, i64 400, !10, i64 408, !15, i64 416, !7, i64 440, !7, i64 448, !10, i64 456, !7, i64 464, !16, i64 472, !15, i64 656, !17, i64 680, !10, i64 704, !8, i64 712, !7, i64 776, !10, i64 784, !10, i64 788, !8, i64 792, !11, i64 800, !7, i64 808}
!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 = !{!"sqlite3InitInfo", !10, i64 0, !10, i64 4, !8, i64 8, !8, i64 9}
!13 = !{!"Lookaside", !14, i64 0, !8, i64 2, !8, i64 3, !10, i64 4, !10, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!14 = !{!"short", !8, i64 0}
!15 = !{!"Hash", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 16}
!16 = !{!"FuncDefHash", !8, i64 0}
!17 = !{!"BusyHandler", !7, i64 0, !7, i64 8, !10, i64 16}
!18 = !{!8, !8, i64 0}


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