; LLVM IR from MaJerle/lwpkt :: libs/lwrb/src/lwrb (lwrb)

; 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.lwrb = type { ptr, i64, i64, i64, 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
define dso_local i64 @lwrb_get_linear_block_read_length(ptr noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %22

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.lwrb, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %22

17:                                               ; preds = %12
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.lwrb, ptr %18, i32 0, i32 1
  %20 = load i64, ptr %19, align 8, !tbaa !12
  %21 = icmp ugt i64 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %17, %12, %1
  store i64 0, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %53

23:                                               ; preds = %17
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.lwrb, ptr %24, i32 0, i32 3
  %26 = load atomic i64, ptr %25 monotonic, align 8
  store i64 %26, ptr %8, align 8
  %27 = load i64, ptr %8, align 8, !tbaa !13
  store volatile i64 %27, ptr %5, align 8, !tbaa !13
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.lwrb, ptr %28, i32 0, i32 2
  %30 = load atomic i64, ptr %29 monotonic, align 8
  store i64 %30, ptr %9, align 8
  %31 = load i64, ptr %9, align 8, !tbaa !13
  store volatile i64 %31, ptr %6, align 8, !tbaa !13
  %32 = load volatile i64, ptr %5, align 8, !tbaa !13
  %33 = load volatile i64, ptr %6, align 8, !tbaa !13
  %34 = icmp ugt i64 %32, %33
  br i1 %34, label %35, label %39

35:                                               ; preds = %23
  %36 = load volatile i64, ptr %5, align 8, !tbaa !13
  %37 = load volatile i64, ptr %6, align 8, !tbaa !13
  %38 = sub i64 %36, %37
  store i64 %38, ptr %4, align 8, !tbaa !13
  br label %51

39:                                               ; preds = %23
  %40 = load volatile i64, ptr %6, align 8, !tbaa !13
  %41 = load volatile i64, ptr %5, align 8, !tbaa !13
  %42 = icmp ugt i64 %40, %41
  br i1 %42, label %43, label %49

43:                                               ; preds = %39
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.lwrb, ptr %44, i32 0, i32 1
  %46 = load i64, ptr %45, align 8, !tbaa !12
  %47 = load volatile i64, ptr %6, align 8, !tbaa !13
  %48 = sub i64 %46, %47
  store i64 %48, ptr %4, align 8, !tbaa !13
  br label %50

49:                                               ; preds = %39
  store i64 0, ptr %4, align 8, !tbaa !13
  br label %50

50:                                               ; preds = %49, %43
  br label %51

51:                                               ; preds = %50, %35
  %52 = load i64, ptr %4, align 8, !tbaa !13
  store i64 %52, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %53

53:                                               ; preds = %51, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %54 = load i64, ptr %2, align 8
  ret i64 %54
}

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, !6, i64 0}
!10 = !{!"lwrb", !6, i64 0, !11, i64 8, !7, i64 16, !7, i64 24, !6, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, 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"

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nofree norecurse nounwind memory(argmem: readwrite, inaccessiblemem: readwrite) uwtable
define dso_local i64 @lwrb_get_linear_block_read_length(ptr noundef readonly %0) local_unnamed_addr #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3)
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %21, label %4

4:                                                ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %.not18 = icmp eq ptr %5, null
  br i1 %.not18, label %21, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !11
  %.not19 = icmp eq i64 %8, 0
  br i1 %.not19, label %21, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load atomic i64, ptr %10 monotonic, align 8
  store volatile i64 %11, ptr %2, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load atomic i64, ptr %12 monotonic, align 8
  store volatile i64 %13, ptr %3, align 8, !tbaa !12
  %.0..0..0..0.5 = load volatile i64, ptr %2, align 8, !tbaa !12
  %.0..0..0..0. = load volatile i64, ptr %3, align 8, !tbaa !12
  %14 = icmp ugt i64 %.0..0..0..0.5, %.0..0..0..0.
  br i1 %14, label %15, label %17

15:                                               ; preds = %9
  %.0..0..0..0.6 = load volatile i64, ptr %2, align 8, !tbaa !12
  %.0..0..0..0.2 = load volatile i64, ptr %3, align 8, !tbaa !12
  %16 = sub i64 %.0..0..0..0.6, %.0..0..0..0.2
  br label %21

17:                                               ; preds = %9
  %.0..0..0..0.3 = load volatile i64, ptr %3, align 8, !tbaa !12
  %.0..0..0..0.7 = load volatile i64, ptr %2, align 8, !tbaa !12
  %18 = icmp ugt i64 %.0..0..0..0.3, %.0..0..0..0.7
  br i1 %18, label %19, label %21

19:                                               ; preds = %17
  %.0..0..0..0.4 = load volatile i64, ptr %3, align 8, !tbaa !12
  %20 = sub i64 %8, %.0..0..0..0.4
  br label %21

21:                                               ; preds = %15, %19, %17, %1, %4, %6
  %.0 = phi i64 [ 0, %6 ], [ 0, %4 ], [ 0, %1 ], [ %16, %15 ], [ %20, %19 ], [ 0, %17 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2)
  ret i64 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree norecurse nounwind memory(argmem: readwrite, inaccessiblemem: readwrite) 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 0}
!6 = !{!"lwrb", !7, i64 0, !10, i64 8, !8, i64 16, !8, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!10, !10, i64 0}


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