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

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

%union.posit8_u = type { [1 x i8] }

; Function Attrs: nounwind uwtable
declare dso_local float @posit8_1_fraction_value(i8 noundef zeroext) #0

; 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

; Function Attrs: nounwind uwtable
define dso_local float @posit8_1_tof(i8 %0) #0 {
  %2 = alloca float, align 4
  %3 = alloca %union.posit8_u, align 1
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = getelementptr inbounds %union.posit8_u, ptr %3, i32 0, i32 0
  store i8 %0, ptr %12, align 1
  %13 = load i8, ptr %3, align 1, !tbaa !5
  %14 = zext i8 %13 to i32
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %1
  store float 0.000000e+00, ptr %2, align 4
  br label %80

17:                                               ; preds = %1
  %18 = load i8, ptr %3, align 1, !tbaa !5
  %19 = zext i8 %18 to i32
  %20 = icmp eq i32 %19, 128
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  store float 0x7FF8000000000000, ptr %2, align 4
  br label %80

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  %23 = load i8, ptr %3, align 1, !tbaa !5
  %24 = zext i8 %23 to i32
  %25 = and i32 %24, 128
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %31

27:                                               ; preds = %22
  %28 = load i8, ptr %3, align 1, !tbaa !5
  %29 = zext i8 %28 to i32
  %30 = sub nsw i32 0, %29
  br label %34

31:                                               ; preds = %22
  %32 = load i8, ptr %3, align 1, !tbaa !5
  %33 = zext i8 %32 to i32
  br label %34

34:                                               ; preds = %31, %27
  %35 = phi i32 [ %30, %27 ], [ %33, %31 ]
  %36 = trunc i32 %35 to i8
  store i8 %36, ptr %4, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  store i8 0, ptr %5, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %37 = load i8, ptr %4, align 1, !tbaa !5
  %38 = call signext i8 @posit8_1_decode_regime(i8 noundef zeroext %37, ptr noundef %5)
  store i8 %38, ptr %6, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  %39 = load i8, ptr %5, align 1, !tbaa !5
  %40 = zext i8 %39 to i32
  %41 = ashr i32 %40, 7
  %42 = trunc i32 %41 to i8
  store i8 %42, ptr %7, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %43 = getelementptr inbounds %union.posit8_u, ptr %3, i32 0, i32 0
  %44 = load i8, ptr %43, align 1
  %45 = call i32 @posit8_1_sign_value(i8 %44)
  %46 = sitofp i32 %45 to float
  store float %46, ptr %8, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %47 = load i8, ptr %6, align 1, !tbaa !5
  %48 = sext i8 %47 to i32
  %49 = icmp sgt i32 %48, 0
  br i1 %49, label %50, label %55

50:                                               ; preds = %34
  %51 = load i8, ptr %6, align 1, !tbaa !5
  %52 = sext i8 %51 to i32
  %53 = shl i32 1, %52
  %54 = uitofp i32 %53 to float
  br label %62

55:                                               ; preds = %34
  %56 = load i8, ptr %6, align 1, !tbaa !5
  %57 = sext i8 %56 to i32
  %58 = sub nsw i32 0, %57
  %59 = shl i32 1, %58
  %60 = uitofp i32 %59 to float
  %61 = fdiv float 1.000000e+00, %60
  br label %62

62:                                               ; preds = %55, %50
  %63 = phi float [ %54, %50 ], [ %61, %55 ]
  %64 = fmul float 4.000000e+00, %63
  store float %64, ptr %9, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %65 = load i8, ptr %7, align 1, !tbaa !5
  %66 = zext i8 %65 to i32
  %67 = sitofp i32 %66 to float
  %68 = fmul float 2.000000e+00, %67
  store float %68, ptr %10, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store float 1.000000e+00, ptr %11, align 4, !tbaa !8
  %69 = load i8, ptr %5, align 1, !tbaa !5
  %70 = call float @posit8_1_fraction_value(i8 noundef zeroext %69)
  %71 = load float, ptr %11, align 4, !tbaa !8
  %72 = fadd float %71, %70
  store float %72, ptr %11, align 4, !tbaa !8
  %73 = load float, ptr %8, align 4, !tbaa !8
  %74 = load float, ptr %9, align 4, !tbaa !8
  %75 = fmul float %73, %74
  %76 = load float, ptr %10, align 4, !tbaa !8
  %77 = fmul float %75, %76
  %78 = load float, ptr %11, align 4, !tbaa !8
  %79 = fmul float %77, %78
  store float %79, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  br label %80

80:                                               ; preds = %62, %21, %16
  %81 = load float, ptr %2, align 4
  ret float %81
}

; Function Attrs: inlinehint nounwind uwtable
declare signext i8 @posit8_1_decode_regime(i8 noundef zeroext, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare i32 @posit8_1_sign_value(i8) #2

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 = { 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"float", !6, 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: nounwind uwtable
declare dso_local float @posit8_1_fraction_value(i8 noundef zeroext) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local float @posit8_1_tof(i8 %0) local_unnamed_addr #0 {
  %2 = alloca i8, align 1
  switch i8 %0, label %4 [
    i8 0, label %32
    i8 -128, label %3
  ]

3:                                                ; preds = %1
  br label %32

4:                                                ; preds = %1
  %5 = tail call i8 @llvm.abs.i8(i8 %0, i1 true)
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #4
  store i8 0, ptr %2, align 1, !tbaa !5
  %6 = call signext i8 @posit8_1_decode_regime(i8 noundef zeroext %5, ptr noundef nonnull %2)
  %7 = load i8, ptr %2, align 1, !tbaa !5
  %8 = call i32 @posit8_1_sign_value(i8 %0)
  %9 = sitofp i32 %8 to float
  %10 = sext i8 %6 to i32
  %11 = icmp sgt i8 %6, 0
  br i1 %11, label %12, label %15

12:                                               ; preds = %4
  %13 = shl nuw i32 1, %10
  %14 = uitofp i32 %13 to float
  br label %20

15:                                               ; preds = %4
  %16 = sub nsw i32 0, %10
  %17 = shl nuw i32 1, %16
  %18 = uitofp i32 %17 to float
  %19 = fdiv float 1.000000e+00, %18
  br label %20

20:                                               ; preds = %15, %12
  %21 = phi float [ %14, %12 ], [ %19, %15 ]
  %22 = fmul float %21, 4.000000e+00
  %23 = lshr i8 %7, 6
  %24 = and i8 %23, 2
  %25 = uitofp nneg i8 %24 to float
  %26 = load i8, ptr %2, align 1, !tbaa !5
  %27 = call float @posit8_1_fraction_value(i8 noundef zeroext %26)
  %28 = fadd float %27, 1.000000e+00
  %29 = fmul float %22, %9
  %30 = fmul float %29, %25
  %31 = fmul float %30, %28
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #4
  br label %32

32:                                               ; preds = %1, %20, %3
  %.0 = phi float [ 0x7FF8000000000000, %3 ], [ %31, %20 ], [ 0.000000e+00, %1 ]
  ret float %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare signext i8 @posit8_1_decode_regime(i8 noundef zeroext, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare i32 @posit8_1_sign_value(i8) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.abs.i8(i8, i1 immarg) #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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