; LLVM IR from IOsonata/IOsonata :: src (cfifo)

; 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.__CFIFO_Header = type <{ i32, i32, i32, i8, [3 x i8], i32, i32, i32, 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
declare dso_local ptr @CFifoGetMultiple(ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @CFifoPutMultiple(ptr noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @CFifoWrite(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %19, label %16

16:                                               ; preds = %3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %16, %3
  store i32 0, ptr %4, align 4
  br label %118

20:                                               ; preds = %16
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.__CFIFO_Header, ptr %21, i32 0, i32 0
  %23 = load volatile i32, ptr %22, align 4, !tbaa !11
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.__CFIFO_Header, ptr %24, i32 0, i32 1
  %26 = load volatile i32, ptr %25, align 4, !tbaa !14
  %27 = icmp eq i32 %23, %26
  br i1 %27, label %28, label %45

28:                                               ; preds = %20
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.__CFIFO_Header, ptr %29, i32 0, i32 3
  %31 = load i8, ptr %30, align 4, !tbaa !15, !range !16, !noundef !17
  %32 = trunc i8 %31 to i1
  %33 = zext i1 %32 to i32
  %34 = icmp eq i32 %33, 1
  br i1 %34, label %35, label %36

35:                                               ; preds = %28
  store i32 0, ptr %4, align 4
  br label %118

36:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %37 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %37, ptr %8, align 4, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = call ptr @CFifoGetMultiple(ptr noundef %38, ptr noundef %8)
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.__CFIFO_Header, ptr %41, i32 0, i32 5
  %43 = load i32, ptr %42, align 4, !tbaa !18
  %44 = add i32 %43, %40
  store i32 %44, ptr %42, align 4, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %45

45:                                               ; preds = %36, %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.__CFIFO_Header, ptr %47, i32 0, i32 6
  %49 = load i32, ptr %48, align 4, !tbaa !19
  %50 = icmp sle i32 %46, %49
  br i1 %50, label %51, label %66

51:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = call ptr @CFifoPut(ptr noundef %52)
  store ptr %53, ptr %10, align 8, !tbaa !5
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %62

56:                                               ; preds = %51
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load i32, ptr %7, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %57, ptr align 1 %58, i64 %60, i1 false)
  %61 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %61, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %63

62:                                               ; preds = %51
  store i32 0, ptr %11, align 4
  br label %63

63:                                               ; preds = %62, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %64 = load i32, ptr %11, align 4
  switch i32 %64, label %117 [
    i32 0, label %65
  ]

65:                                               ; preds = %63
  br label %115

66:                                               ; preds = %45
  br label %67

67:                                               ; preds = %113, %66
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = icmp sgt i32 %68, 0
  br i1 %69, label %70, label %114

70:                                               ; preds = %67
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %71 = load i32, ptr %7, align 4, !tbaa !9
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.__CFIFO_Header, ptr %72, i32 0, i32 6
  %74 = load i32, ptr %73, align 4, !tbaa !19
  %75 = udiv i32 %71, %74
  store i32 %75, ptr %12, align 4, !tbaa !9
  %76 = load i32, ptr %7, align 4, !tbaa !9
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.__CFIFO_Header, ptr %77, i32 0, i32 6
  %79 = load i32, ptr %78, align 4, !tbaa !19
  %80 = urem i32 %76, %79
  %81 = icmp ugt i32 %80, 0
  br i1 %81, label %82, label %85

82:                                               ; preds = %70
  %83 = load i32, ptr %12, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %12, align 4, !tbaa !9
  br label %85

85:                                               ; preds = %82, %70
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = call ptr @CFifoPutMultiple(ptr noundef %86, ptr noundef %12)
  store ptr %87, ptr %13, align 8, !tbaa !5
  %88 = load ptr, ptr %13, align 8, !tbaa !5
  %89 = icmp eq ptr %88, null
  br i1 %89, label %90, label %91

90:                                               ; preds = %85
  store i32 3, ptr %11, align 4
  br label %111

91:                                               ; preds = %85
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.__CFIFO_Header, ptr %92, i32 0, i32 6
  %94 = load i32, ptr %93, align 4, !tbaa !19
  %95 = load i32, ptr %12, align 4, !tbaa !9
  %96 = mul i32 %95, %94
  store i32 %96, ptr %12, align 4, !tbaa !9
  %97 = load ptr, ptr %13, align 8, !tbaa !5
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = load i32, ptr %12, align 4, !tbaa !9
  %100 = sext i32 %99 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %97, ptr align 1 %98, i64 %100, i1 false)
  %101 = load i32, ptr %12, align 4, !tbaa !9
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  %103 = sext i32 %101 to i64
  %104 = getelementptr inbounds i8, ptr %102, i64 %103
  store ptr %104, ptr %6, align 8, !tbaa !5
  %105 = load i32, ptr %12, align 4, !tbaa !9
  %106 = load i32, ptr %7, align 4, !tbaa !9
  %107 = sub nsw i32 %106, %105
  store i32 %107, ptr %7, align 4, !tbaa !9
  %108 = load i32, ptr %12, align 4, !tbaa !9
  %109 = load i32, ptr %9, align 4, !tbaa !9
  %110 = add nsw i32 %109, %108
  store i32 %110, ptr %9, align 4, !tbaa !9
  store i32 0, ptr %11, align 4
  br label %111

111:                                              ; preds = %91, %90
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %112 = load i32, ptr %11, align 4
  switch i32 %112, label %120 [
    i32 0, label %113
    i32 3, label %114
  ]

113:                                              ; preds = %111
  br label %67, !llvm.loop !20

114:                                              ; preds = %111, %67
  br label %115

115:                                              ; preds = %114, %65
  %116 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %116, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %117

117:                                              ; preds = %115, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %118

118:                                              ; preds = %117, %35, %19
  %119 = load i32, ptr %4, align 4
  ret i32 %119

120:                                              ; preds = %111
  unreachable
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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}
!11 = !{!12, !10, i64 0}
!12 = !{!"__CFIFO_Header", !10, i64 0, !10, i64 4, !10, i64 8, !13, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !6, i64 28}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!12, !10, i64 4}
!15 = !{!12, !13, i64 12}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!12, !10, i64 16}
!19 = !{!12, !10, i64 20}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; 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: nounwind uwtable
declare dso_local ptr @CFifoGetMultiple(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @CFifoPut(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @CFifoPutMultiple(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @CFifoWrite(ptr noundef %0, ptr noundef readonly %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = icmp eq ptr %0, null
  %7 = icmp eq ptr %1, null
  %or.cond = or i1 %6, %7
  br i1 %or.cond, label %.loopexit, label %8

8:                                                ; preds = %3
  %9 = load volatile i32, ptr %0, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  %11 = load volatile i32, ptr %10, align 4, !tbaa !12
  %12 = icmp eq i32 %9, %11
  br i1 %12, label %13, label %23

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 12
  %15 = load i8, ptr %14, align 4, !tbaa !13, !range !14, !noundef !15
  %16 = trunc nuw i8 %15 to i1
  br i1 %16, label %.loopexit, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  store i32 %2, ptr %4, align 4, !tbaa !16
  %18 = call ptr @CFifoGetMultiple(ptr noundef nonnull %0, ptr noundef nonnull %4)
  %19 = load i32, ptr %4, align 4, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  %21 = load i32, ptr %20, align 4, !tbaa !17
  %22 = add i32 %21, %19
  store i32 %22, ptr %20, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br label %23

23:                                               ; preds = %17, %8
  %24 = getelementptr inbounds i8, ptr %0, i64 20
  %25 = load i32, ptr %24, align 4, !tbaa !18
  %.not = icmp slt i32 %25, %2
  br i1 %.not, label %.preheader, label %27

.preheader:                                       ; preds = %23
  %26 = icmp sgt i32 %2, 0
  br i1 %26, label %.lr.ph, label %.loopexit

27:                                               ; preds = %23
  %28 = call ptr @CFifoPut(ptr noundef nonnull %0)
  %.not48 = icmp eq ptr %28, null
  br i1 %.not48, label %.loopexit, label %29

29:                                               ; preds = %27
  %30 = sext i32 %2 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %28, ptr nonnull align 1 %1, i64 %30, i1 false)
  br label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %37
  %.03557 = phi ptr [ %44, %37 ], [ %1, %.preheader ]
  %.03756 = phi i32 [ %46, %37 ], [ 0, %.preheader ]
  %.04055 = phi i32 [ %45, %37 ], [ %2, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %31 = load i32, ptr %24, align 4, !tbaa !18
  %32 = udiv i32 %.04055, %31
  %33 = urem i32 %.04055, %31
  %.not47 = icmp ne i32 %33, 0
  %34 = zext i1 %.not47 to i32
  %spec.select = add nuw nsw i32 %32, %34
  store i32 %spec.select, ptr %5, align 4, !tbaa !16
  %35 = call ptr @CFifoPutMultiple(ptr noundef nonnull %0, ptr noundef nonnull %5)
  %36 = icmp eq ptr %35, null
  br i1 %36, label %.thread, label %37

.thread:                                          ; preds = %.lr.ph
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  br label %.loopexit

37:                                               ; preds = %.lr.ph
  %38 = load i32, ptr %24, align 4, !tbaa !18
  %39 = load i32, ptr %5, align 4, !tbaa !16
  %40 = mul i32 %39, %38
  store i32 %40, ptr %5, align 4, !tbaa !16
  %41 = sext i32 %40 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %35, ptr align 1 %.03557, i64 %41, i1 false)
  %42 = load i32, ptr %5, align 4, !tbaa !16
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %.03557, i64 %43
  %45 = sub nsw i32 %.04055, %42
  %46 = add nsw i32 %42, %.03756
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  %47 = icmp sgt i32 %45, 0
  br i1 %47, label %.lr.ph, label %.loopexit

.loopexit:                                        ; preds = %37, %.preheader, %.thread, %29, %27, %13, %3
  %.2 = phi i32 [ 0, %3 ], [ 0, %13 ], [ %2, %29 ], [ 0, %27 ], [ %.03756, %.thread ], [ 0, %.preheader ], [ %46, %37 ]
  ret i32 %.2
}

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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, !7, i64 0}
!6 = !{!"__CFIFO_Header", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !11, i64 28}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !10, i64 12}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!7, !7, i64 0}
!17 = !{!6, !7, i64 16}
!18 = !{!6, !7, i64 20}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass