; LLVM IR from pmwkaa/monotone :: monotone/engine/io (writer)

; 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.Writer = type { ptr, %struct.Iov, %struct.RegionWriter, %struct.IndexWriter, ptr, ptr, ptr }
%struct.Iov = type { %struct.Buf, i32, i32 }
%struct.Buf = type { ptr, ptr, ptr }
%struct.RegionWriter = type { %struct.Buf, %struct.Buf, %struct.Buf, %struct.Buf, ptr, i32, ptr, ptr }
%struct.IndexWriter = type { i8, %struct.Buf, %struct.Buf, ptr, i32, %struct.Buf, ptr, ptr, i8, %struct.Index }
%struct.Index = type <{ i32, i32, i32, i32, %struct.Id, i32, i32, i64, i64, i64, i64, i32, i64, i64, i64, i32, i64, i8, i8, [4 x i32] }>
%struct.Id = type { i64, i64 }
%struct.Event = type <{ i64, i8, i8, i32, [0 x i8] }>

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @region_writer_started(ptr noundef) #0

; Function Attrs: hot inlinehint nounwind uwtable
declare hidden void @writer_stop_region(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @writer_add(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = call zeroext i1 @writer_is_region_limit(ptr noundef %5) #4
  %7 = xor i1 %6, true
  %8 = xor i1 %7, true
  %9 = zext i1 %8 to i32
  %10 = sext i32 %9 to i64
  %11 = call i64 @llvm.expect.i64(i64 %10, i64 0)
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %13, label %32

13:                                               ; preds = %2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Writer, ptr %14, i32 0, i32 2
  %16 = call zeroext i1 @region_writer_started(ptr noundef %15)
  br i1 %16, label %17, label %29

17:                                               ; preds = %13
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.Writer, ptr %18, i32 0, i32 2
  %20 = call ptr @region_writer_max(ptr noundef %19)
  %21 = getelementptr inbounds %struct.Event, ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 1, !tbaa !9
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Event, ptr %23, i32 0, i32 0
  %25 = load i64, ptr %24, align 1, !tbaa !9
  %26 = icmp eq i64 %22, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %17
  br label %33

28:                                               ; preds = %17
  br label %29

29:                                               ; preds = %28, %13
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  call void @writer_stop_region(ptr noundef %30) #4
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  call void @writer_start_region(ptr noundef %31)
  br label %32

32:                                               ; preds = %29, %2
  br label %33

33:                                               ; preds = %32, %27
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Writer, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  call void @region_writer_add(ptr noundef %35, ptr noundef %36)
  ret void
}

; Function Attrs: hot inlinehint nounwind uwtable
declare hidden zeroext i1 @writer_is_region_limit(ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @region_writer_max(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @writer_start_region(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @region_writer_add(ptr noundef, ptr noundef) #0

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 = { hot 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 #2 = { 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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #4 = { hot }

!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}


; 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 nounwind uwtable
declare hidden zeroext i1 @region_writer_started(ptr noundef) local_unnamed_addr #0

; Function Attrs: hot inlinehint nounwind uwtable
declare hidden void @writer_stop_region(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @writer_add(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = tail call zeroext i1 @writer_is_region_limit(ptr noundef %0) #3
  br i1 %3, label %4, label %13, !prof !5

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  %6 = tail call zeroext i1 @region_writer_started(ptr noundef nonnull %5)
  br i1 %6, label %7, label %12

7:                                                ; preds = %4
  %8 = tail call ptr @region_writer_max(ptr noundef nonnull %5)
  %9 = load i64, ptr %8, align 1, !tbaa !6
  %10 = load i64, ptr %1, align 1, !tbaa !6
  %11 = icmp eq i64 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %7, %4
  tail call void @writer_stop_region(ptr noundef %0) #3
  tail call void @writer_start_region(ptr noundef %0)
  br label %13

13:                                               ; preds = %2, %12, %7
  %14 = getelementptr inbounds i8, ptr %0, i64 40
  tail call void @region_writer_add(ptr noundef nonnull %14, ptr noundef %1)
  ret void
}

; Function Attrs: hot inlinehint nounwind uwtable
declare hidden zeroext i1 @writer_is_region_limit(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @region_writer_max(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @writer_start_region(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @region_writer_add(ptr noundef, ptr noundef) local_unnamed_addr #0

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 = { hot 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 #2 = { 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 = { hot }

!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 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!6 = !{!7, !7, i64 0}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}


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