; LLVM IR from heroseh/cgm :: cgm (CgmF16_to_float)

; 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.CgmF16 = type { i16 }
%union._cgm_float_uint = type { float }

; 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
define dso_local float @CgmF16_to_float(i16 %0) #1 {
  %2 = alloca float, align 4
  %3 = alloca %struct.CgmF16, align 2
  %4 = alloca %union._cgm_float_uint, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = getelementptr inbounds %struct.CgmF16, ptr %3, i32 0, i32 0
  store i16 %0, ptr %7, align 2
  %8 = getelementptr inbounds %struct.CgmF16, ptr %3, i32 0, i32 0
  %9 = load i16, ptr %8, align 2, !tbaa !5
  %10 = zext i16 %9 to i32
  %11 = and i32 %10, 31744
  %12 = icmp eq i32 %11, 31744
  br i1 %12, label %13, label %28

13:                                               ; preds = %1
  %14 = getelementptr inbounds %struct.CgmF16, ptr %3, i32 0, i32 0
  %15 = load i16, ptr %14, align 2, !tbaa !5
  %16 = zext i16 %15 to i32
  %17 = and i32 %16, 1023
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %13
  store float 0x7FF8000000000000, ptr %2, align 4
  br label %58

20:                                               ; preds = %13
  %21 = getelementptr inbounds %struct.CgmF16, ptr %3, i32 0, i32 0
  %22 = load i16, ptr %21, align 2, !tbaa !5
  %23 = zext i16 %22 to i32
  %24 = and i32 %23, 32768
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %20
  store float 0xFFF0000000000000, ptr %2, align 4
  br label %58

27:                                               ; preds = %20
  store float 0x7FF0000000000000, ptr %2, align 4
  br label %58

28:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %29 = getelementptr inbounds %struct.CgmF16, ptr %3, i32 0, i32 0
  %30 = load i16, ptr %29, align 2, !tbaa !5
  %31 = zext i16 %30 to i32
  %32 = and i32 %31, 32767
  store i32 %32, ptr %4, align 4, !tbaa !10
  %33 = getelementptr inbounds %struct.CgmF16, ptr %3, i32 0, i32 0
  %34 = load i16, ptr %33, align 2, !tbaa !5
  %35 = zext i16 %34 to i32
  %36 = and i32 %35, 32768
  store i32 %36, ptr %5, align 4, !tbaa !11
  %37 = getelementptr inbounds %struct.CgmF16, ptr %3, i32 0, i32 0
  %38 = load i16, ptr %37, align 2, !tbaa !5
  %39 = zext i16 %38 to i32
  %40 = and i32 %39, 31744
  store i32 %40, ptr %6, align 4, !tbaa !11
  %41 = load i32, ptr %4, align 4, !tbaa !10
  %42 = shl i32 %41, 13
  store i32 %42, ptr %4, align 4, !tbaa !10
  %43 = load i32, ptr %5, align 4, !tbaa !11
  %44 = shl i32 %43, 16
  store i32 %44, ptr %5, align 4, !tbaa !11
  %45 = load i32, ptr %4, align 4, !tbaa !10
  %46 = add i32 %45, 939524096
  store i32 %46, ptr %4, align 4, !tbaa !10
  %47 = load i32, ptr %6, align 4, !tbaa !11
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %28
  br label %52

50:                                               ; preds = %28
  %51 = load i32, ptr %4, align 4, !tbaa !10
  br label %52

52:                                               ; preds = %50, %49
  %53 = phi i32 [ 0, %49 ], [ %51, %50 ]
  store i32 %53, ptr %4, align 4, !tbaa !10
  %54 = load i32, ptr %5, align 4, !tbaa !11
  %55 = load i32, ptr %4, align 4, !tbaa !10
  %56 = or i32 %55, %54
  store i32 %56, ptr %4, align 4, !tbaa !10
  %57 = load float, ptr %4, align 4, !tbaa !10
  store float %57, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %58

58:                                               ; preds = %52, %27, %26, %19
  %59 = load float, ptr %2, align 4
  ret float %59
}

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 = { 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 = !{!"CgmF16", !7, i64 0}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !8, 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: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local float @CgmF16_to_float(i16 %0) local_unnamed_addr #0 {
  %2 = zext i16 %0 to i32
  %3 = and i32 %2, 31744
  %4 = icmp eq i32 %3, 31744
  br i1 %4, label %5, label %8

5:                                                ; preds = %1
  %6 = and i32 %2, 1023
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %17

7:                                                ; preds = %5
  %.not13 = icmp sgt i16 %0, -1
  %. = select i1 %.not13, float 0x7FF0000000000000, float 0xFFF0000000000000
  br label %17

8:                                                ; preds = %1
  %9 = shl nuw nsw i32 %2, 13
  %10 = and i32 %9, 268427264
  %.signext = sext i16 %0 to i32
  %11 = and i32 %.signext, -2147483648
  %12 = add nuw nsw i32 %10, 939524096
  %13 = icmp eq i32 %3, 0
  %14 = select i1 %13, i32 0, i32 %12
  %15 = or disjoint i32 %14, %11
  %16 = bitcast i32 %15 to float
  br label %17

17:                                               ; preds = %7, %5, %8
  %.0 = phi float [ %16, %8 ], [ 0x7FF8000000000000, %5 ], [ %., %7 ]
  ret float %.0
}

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,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass