; LLVM IR from NervanaSystems/ngraph :: src/ngraph/type/float16.ll (ZNK6ngraph7float16cvfEv)

; 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.anon.1 = type { i32 }
%"class.ngraph::float16" = type { i16 }

; 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: mustprogress nounwind uwtable
define dso_local noundef float @_ZNK6ngraph7float16cvfEv(ptr noundef nonnull align 2 dereferenceable(2) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca %union.anon.1, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %8 = getelementptr inbounds %"class.ngraph::float16", ptr %7, i32 0, i32 0
  %9 = load i16, ptr %8, align 2, !tbaa !9
  %10 = zext i16 %9 to i32
  %11 = ashr i32 %10, 10
  %12 = and i32 31, %11
  store i32 %12, ptr %4, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %13 = load i32, ptr %4, align 4, !tbaa !12
  %14 = add i32 %13, 127
  %15 = sub i32 %14, 15
  store i32 %15, ptr %5, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %16 = getelementptr inbounds %"class.ngraph::float16", ptr %7, i32 0, i32 0
  %17 = load i16, ptr %16, align 2, !tbaa !9
  %18 = zext i16 %17 to i32
  %19 = and i32 %18, 1023
  store i32 %19, ptr %6, align 4, !tbaa !12
  %20 = load i32, ptr %4, align 4, !tbaa !12
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %42

22:                                               ; preds = %1
  %23 = load i32, ptr %6, align 4, !tbaa !12
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %41

26:                                               ; preds = %22
  %27 = load i32, ptr %5, align 4, !tbaa !12
  %28 = add i32 %27, 1
  store i32 %28, ptr %5, align 4, !tbaa !12
  br label %29

29:                                               ; preds = %33, %26
  %30 = load i32, ptr %6, align 4, !tbaa !12
  %31 = and i32 %30, 1024
  %32 = icmp eq i32 0, %31
  br i1 %32, label %33, label %38

33:                                               ; preds = %29
  %34 = load i32, ptr %5, align 4, !tbaa !12
  %35 = add i32 %34, -1
  store i32 %35, ptr %5, align 4, !tbaa !12
  %36 = load i32, ptr %6, align 4, !tbaa !12
  %37 = shl i32 %36, 1
  store i32 %37, ptr %6, align 4, !tbaa !12
  br label %29, !llvm.loop !14

38:                                               ; preds = %29
  %39 = load i32, ptr %6, align 4, !tbaa !12
  %40 = and i32 %39, 1023
  store i32 %40, ptr %6, align 4, !tbaa !12
  br label %41

41:                                               ; preds = %38, %25
  br label %47

42:                                               ; preds = %1
  %43 = load i32, ptr %4, align 4, !tbaa !12
  %44 = icmp eq i32 %43, 31
  br i1 %44, label %45, label %46

45:                                               ; preds = %42
  store i32 255, ptr %5, align 4, !tbaa !12
  br label %46

46:                                               ; preds = %45, %42
  br label %47

47:                                               ; preds = %46, %41
  %48 = load i32, ptr %6, align 4, !tbaa !12
  %49 = shl i32 %48, 13
  store i32 %49, ptr %6, align 4, !tbaa !12
  %50 = getelementptr inbounds %"class.ngraph::float16", ptr %7, i32 0, i32 0
  %51 = load i16, ptr %50, align 2, !tbaa !9
  %52 = zext i16 %51 to i32
  %53 = and i32 %52, 32768
  %54 = shl i32 %53, 16
  %55 = load i32, ptr %5, align 4, !tbaa !12
  %56 = shl i32 %55, 23
  %57 = or i32 %54, %56
  %58 = load i32, ptr %6, align 4, !tbaa !12
  %59 = or i32 %57, %58
  store i32 %59, ptr %3, align 4, !tbaa !16
  %60 = load float, ptr %3, align 4, !tbaa !16
  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
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret float %60
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSN6ngraph7float16E", !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!7, !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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef float @_ZNK6ngraph7float16cvfEv(ptr nocapture noundef nonnull readonly align 2 dereferenceable(2) %0) local_unnamed_addr #0 align 2 {
  %2 = load i16, ptr %0, align 2, !tbaa !5
  %3 = zext i16 %2 to i32
  %4 = lshr i32 %3, 10
  %5 = and i32 %4, 31
  %6 = and i32 %3, 1023
  %7 = icmp eq i32 %5, 0
  br i1 %7, label %8, label %13

8:                                                ; preds = %1
  %9 = icmp eq i32 %6, 0
  br i1 %9, label %16, label %.preheader.preheader

.preheader.preheader:                             ; preds = %8
  %.masked.numleadingzeros = tail call range(i32 22, 33) i32 @llvm.ctlz.i32(i32 %6, i1 true)
  %.masked.leadingonepos = xor i32 %.masked.numleadingzeros, 31
  %.preheader.tripcount = sub nuw nsw i32 10, %.masked.leadingonepos
  %10 = shl nuw nsw i32 %3, %.preheader.tripcount
  %11 = sub nuw nsw i32 134, %.masked.numleadingzeros
  %12 = and i32 %10, 1022
  br label %16

13:                                               ; preds = %1
  %14 = add nuw nsw i32 %5, 112
  %15 = icmp eq i32 %5, 31
  %spec.select = select i1 %15, i32 255, i32 %14
  br label %16

16:                                               ; preds = %13, %8, %.preheader.preheader
  %.113 = phi i32 [ %11, %.preheader.preheader ], [ 0, %8 ], [ %spec.select, %13 ]
  %.1 = phi i32 [ %12, %.preheader.preheader ], [ 0, %8 ], [ %6, %13 ]
  %17 = shl nuw nsw i32 %.1, 13
  %18 = and i16 %2, -32768
  %19 = zext i16 %18 to i32
  %20 = shl nuw i32 %19, 16
  %21 = shl nuw nsw i32 %.113, 23
  %22 = or disjoint i32 %20, %21
  %23 = or disjoint i32 %22, %17
  %24 = bitcast i32 %23 to float
  ret float %24
}

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

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

!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 = !{!"_ZTSN6ngraph7float16E", !7, i64 0}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass