; 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: nounwind uwtable
define dso_local ptr @CFifoInit(ptr noundef %0, i32 noundef %1, i32 noundef %2, i1 noundef zeroext %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  %11 = zext i1 %3 to i8
  store i8 %11, ptr %9, align 1, !tbaa !11
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  br label %48

15:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %16, ptr %10, align 8, !tbaa !5
  %17 = load i8, ptr %9, align 1, !tbaa !11, !range !13, !noundef !14
  %18 = trunc i8 %17 to i1
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.__CFIFO_Header, ptr %19, i32 0, i32 3
  %21 = zext i1 %18 to i8
  store i8 %21, ptr %20, align 4, !tbaa !15
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.__CFIFO_Header, ptr %22, i32 0, i32 5
  store i32 0, ptr %23, align 4, !tbaa !17
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.__CFIFO_Header, ptr %24, i32 0, i32 0
  store volatile i32 0, ptr %25, align 4, !tbaa !18
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.__CFIFO_Header, ptr %26, i32 0, i32 1
  store volatile i32 -1, ptr %27, align 4, !tbaa !19
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.__CFIFO_Header, ptr %29, i32 0, i32 6
  store i32 %28, ptr %30, align 4, !tbaa !20
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.__CFIFO_Header, ptr %32, i32 0, i32 7
  store i32 %31, ptr %33, align 4, !tbaa !21
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = sub i64 %35, 36
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = zext i32 %37 to i64
  %39 = udiv i64 %36, %38
  %40 = trunc i64 %39 to i32
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.__CFIFO_Header, ptr %41, i32 0, i32 2
  store i32 %40, ptr %42, align 4, !tbaa !22
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i64 36
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.__CFIFO_Header, ptr %45, i32 0, i32 8
  store ptr %44, ptr %46, align 4, !tbaa !23
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %47, ptr %5, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %48

48:                                               ; preds = %15, %14
  %49 = load ptr, ptr %5, align 8
  ret ptr %49
}

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

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

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


; 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: nofree norecurse nounwind memory(argmem: readwrite, inaccessiblemem: readwrite) uwtable
define dso_local noundef ptr @CFifoInit(ptr noundef returned %0, i32 noundef %1, i32 noundef %2, i1 noundef zeroext %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %0, null
  br i1 %5, label %21, label %6

6:                                                ; preds = %4
  %7 = zext i1 %3 to i8
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  store i8 %7, ptr %8, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 0, ptr %9, align 4, !tbaa !12
  store volatile i32 0, ptr %0, align 4, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  store volatile i32 -1, ptr %10, align 4, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %2, ptr %11, align 4, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %1, ptr %12, align 4, !tbaa !16
  %13 = zext i32 %1 to i64
  %14 = add nsw i64 %13, -36
  %15 = zext i32 %2 to i64
  %16 = udiv i64 %14, %15
  %17 = trunc i64 %16 to i32
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %17, ptr %18, align 4, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %0, i64 36
  %20 = getelementptr inbounds i8, ptr %0, i64 28
  store ptr %19, ptr %20, align 4, !tbaa !18
  br label %21

21:                                               ; preds = %4, %6
  ret ptr %0
}

attributes #0 = { 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, !10, i64 12}
!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 16}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !7, i64 4}
!15 = !{!6, !7, i64 20}
!16 = !{!6, !7, i64 24}
!17 = !{!6, !7, i64 8}
!18 = !{!6, !11, i64 28}


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