; LLVM IR from stillwater-sc/universal :: c_api/pure_c/posit (posit8)

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

; Function Attrs: nounwind uwtable
define dso_local float @posit8_fraction_value(i8 noundef zeroext %0) #0 {
  %2 = alloca i8, align 1
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i8 %0, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store float 0.000000e+00, ptr %3, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store float 1.000000e+00, ptr %4, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  store i8 -128, ptr %5, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 5, ptr %6, align 4, !tbaa !10
  br label %8

8:                                                ; preds = %35, %1
  %9 = load i32, ptr %6, align 4, !tbaa !10
  %10 = icmp sge i32 %9, 0
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  store i32 2, ptr %7, align 4
  br label %38

12:                                               ; preds = %8
  %13 = load i8, ptr %2, align 1, !tbaa !5
  %14 = zext i8 %13 to i32
  %15 = load i8, ptr %5, align 1, !tbaa !5
  %16 = zext i8 %15 to i32
  %17 = and i32 %14, %16
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %23

19:                                               ; preds = %12
  %20 = load float, ptr %4, align 4, !tbaa !8
  %21 = load float, ptr %3, align 4, !tbaa !8
  %22 = fadd float %21, %20
  store float %22, ptr %3, align 4, !tbaa !8
  br label %23

23:                                               ; preds = %19, %12
  %24 = load float, ptr %4, align 4, !tbaa !8
  %25 = fmul float %24, 5.000000e-01
  store float %25, ptr %4, align 4, !tbaa !8
  %26 = load i8, ptr %5, align 1, !tbaa !5
  %27 = zext i8 %26 to i32
  %28 = ashr i32 %27, 1
  %29 = trunc i32 %28 to i8
  store i8 %29, ptr %5, align 1, !tbaa !5
  %30 = load float, ptr %4, align 4, !tbaa !8
  %31 = fpext float %30 to double
  %32 = fcmp oeq double %31, 0.000000e+00
  br i1 %32, label %33, label %34

33:                                               ; preds = %23
  store i32 2, ptr %7, align 4
  br label %38

34:                                               ; preds = %23
  br label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %6, align 4, !tbaa !10
  %37 = add nsw i32 %36, -1
  store i32 %37, ptr %6, align 4, !tbaa !10
  br label %8, !llvm.loop !12

38:                                               ; preds = %33, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %39

39:                                               ; preds = %38
  %40 = load float, ptr %3, align 4, !tbaa !8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret float %40
}

; 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"float", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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 nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local float @posit8_fraction_value(i8 noundef zeroext %0) local_unnamed_addr #0 {
  %2 = zext i8 %0 to i32
  %3 = and i32 %2, 4
  %.not.5 = icmp eq i32 %3, 0
  %4 = and i32 %2, 8
  %.not.4 = icmp eq i32 %4, 0
  %5 = and i32 %2, 16
  %.not.3 = icmp eq i32 %5, 0
  %6 = and i32 %2, 32
  %.not.2 = icmp eq i32 %6, 0
  %7 = and i32 %2, 64
  %.not.1 = icmp eq i32 %7, 0
  %.not = icmp sgt i8 %0, -1
  %.1 = select i1 %.not, float 0.000000e+00, float 1.000000e+00
  %8 = fadd float %.1, 5.000000e-01
  %.1.1 = select i1 %.not.1, float %.1, float %8
  %9 = fadd float %.1.1, 2.500000e-01
  %.1.2 = select i1 %.not.2, float %.1.1, float %9
  %10 = fadd float %.1.2, 1.250000e-01
  %.1.3 = select i1 %.not.3, float %.1.2, float %10
  %11 = fadd float %.1.3, 6.250000e-02
  %.1.4 = select i1 %.not.4, float %.1.3, float %11
  %12 = fadd float %.1.4, 3.125000e-02
  %.1.5 = select i1 %.not.5, float %.1.4, float %12
  ret float %.1.5
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass