; LLVM IR from turi-code/SFrame :: oss_src/graphlab/util (safe_circular_char_buffer)

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

%"class.graphlab::safe_circular_char_buffer" = type <{ ptr, i64, i64, i64, %"class.graphlab::mutex", %"class.graphlab::conditional", i8, i8, [6 x i8] }>
%"class.graphlab::mutex" = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"class.graphlab::conditional" = type { %union.pthread_cond_t }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { 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: inlinehint mustprogress uwtable
declare dso_local void @_ZNK8graphlab5mutex4lockEv(ptr noundef nonnull align 8 dereferenceable(40)) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK8graphlab5mutex6unlockEv(ptr noundef nonnull align 8 dereferenceable(40)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK8graphlab25safe_circular_char_buffer5emptyEv(ptr noundef nonnull align 8 dereferenceable(122)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN8graphlab25safe_circular_char_buffer18introspective_readERPcl(ptr noundef nonnull align 8 dereferenceable(122), ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN8graphlab25safe_circular_char_buffer27blocking_introspective_readERPcl(ptr noundef nonnull align 8 dereferenceable(122) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, i64 noundef %2) #3 align 2 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = load i64, ptr %7, align 8, !tbaa !9
  %14 = call noundef i64 @_ZN8graphlab25safe_circular_char_buffer18introspective_readERPcl(ptr noundef nonnull align 8 dereferenceable(122) %11, ptr noundef nonnull align 8 dereferenceable(8) %12, i64 noundef %13)
  store i64 %14, ptr %8, align 8, !tbaa !9
  %15 = load i64, ptr %8, align 8, !tbaa !9
  %16 = icmp ne i64 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %3
  %18 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %18, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %55

19:                                               ; preds = %3
  br label %20

20:                                               ; preds = %54, %19
  br label %21

21:                                               ; preds = %20
  %22 = getelementptr inbounds %"class.graphlab::safe_circular_char_buffer", ptr %11, i32 0, i32 7
  store volatile i8 1, ptr %22, align 1, !tbaa !11
  %23 = getelementptr inbounds %"class.graphlab::safe_circular_char_buffer", ptr %11, i32 0, i32 4
  call void @_ZNK8graphlab5mutex4lockEv(ptr noundef nonnull align 8 dereferenceable(40) %23)
  br label %24

24:                                               ; preds = %33, %21
  %25 = call noundef zeroext i1 @_ZNK8graphlab25safe_circular_char_buffer5emptyEv(ptr noundef nonnull align 8 dereferenceable(122) %11)
  br i1 %25, label %26, label %31

26:                                               ; preds = %24
  %27 = getelementptr inbounds %"class.graphlab::safe_circular_char_buffer", ptr %11, i32 0, i32 6
  %28 = load volatile i8, ptr %27, align 8, !tbaa !16, !range !17, !noundef !18
  %29 = trunc i8 %28 to i1
  %30 = xor i1 %29, true
  br label %31

31:                                               ; preds = %26, %24
  %32 = phi i1 [ false, %24 ], [ %30, %26 ]
  br i1 %32, label %33, label %36

33:                                               ; preds = %31
  %34 = getelementptr inbounds %"class.graphlab::safe_circular_char_buffer", ptr %11, i32 0, i32 5
  %35 = getelementptr inbounds %"class.graphlab::safe_circular_char_buffer", ptr %11, i32 0, i32 4
  call void @_ZNK8graphlab11conditional4waitERKNS_5mutexE(ptr noundef nonnull align 8 dereferenceable(48) %34, ptr noundef nonnull align 8 dereferenceable(40) %35)
  br label %24, !llvm.loop !19

36:                                               ; preds = %31
  %37 = getelementptr inbounds %"class.graphlab::safe_circular_char_buffer", ptr %11, i32 0, i32 7
  store volatile i8 0, ptr %37, align 1, !tbaa !11
  %38 = getelementptr inbounds %"class.graphlab::safe_circular_char_buffer", ptr %11, i32 0, i32 4
  call void @_ZNK8graphlab5mutex6unlockEv(ptr noundef nonnull align 8 dereferenceable(40) %38)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = call noundef i64 @_ZN8graphlab25safe_circular_char_buffer18introspective_readERPcl(ptr noundef nonnull align 8 dereferenceable(122) %11, ptr noundef nonnull align 8 dereferenceable(8) %39, i64 noundef %40)
  store i64 %41, ptr %10, align 8, !tbaa !9
  %42 = load i64, ptr %10, align 8, !tbaa !9
  %43 = icmp ne i64 %42, 0
  br i1 %43, label %44, label %46

44:                                               ; preds = %36
  %45 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %45, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %52

46:                                               ; preds = %36
  %47 = getelementptr inbounds %"class.graphlab::safe_circular_char_buffer", ptr %11, i32 0, i32 6
  %48 = load volatile i8, ptr %47, align 8, !tbaa !16, !range !17, !noundef !18
  %49 = trunc i8 %48 to i1
  br i1 %49, label %50, label %51

50:                                               ; preds = %46
  store i64 0, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %52

51:                                               ; preds = %46
  store i32 0, ptr %9, align 4
  br label %52

52:                                               ; preds = %51, %50, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %53 = load i32, ptr %9, align 4
  switch i32 %53, label %55 [
    i32 0, label %54
  ]

54:                                               ; preds = %52
  br label %20, !llvm.loop !21

55:                                               ; preds = %52, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %56 = load i64, ptr %4, align 8
  ret i64 %56
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK8graphlab11conditional4waitERKNS_5mutexE(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(40)) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress 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 = { mustprogress 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 #3 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !15, i64 121}
!12 = !{!"_ZTSN8graphlab25safe_circular_char_bufferE", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !13, i64 32, !14, i64 72, !15, i64 120, !15, i64 121}
!13 = !{!"_ZTSN8graphlab5mutexE", !7, i64 0}
!14 = !{!"_ZTSN8graphlab11conditionalE", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!12, !15, i64 120}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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: inlinehint mustprogress uwtable
declare dso_local void @_ZNK8graphlab5mutex4lockEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK8graphlab5mutex6unlockEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK8graphlab25safe_circular_char_buffer5emptyEv(ptr noundef nonnull align 8 dereferenceable(122)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN8graphlab25safe_circular_char_buffer18introspective_readERPcl(ptr noundef nonnull align 8 dereferenceable(122), ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN8graphlab25safe_circular_char_buffer27blocking_introspective_readERPcl(ptr noundef nonnull align 8 dereferenceable(122) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, i64 noundef %2) local_unnamed_addr #2 align 2 {
  %4 = tail call noundef i64 @_ZN8graphlab25safe_circular_char_buffer18introspective_readERPcl(ptr noundef nonnull align 8 dereferenceable(122) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, i64 noundef %2)
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %.preheader, label %.thread

.preheader:                                       ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 121
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = getelementptr inbounds i8, ptr %0, i64 120
  %8 = getelementptr inbounds i8, ptr %0, i64 72
  br label %9

9:                                                ; preds = %.preheader, %16
  store volatile i8 1, ptr %5, align 1, !tbaa !5
  tail call void @_ZNK8graphlab5mutex4lockEv(ptr noundef nonnull align 8 dereferenceable(40) %6)
  %10 = tail call noundef zeroext i1 @_ZNK8graphlab25safe_circular_char_buffer5emptyEv(ptr noundef nonnull align 8 dereferenceable(122) %0)
  br i1 %10, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %9, %13
  %11 = load volatile i8, ptr %7, align 8, !tbaa !14, !range !15, !noundef !16
  %12 = trunc nuw i8 %11 to i1
  br i1 %12, label %.critedge, label %13

13:                                               ; preds = %.lr.ph
  tail call void @_ZNK8graphlab11conditional4waitERKNS_5mutexE(ptr noundef nonnull align 8 dereferenceable(48) %8, ptr noundef nonnull align 8 dereferenceable(40) %6)
  %14 = tail call noundef zeroext i1 @_ZNK8graphlab25safe_circular_char_buffer5emptyEv(ptr noundef nonnull align 8 dereferenceable(122) %0)
  br i1 %14, label %.lr.ph, label %.critedge, !llvm.loop !17

.critedge:                                        ; preds = %.lr.ph, %13, %9
  store volatile i8 0, ptr %5, align 1, !tbaa !5
  tail call void @_ZNK8graphlab5mutex6unlockEv(ptr noundef nonnull align 8 dereferenceable(40) %6)
  %15 = tail call noundef i64 @_ZN8graphlab25safe_circular_char_buffer18introspective_readERPcl(ptr noundef nonnull align 8 dereferenceable(122) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, i64 noundef %2)
  %.not13 = icmp eq i64 %15, 0
  br i1 %.not13, label %16, label %.thread

16:                                               ; preds = %.critedge
  %17 = load volatile i8, ptr %7, align 8, !tbaa !14, !range !15, !noundef !16
  %18 = trunc nuw i8 %17 to i1
  br i1 %18, label %.thread, label %9, !llvm.loop !19

.thread:                                          ; preds = %.critedge, %16, %3
  %.2 = phi i64 [ %4, %3 ], [ %15, %.critedge ], [ 0, %16 ]
  ret i64 %.2
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK8graphlab11conditional4waitERKNS_5mutexE(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0 align 2

attributes #0 = { inlinehint mustprogress 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 = { mustprogress 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 = { mustprogress 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, !13, i64 121}
!6 = !{!"_ZTSN8graphlab25safe_circular_char_bufferE", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !12, i64 72, !13, i64 120, !13, i64 121}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_ZTSN8graphlab5mutexE", !8, i64 0}
!12 = !{!"_ZTSN8graphlab11conditionalE", !8, i64 0}
!13 = !{!"bool", !8, i64 0}
!14 = !{!6, !13, i64 120}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass