; LLVM IR from Mac-Rsh/mr-library :: source (service)

; 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.mr_ringbuf = type { ptr, i64, i32, i64, i64 }

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @mr_ringbuf_get_space_size(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @mr_ringbuf_push_force(ptr noundef %0, i8 noundef zeroext %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !10
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call i64 @mr_ringbuf_get_bufsz(ptr noundef %8)
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store i64 0, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %85

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i64 @mr_ringbuf_get_space_size(ptr noundef %13)
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %12
  store i32 1, ptr %6, align 4, !tbaa !10
  br label %17

17:                                               ; preds = %16, %12
  %18 = load i8, ptr %5, align 1, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.mr_ringbuf, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.mr_ringbuf, ptr %22, i32 0, i32 4
  %24 = load i64, ptr %23, align 8, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %21, i64 %24
  store i8 %18, ptr %25, align 1, !tbaa !9
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.mr_ringbuf, ptr %26, i32 0, i32 4
  %28 = load i64, ptr %27, align 8, !tbaa !15
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mr_ringbuf, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !16
  %32 = sub i64 %31, 1
  %33 = icmp eq i64 %28, %32
  br i1 %33, label %34, label %70

34:                                               ; preds = %17
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mr_ringbuf, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 8
  %38 = lshr i32 %37, 1
  %39 = and i32 %38, 1
  %40 = xor i32 %39, -1
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.mr_ringbuf, ptr %41, i32 0, i32 2
  %43 = load i32, ptr %42, align 8
  %44 = and i32 %40, 1
  %45 = shl i32 %44, 1
  %46 = and i32 %43, -3
  %47 = or i32 %46, %45
  store i32 %47, ptr %42, align 8
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.mr_ringbuf, ptr %48, i32 0, i32 4
  store i64 0, ptr %49, align 8, !tbaa !15
  %50 = load i32, ptr %6, align 4, !tbaa !10
  %51 = icmp eq i32 %50, 1
  br i1 %51, label %52, label %69

52:                                               ; preds = %34
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mr_ringbuf, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 8
  %56 = and i32 %55, 1
  %57 = xor i32 %56, -1
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.mr_ringbuf, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %59, align 8
  %61 = and i32 %57, 1
  %62 = and i32 %60, -2
  %63 = or i32 %62, %61
  store i32 %63, ptr %59, align 8
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.mr_ringbuf, ptr %64, i32 0, i32 4
  %66 = load i64, ptr %65, align 8, !tbaa !15
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.mr_ringbuf, ptr %67, i32 0, i32 3
  store i64 %66, ptr %68, align 8, !tbaa !17
  br label %69

69:                                               ; preds = %52, %34
  br label %84

70:                                               ; preds = %17
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.mr_ringbuf, ptr %71, i32 0, i32 4
  %73 = load i64, ptr %72, align 8, !tbaa !15
  %74 = add i64 %73, 1
  store i64 %74, ptr %72, align 8, !tbaa !15
  %75 = load i32, ptr %6, align 4, !tbaa !10
  %76 = icmp eq i32 %75, 1
  br i1 %76, label %77, label %83

77:                                               ; preds = %70
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.mr_ringbuf, ptr %78, i32 0, i32 4
  %80 = load i64, ptr %79, align 8, !tbaa !15
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.mr_ringbuf, ptr %81, i32 0, i32 3
  store i64 %80, ptr %82, align 8, !tbaa !17
  br label %83

83:                                               ; preds = %77, %70
  br label %84

84:                                               ; preds = %83, %69
  store i64 1, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %85

85:                                               ; preds = %84, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %86 = load i64, ptr %3, align 8
  ret i64 %86
}

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 2) i64 @mr_ringbuf_push_force(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = tail call i64 @mr_ringbuf_get_bufsz(ptr noundef %0)
  %4 = icmp eq i64 %3, 0
  br i1 %4, label %26, label %5

5:                                                ; preds = %2
  %6 = tail call i64 @mr_ringbuf_get_space_size(ptr noundef %0)
  %7 = icmp eq i64 %6, 0
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = load i64, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %8, i64 %10
  store i8 %1, ptr %11, align 1, !tbaa !13
  %12 = load i64, ptr %9, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !14
  %15 = add i64 %14, -1
  %16 = icmp eq i64 %12, %15
  br i1 %16, label %17, label %23

17:                                               ; preds = %5
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  %19 = load i32, ptr %18, align 8
  %20 = xor i32 %19, 2
  store i32 %20, ptr %18, align 8
  store i64 0, ptr %9, align 8, !tbaa !12
  br i1 %7, label %21, label %26

21:                                               ; preds = %17
  %22 = xor i32 %19, 3
  store i32 %22, ptr %18, align 8
  br label %.sink.split

23:                                               ; preds = %5
  %24 = add i64 %12, 1
  store i64 %24, ptr %9, align 8, !tbaa !12
  br i1 %7, label %.sink.split, label %26

.sink.split:                                      ; preds = %23, %21
  %.sink = phi i64 [ 0, %21 ], [ %24, %23 ]
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %.sink, ptr %25, align 8, !tbaa !15
  br label %26

26:                                               ; preds = %.sink.split, %17, %23, %2
  %.019 = phi i64 [ 0, %2 ], [ 1, %23 ], [ 1, %17 ], [ 1, %.sink.split ]
  ret i64 %.019
}

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


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