; LLVM IR from 2404589803/LowMemoryLLM :: src/hal (fp8)

; 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.FP8 = type { i8 }

; Function Attrs: nounwind uwtable
define dso_local i8 @float_to_fp8(float noundef %0, i32 noundef %1) #0 {
  %3 = alloca %struct.FP8, align 1
  %4 = alloca float, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca float, align 4
  %13 = alloca i32, align 4
  store float %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %14 = load float, ptr %4, align 4, !tbaa !5
  %15 = call i1 @llvm.is.fpclass.f32(float %14, i32 3)
  br i1 %15, label %16, label %23

16:                                               ; preds = %2
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 0
  %19 = zext i1 %18 to i64
  %20 = select i1 %18, i32 127, i32 127
  %21 = trunc i32 %20 to i8
  %22 = getelementptr inbounds %struct.FP8, ptr %3, i32 0, i32 0
  store i8 %21, ptr %22, align 1, !tbaa !11
  br label %135

23:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %24 = load float, ptr %4, align 4, !tbaa !5
  %25 = fcmp olt float %24, 0.000000e+00
  %26 = zext i1 %25 to i64
  %27 = select i1 %25, i32 1, i32 0
  store i32 %27, ptr %6, align 4, !tbaa !9
  %28 = load float, ptr %4, align 4, !tbaa !5
  %29 = call float @llvm.fabs.f32(float %28)
  store float %29, ptr %4, align 4, !tbaa !5
  %30 = load float, ptr %4, align 4, !tbaa !5
  %31 = call float @llvm.fabs.f32(float %30) #5
  %32 = fcmp oeq float %31, 0x7FF0000000000000
  %33 = bitcast float %30 to i32
  %34 = icmp slt i32 %33, 0
  %35 = select i1 %34, i32 -1, i32 1
  %36 = select i1 %32, i32 %35, i32 0
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %54

38:                                               ; preds = %23
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 0
  %41 = zext i1 %40 to i64
  %42 = select i1 %40, i32 127, i32 127
  %43 = trunc i32 %42 to i8
  %44 = getelementptr inbounds %struct.FP8, ptr %3, i32 0, i32 0
  store i8 %43, ptr %44, align 1, !tbaa !11
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %53

47:                                               ; preds = %38
  %48 = getelementptr inbounds %struct.FP8, ptr %3, i32 0, i32 0
  %49 = load i8, ptr %48, align 1, !tbaa !11
  %50 = zext i8 %49 to i32
  %51 = or i32 %50, 128
  %52 = trunc i32 %51 to i8
  store i8 %52, ptr %48, align 1, !tbaa !11
  br label %53

53:                                               ; preds = %47, %38
  store i32 1, ptr %7, align 4
  br label %134

54:                                               ; preds = %23
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %95

57:                                               ; preds = %54
  %58 = load float, ptr %4, align 4, !tbaa !5
  %59 = fcmp oeq float %58, 0.000000e+00
  br i1 %59, label %60, label %62

60:                                               ; preds = %57
  %61 = getelementptr inbounds %struct.FP8, ptr %3, i32 0, i32 0
  store i8 0, ptr %61, align 1, !tbaa !11
  store i32 1, ptr %7, align 4
  br label %134

62:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %63 = load float, ptr %4, align 4, !tbaa !5
  %64 = call float @frexpf(float noundef %63, ptr noundef %8) #4
  store float %64, ptr %9, align 4, !tbaa !5
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = add nsw i32 %65, 6
  store i32 %66, ptr %8, align 4, !tbaa !9
  %67 = load float, ptr %9, align 4, !tbaa !5
  %68 = call float @llvm.fmuladd.f32(float %67, float 1.600000e+01, float -8.000000e+00)
  store float %68, ptr %9, align 4, !tbaa !5
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = icmp slt i32 %69, -7
  br i1 %70, label %71, label %73

71:                                               ; preds = %62
  %72 = getelementptr inbounds %struct.FP8, ptr %3, i32 0, i32 0
  store i8 0, ptr %72, align 1, !tbaa !11
  br label %94

73:                                               ; preds = %62
  %74 = load i32, ptr %8, align 4, !tbaa !9
  %75 = icmp sgt i32 %74, 8
  br i1 %75, label %76, label %78

76:                                               ; preds = %73
  %77 = getelementptr inbounds %struct.FP8, ptr %3, i32 0, i32 0
  store i8 127, ptr %77, align 1, !tbaa !11
  br label %93

78:                                               ; preds = %73
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %79 = load float, ptr %9, align 4, !tbaa !5
  %80 = call float @llvm.round.f32(float %79)
  %81 = fptosi float %80 to i32
  store i32 %81, ptr %10, align 4, !tbaa !9
  %82 = load i32, ptr %10, align 4, !tbaa !9
  %83 = icmp eq i32 %82, 8
  br i1 %83, label %84, label %87

84:                                               ; preds = %78
  %85 = load i32, ptr %8, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %8, align 4, !tbaa !9
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %87

87:                                               ; preds = %84, %78
  %88 = load i32, ptr %6, align 4, !tbaa !9
  %89 = load i32, ptr %8, align 4, !tbaa !9
  %90 = load i32, ptr %10, align 4, !tbaa !9
  %91 = call zeroext i8 @pack_e4m3(i32 noundef %88, i32 noundef %89, i32 noundef %90)
  %92 = getelementptr inbounds %struct.FP8, ptr %3, i32 0, i32 0
  store i8 %91, ptr %92, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %93

93:                                               ; preds = %87, %76
  br label %94

94:                                               ; preds = %93, %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %133

95:                                               ; preds = %54
  %96 = load float, ptr %4, align 4, !tbaa !5
  %97 = fcmp oeq float %96, 0.000000e+00
  br i1 %97, label %98, label %100

98:                                               ; preds = %95
  %99 = getelementptr inbounds %struct.FP8, ptr %3, i32 0, i32 0
  store i8 0, ptr %99, align 1, !tbaa !11
  store i32 1, ptr %7, align 4
  br label %134

100:                                              ; preds = %95
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %101 = load float, ptr %4, align 4, !tbaa !5
  %102 = call float @frexpf(float noundef %101, ptr noundef %11) #4
  store float %102, ptr %12, align 4, !tbaa !5
  %103 = load i32, ptr %11, align 4, !tbaa !9
  %104 = add nsw i32 %103, 14
  store i32 %104, ptr %11, align 4, !tbaa !9
  %105 = load float, ptr %12, align 4, !tbaa !5
  %106 = call float @llvm.fmuladd.f32(float %105, float 8.000000e+00, float -4.000000e+00)
  store float %106, ptr %12, align 4, !tbaa !5
  %107 = load i32, ptr %11, align 4, !tbaa !9
  %108 = icmp slt i32 %107, -15
  br i1 %108, label %109, label %111

109:                                              ; preds = %100
  %110 = getelementptr inbounds %struct.FP8, ptr %3, i32 0, i32 0
  store i8 0, ptr %110, align 1, !tbaa !11
  br label %132

111:                                              ; preds = %100
  %112 = load i32, ptr %11, align 4, !tbaa !9
  %113 = icmp sgt i32 %112, 16
  br i1 %113, label %114, label %116

114:                                              ; preds = %111
  %115 = getelementptr inbounds %struct.FP8, ptr %3, i32 0, i32 0
  store i8 127, ptr %115, align 1, !tbaa !11
  br label %131

116:                                              ; preds = %111
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %117 = load float, ptr %12, align 4, !tbaa !5
  %118 = call float @llvm.round.f32(float %117)
  %119 = fptosi float %118 to i32
  store i32 %119, ptr %13, align 4, !tbaa !9
  %120 = load i32, ptr %13, align 4, !tbaa !9
  %121 = icmp eq i32 %120, 4
  br i1 %121, label %122, label %125

122:                                              ; preds = %116
  %123 = load i32, ptr %11, align 4, !tbaa !9
  %124 = add nsw i32 %123, 1
  store i32 %124, ptr %11, align 4, !tbaa !9
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %125

125:                                              ; preds = %122, %116
  %126 = load i32, ptr %6, align 4, !tbaa !9
  %127 = load i32, ptr %11, align 4, !tbaa !9
  %128 = load i32, ptr %13, align 4, !tbaa !9
  %129 = call zeroext i8 @pack_e5m2(i32 noundef %126, i32 noundef %127, i32 noundef %128)
  %130 = getelementptr inbounds %struct.FP8, ptr %3, i32 0, i32 0
  store i8 %129, ptr %130, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %131

131:                                              ; preds = %125, %114
  br label %132

132:                                              ; preds = %131, %109
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %133

133:                                              ; preds = %132, %94
  store i32 1, ptr %7, align 4
  br label %134

134:                                              ; preds = %133, %98, %60, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %135

135:                                              ; preds = %134, %16
  %136 = getelementptr inbounds %struct.FP8, ptr %3, i32 0, i32 0
  %137 = load i8, ptr %136, align 1
  ret i8 %137
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i1 @llvm.is.fpclass.f32(float, i32 immarg) #1

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fabs.f32(float) #1

; Function Attrs: nounwind
declare float @frexpf(float noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.round.f32(float) #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @pack_e4m3(i32 noundef, i32 noundef, i32 noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @pack_e5m2(i32 noundef, i32 noundef, i32 noundef) #0

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 speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind "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 #4 = { nounwind }
attributes #5 = { memory(none) }

!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 = !{!"float", !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, !7, i64 0}
!12 = !{!"", !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: nounwind uwtable
define dso_local i8 @float_to_fp8(float noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = fcmp uno float %0, 0.000000e+00
  br i1 %5, label %43, label %6

6:                                                ; preds = %2
  %7 = fcmp olt float %0, 0.000000e+00
  %8 = zext i1 %7 to i32
  %9 = tail call float @llvm.fabs.f32(float %0)
  %10 = fcmp oeq float %9, 0x7FF0000000000000
  br i1 %10, label %11, label %12

11:                                               ; preds = %6
  %.sroa.0.0 = select i1 %7, i8 -1, i8 127
  br label %43

12:                                               ; preds = %6
  %13 = icmp eq i32 %1, 0
  %14 = fcmp oeq float %0, 0.000000e+00
  br i1 %13, label %15, label %29

15:                                               ; preds = %12
  br i1 %14, label %43, label %16

16:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %17 = call float @frexpf(float noundef %9, ptr noundef nonnull %3) #4
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = tail call float @llvm.fmuladd.f32(float %17, float 1.600000e+01, float -8.000000e+00)
  %20 = icmp slt i32 %18, -13
  br i1 %20, label %28, label %21

21:                                               ; preds = %16
  %22 = icmp sgt i32 %18, 2
  br i1 %22, label %28, label %23

23:                                               ; preds = %21
  %24 = tail call float @llvm.round.f32(float %19)
  %25 = fptosi float %24 to i32
  %26 = icmp eq i32 %25, 8
  %spec.select.v = select i1 %26, i32 7, i32 6
  %spec.select = add nsw i32 %18, %spec.select.v
  %spec.select28 = select i1 %26, i32 0, i32 %25
  %27 = tail call zeroext i8 @pack_e4m3(i32 noundef %8, i32 noundef %spec.select, i32 noundef %spec.select28)
  br label %28

28:                                               ; preds = %21, %16, %23
  %.sroa.0.1 = phi i8 [ %27, %23 ], [ 0, %16 ], [ 127, %21 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  br label %43

29:                                               ; preds = %12
  br i1 %14, label %43, label %30

30:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %31 = call float @frexpf(float noundef %9, ptr noundef nonnull %4) #4
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = tail call float @llvm.fmuladd.f32(float %31, float 8.000000e+00, float -4.000000e+00)
  %34 = icmp slt i32 %32, -29
  br i1 %34, label %42, label %35

35:                                               ; preds = %30
  %36 = icmp sgt i32 %32, 2
  br i1 %36, label %42, label %37

37:                                               ; preds = %35
  %38 = tail call float @llvm.round.f32(float %33)
  %39 = fptosi float %38 to i32
  %40 = icmp eq i32 %39, 4
  %spec.select29.v = select i1 %40, i32 15, i32 14
  %spec.select29 = add nsw i32 %32, %spec.select29.v
  %spec.select30 = select i1 %40, i32 0, i32 %39
  %41 = tail call zeroext i8 @pack_e5m2(i32 noundef %8, i32 noundef %spec.select29, i32 noundef %spec.select30)
  br label %42

42:                                               ; preds = %35, %30, %37
  %.sroa.0.2 = phi i8 [ %41, %37 ], [ 0, %30 ], [ 127, %35 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  br label %43

43:                                               ; preds = %11, %15, %29, %42, %28, %2
  %.sroa.0.5 = phi i8 [ 127, %2 ], [ %.sroa.0.0, %11 ], [ 0, %15 ], [ 0, %29 ], [ %.sroa.0.1, %28 ], [ %.sroa.0.2, %42 ]
  ret i8 %.sroa.0.5
}

; 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 speculatable willreturn memory(none)
declare float @llvm.fabs.f32(float) #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: write)
declare float @frexpf(float noundef, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.round.f32(float) #2

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @pack_e4m3(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; 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
declare hidden zeroext i8 @pack_e5m2(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass