; LLVM IR from adventure-db/adventure :: src/db/store (store)

; 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.store = type { [6 x i8], i64, ptr, ptr, i64 }
%struct.fs_map = type { ptr, ptr, i64 }

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [35 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #2

; Function Attrs: nounwind
declare ptr @strerror(i32 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
declare void @free(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @store_extend(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i64 @store_alloc(ptr noundef %0, i64 noundef %1) #3 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.store, ptr %11, i32 0, i32 2
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %struct.fs_map, ptr %13, i32 0, i32 2
  %15 = load i64, ptr %14, align 8, !tbaa !13
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.store, ptr %16, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !15
  %19 = sub i64 %15, %18
  store i64 %19, ptr %6, align 8, !tbaa !9
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = icmp ugt i64 %20, %21
  br i1 %22, label %23, label %45

23:                                               ; preds = %2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = call i32 @store_extend(ptr noundef %24)
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %41, label %27

27:                                               ; preds = %23
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = call ptr @__errno_location() #7
  %30 = load i32, ptr %29, align 4, !tbaa !16
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  br label %37

33:                                               ; preds = %27
  %34 = call ptr @__errno_location() #7
  %35 = load i32, ptr %34, align 4, !tbaa !16
  %36 = call ptr @strerror(i32 noundef %35) #6
  br label %37

37:                                               ; preds = %33, %32
  %38 = phi ptr [ @.str.2, %32 ], [ %36, %33 ]
  %39 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 112, ptr noundef %38) #6
  %40 = call ptr @__errno_location() #7
  store i32 0, ptr %40, align 4, !tbaa !16
  br label %82

41:                                               ; preds = %23
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load i64, ptr %5, align 8, !tbaa !9
  %44 = call i64 @store_alloc(ptr noundef %42, i64 noundef %43)
  store i64 %44, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %83

45:                                               ; preds = %2
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.store, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !18
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %56

50:                                               ; preds = %45
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.store, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = call i64 @list_count(ptr noundef %53)
  %55 = icmp ne i64 %54, 0
  br i1 %55, label %70, label %56

56:                                               ; preds = %50, %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.store, ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !15
  store i64 %59, ptr %8, align 8, !tbaa !9
  %60 = load i64, ptr %5, align 8, !tbaa !9
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.store, ptr %61, i32 0, i32 1
  %63 = load i64, ptr %62, align 8, !tbaa !15
  %64 = add i64 %63, %60
  store i64 %64, ptr %62, align 8, !tbaa !15
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.store, ptr %66, i32 0, i32 1
  %68 = load i64, ptr %67, align 8, !tbaa !15
  call void @store_write_ui64(ptr noundef %65, i64 noundef 6, i64 noundef %68)
  %69 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %69, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %83

70:                                               ; preds = %50
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.store, ptr %71, i32 0, i32 3
  %73 = load ptr, ptr %72, align 8, !tbaa !18
  %74 = call ptr @list_shift(ptr noundef %73)
  store ptr %74, ptr %9, align 8, !tbaa !5
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = load i64, ptr %75, align 8, !tbaa !9
  store i64 %76, ptr %10, align 8, !tbaa !9
  %77 = load ptr, ptr @stderr, align 8, !tbaa !5
  %78 = load i64, ptr %10, align 8, !tbaa !9
  %79 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %77, ptr noundef @.str.7, ptr noundef @.str.1, i32 noundef 126, i64 noundef %78) #6
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %80) #6
  %81 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %81, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %83

82:                                               ; preds = %37
  store i64 0, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %83

83:                                               ; preds = %82, %70, %56, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %84 = load i64, ptr %3, align 8
  ret i64 %84
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @list_count(ptr noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare void @store_write_ui64(ptr noundef, i64 noundef, i64 noundef) #4

declare ptr @list_shift(ptr noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 willreturn memory(none) "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 #3 = { 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 #4 = { inlinehint 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 #5 = { "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(none) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"store", !7, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !10, i64 32}
!13 = !{!14, !10, i64 16}
!14 = !{!"fs_map", !6, i64 0, !6, i64 8, !10, i64 16}
!15 = !{!12, !10, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [56 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #1

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @store_extend(ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local i64 @store_alloc(ptr noundef %0, i64 noundef %1) local_unnamed_addr #4 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  br label %tailrecurse

tailrecurse:                                      ; preds = %11, %2
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %8 = load i64, ptr %4, align 8, !tbaa !13
  %9 = sub i64 %7, %8
  %10 = icmp ult i64 %9, %1
  br i1 %10, label %11, label %24

11:                                               ; preds = %tailrecurse
  %12 = tail call i32 @store_extend(ptr noundef nonnull %0)
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %tailrecurse, label %14

14:                                               ; preds = %11
  %15 = load ptr, ptr @stderr, align 8, !tbaa !14
  %16 = tail call ptr @__errno_location() #7
  %17 = load i32, ptr %16, align 4, !tbaa !15
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %21, label %19

19:                                               ; preds = %14
  %20 = tail call ptr @strerror(i32 noundef %17) #8
  br label %21

21:                                               ; preds = %14, %19
  %22 = phi ptr [ %20, %19 ], [ @.str.2, %14 ]
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i32 noundef 112, ptr noundef %22) #9
  store i32 0, ptr %16, align 4, !tbaa !15
  br label %38

24:                                               ; preds = %tailrecurse
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %.not = icmp eq ptr %26, null
  br i1 %.not, label %29, label %27

27:                                               ; preds = %24
  %28 = tail call i64 @list_count(ptr noundef nonnull %26)
  %.not23 = icmp eq i64 %28, 0
  br i1 %.not23, label %._crit_edge, label %32

._crit_edge:                                      ; preds = %27
  %.pre = load i64, ptr %4, align 8, !tbaa !13
  br label %29

29:                                               ; preds = %._crit_edge, %24
  %30 = phi i64 [ %.pre, %._crit_edge ], [ %8, %24 ]
  %31 = add i64 %30, %1
  store i64 %31, ptr %4, align 8, !tbaa !13
  tail call void @store_write_ui64(ptr noundef nonnull %0, i64 noundef 6, i64 noundef %31)
  br label %38

32:                                               ; preds = %27
  %33 = load ptr, ptr %25, align 8, !tbaa !17
  %34 = tail call ptr @list_shift(ptr noundef %33) #8
  %35 = load i64, ptr %34, align 8, !tbaa !18
  %36 = load ptr, ptr @stderr, align 8, !tbaa !14
  %37 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.1, i32 noundef 126, i64 noundef %35) #9
  tail call void @free(ptr noundef %34) #8
  br label %38

38:                                               ; preds = %21, %32, %29
  %.0 = phi i64 [ 0, %21 ], [ %35, %32 ], [ %30, %29 ]
  ret i64 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @list_count(ptr noundef) local_unnamed_addr #5

; Function Attrs: inlinehint nounwind uwtable
declare void @store_write_ui64(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #5

declare ptr @list_shift(ptr noundef) local_unnamed_addr #6

attributes #0 = { nofree nounwind "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 #1 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 "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 #3 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #4 = { 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 #5 = { inlinehint 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 #6 = { "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 #7 = { nounwind willreturn memory(none) }
attributes #8 = { nounwind }
attributes #9 = { cold 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, !10, i64 16}
!6 = !{!"store", !7, i64 0, !9, i64 8, !10, i64 16, !10, i64 24, !9, i64 32}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !9, i64 16}
!12 = !{!"fs_map", !10, i64 0, !10, i64 8, !9, i64 16}
!13 = !{!6, !9, i64 8}
!14 = !{!10, !10, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!6, !10, i64 24}
!18 = !{!9, !9, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass