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

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

@stderr = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [78 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @read_ui64(ptr noundef, i64 noundef, i16 noundef zeroext) #0

declare i64 @store_alloc(ptr noundef, i64 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bstack_hdr_write(ptr noundef, i64 noundef, i8 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext, i64 noundef) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @bstack_add(ptr noundef %0, i64 noundef %1, i64 noundef %2) #4 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i16, align 2
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %28, label %14

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

19:                                               ; preds = %14
  br label %24

20:                                               ; preds = %14
  %21 = call ptr @__errno_location() #5
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = call ptr @strerror(i32 noundef %22) #6
  br label %24

24:                                               ; preds = %20, %19
  %25 = phi ptr [ @.str.6, %19 ], [ %23, %20 ]
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef @.str.4, ptr noundef @.str.5, i32 noundef 127, ptr noundef %25) #6
  %27 = call ptr @__errno_location() #5
  store i32 0, ptr %27, align 4, !tbaa !11
  br label %118

28:                                               ; preds = %3
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %45, label %31

31:                                               ; preds = %28
  %32 = load ptr, ptr @stderr, align 8, !tbaa !5
  %33 = call ptr @__errno_location() #5
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %31
  br label %41

37:                                               ; preds = %31
  %38 = call ptr @__errno_location() #5
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = call ptr @strerror(i32 noundef %39) #6
  br label %41

41:                                               ; preds = %37, %36
  %42 = phi ptr [ @.str.6, %36 ], [ %40, %37 ]
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str.7, ptr noundef @.str.5, i32 noundef 128, ptr noundef %42) #6
  %44 = call ptr @__errno_location() #5
  store i32 0, ptr %44, align 4, !tbaa !11
  br label %118

45:                                               ; preds = %28
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i64, ptr %6, align 8, !tbaa !9
  %48 = call i64 @read_ui64(ptr noundef %46, i64 noundef %47, i16 noundef zeroext 0)
  store i64 %48, ptr %8, align 8, !tbaa !9
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = call i64 @read_ui64(ptr noundef %49, i64 noundef %50, i16 noundef zeroext 8)
  store i64 %51, ptr %9, align 8, !tbaa !9
  %52 = load i64, ptr %8, align 8, !tbaa !9
  %53 = lshr i64 %52, 0
  %54 = and i64 %53, 65535
  %55 = trunc i64 %54 to i16
  store i16 %55, ptr %10, align 2, !tbaa !13
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = load i64, ptr %8, align 8, !tbaa !9
  %58 = lshr i64 %57, 32
  %59 = and i64 %58, 65535
  %60 = call i64 @store_alloc(ptr noundef %56, i64 noundef %59)
  store i64 %60, ptr %11, align 8, !tbaa !9
  %61 = load i64, ptr %8, align 8, !tbaa !9
  %62 = lshr i64 %61, 32
  %63 = and i64 %62, 65535
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = lshr i64 %64, 0
  %66 = and i64 %65, 65535
  %67 = sub i64 %63, %66
  %68 = icmp ult i64 %67, 8
  br i1 %68, label %69, label %84

69:                                               ; preds = %45
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load i64, ptr %11, align 8, !tbaa !9
  %72 = load i64, ptr %8, align 8, !tbaa !9
  %73 = lshr i64 %72, 56
  %74 = and i64 %73, 65535
  %75 = trunc i64 %74 to i8
  %76 = load i64, ptr %8, align 8, !tbaa !9
  %77 = lshr i64 %76, 32
  %78 = and i64 %77, 65535
  %79 = trunc i64 %78 to i16
  %80 = load i64, ptr %6, align 8, !tbaa !9
  call void @bstack_hdr_write(ptr noundef %70, i64 noundef %71, i8 noundef zeroext %75, i16 noundef zeroext %79, i16 noundef zeroext 1, i16 noundef zeroext 24, i64 noundef %80)
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load i64, ptr %11, align 8, !tbaa !9
  %83 = load i64, ptr %7, align 8, !tbaa !9
  call void @write_ui64(ptr noundef %81, i64 noundef %82, i16 noundef zeroext 16, i64 noundef %83)
  br label %116

84:                                               ; preds = %45
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = load i64, ptr %11, align 8, !tbaa !9
  %87 = load i64, ptr %8, align 8, !tbaa !9
  %88 = lshr i64 %87, 56
  %89 = and i64 %88, 65535
  %90 = trunc i64 %89 to i8
  %91 = load i64, ptr %8, align 8, !tbaa !9
  %92 = lshr i64 %91, 32
  %93 = and i64 %92, 65535
  %94 = trunc i64 %93 to i16
  %95 = load i64, ptr %8, align 8, !tbaa !9
  %96 = lshr i64 %95, 16
  %97 = and i64 %96, 65535
  %98 = add i64 %97, 1
  %99 = trunc i64 %98 to i16
  %100 = load i64, ptr %8, align 8, !tbaa !9
  %101 = lshr i64 %100, 0
  %102 = and i64 %101, 65535
  %103 = add i64 %102, 8
  %104 = trunc i64 %103 to i16
  %105 = load i64, ptr %9, align 8, !tbaa !9
  call void @bstack_hdr_write(ptr noundef %85, i64 noundef %86, i8 noundef zeroext %90, i16 noundef zeroext %94, i16 noundef zeroext %99, i16 noundef zeroext %104, i64 noundef %105)
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = load i64, ptr %11, align 8, !tbaa !9
  %108 = load i64, ptr %6, align 8, !tbaa !9
  %109 = load i16, ptr %10, align 2, !tbaa !13
  call void @copy(ptr noundef %106, i64 noundef %107, i16 noundef zeroext 16, i64 noundef %108, i16 noundef zeroext 16, i16 noundef zeroext %109)
  %110 = load ptr, ptr %5, align 8, !tbaa !5
  %111 = load i64, ptr %11, align 8, !tbaa !9
  %112 = load i16, ptr %10, align 2, !tbaa !13
  %113 = load i64, ptr %7, align 8, !tbaa !9
  call void @write_ui64(ptr noundef %110, i64 noundef %111, i16 noundef zeroext %112, i64 noundef %113)
  %114 = load ptr, ptr %5, align 8, !tbaa !5
  %115 = load i64, ptr %6, align 8, !tbaa !9
  call void @store_free(ptr noundef %114, i64 noundef %115)
  br label %116

116:                                              ; preds = %84, %69
  %117 = load i64, ptr %11, align 8, !tbaa !9
  store i64 %117, ptr %4, align 8
  br label %120

118:                                              ; preds = %41, %24
  %119 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %119, ptr %4, align 8
  br label %120

120:                                              ; preds = %118, %116
  %121 = load i64, ptr %4, align 8
  ret i64 %121
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @write_ui64(ptr noundef, i64 noundef, i16 noundef zeroext, i64 noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @copy(ptr noundef, i64 noundef, i16 noundef zeroext, i64 noundef, i16 noundef zeroext, i16 noundef zeroext) #0

declare void @store_free(ptr noundef, i64 noundef) #1

attributes #0 = { 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 #1 = { "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 = { 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 #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 = { nounwind willreturn memory(none) }
attributes #6 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [78 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @read_ui64(ptr noundef, i64 noundef, i16 noundef zeroext) local_unnamed_addr #0

declare i64 @store_alloc(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @bstack_hdr_write(ptr noundef, i64 noundef, i8 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext, i64 noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @bstack_add(ptr noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #5 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %14

4:                                                ; preds = %3
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = tail call ptr @__errno_location() #6
  %7 = load i32, ptr %6, align 4, !tbaa !9
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %11, label %9

9:                                                ; preds = %4
  %10 = tail call ptr @strerror(i32 noundef %7) #7
  br label %11

11:                                               ; preds = %4, %9
  %12 = phi ptr [ %10, %9 ], [ @.str.6, %4 ]
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.5, i32 noundef 127, ptr noundef %12) #8
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %47

14:                                               ; preds = %3
  %.not42 = icmp eq i64 %1, 0
  br i1 %.not42, label %15, label %25

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

20:                                               ; preds = %15
  %21 = tail call ptr @strerror(i32 noundef %18) #7
  br label %22

22:                                               ; preds = %15, %20
  %23 = phi ptr [ %21, %20 ], [ @.str.6, %15 ]
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.5, i32 noundef 128, ptr noundef %23) #8
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %47

25:                                               ; preds = %14
  %26 = tail call i64 @read_ui64(ptr noundef nonnull %0, i64 noundef %1, i16 noundef zeroext 0)
  %27 = tail call i64 @read_ui64(ptr noundef nonnull %0, i64 noundef %1, i16 noundef zeroext 8)
  %28 = and i64 %26, 65535
  %29 = lshr i64 %26, 32
  %30 = and i64 %29, 65535
  %31 = tail call i64 @store_alloc(ptr noundef nonnull %0, i64 noundef %30) #7
  %32 = sub nsw i64 %30, %28
  %33 = icmp ult i64 %32, 8
  br i1 %33, label %34, label %38

34:                                               ; preds = %25
  %35 = lshr i64 %26, 56
  %36 = trunc nuw i64 %35 to i8
  %37 = trunc i64 %29 to i16
  tail call void @bstack_hdr_write(ptr noundef nonnull %0, i64 noundef %31, i8 noundef zeroext %36, i16 noundef zeroext %37, i16 noundef zeroext 1, i16 noundef zeroext 24, i64 noundef %1)
  tail call void @write_ui64(ptr noundef nonnull %0, i64 noundef %31, i16 noundef zeroext 16, i64 noundef %2)
  br label %47

38:                                               ; preds = %25
  %39 = trunc i64 %26 to i16
  %40 = lshr i64 %26, 56
  %41 = trunc nuw i64 %40 to i8
  %42 = trunc i64 %29 to i16
  %43 = lshr i64 %26, 16
  %44 = trunc i64 %43 to i16
  %45 = add i16 %44, 1
  %46 = add i16 %39, 8
  tail call void @bstack_hdr_write(ptr noundef nonnull %0, i64 noundef %31, i8 noundef zeroext %41, i16 noundef zeroext %42, i16 noundef zeroext %45, i16 noundef zeroext %46, i64 noundef %27)
  tail call void @copy(ptr noundef nonnull %0, i64 noundef %31, i16 noundef zeroext 16, i64 noundef %1, i16 noundef zeroext 16, i16 noundef zeroext %39)
  tail call void @write_ui64(ptr noundef nonnull %0, i64 noundef %31, i16 noundef zeroext %39, i64 noundef %2)
  tail call void @store_free(ptr noundef nonnull %0, i64 noundef %1) #7
  br label %47

47:                                               ; preds = %11, %22, %34, %38
  %.0 = phi i64 [ %31, %38 ], [ %31, %34 ], [ 0, %22 ], [ %1, %11 ]
  ret i64 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @write_ui64(ptr noundef, i64 noundef, i16 noundef zeroext, i64 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @copy(ptr noundef, i64 noundef, i16 noundef zeroext, i64 noundef, i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #0

declare void @store_free(ptr noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { "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 = { 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 #3 = { 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 #4 = { 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 #5 = { 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 = { nounwind willreturn memory(none) }
attributes #7 = { nounwind }
attributes #8 = { 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, !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}


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