; LLVM IR from kmilo17pet/qlibs :: qfp16 (qFP16_Exp)

; 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.qFP16_Settings_t = type { i32, i32, i8, i8 }

@fp = external hidden global ptr, align 8

; 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
declare dso_local i32 @qFP16_IntToFP(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @qFP16_Mul(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @qFP16_Div(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @qFP16_Exp(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp eq i32 0, %7
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i32 65536, ptr %3, align 4, !tbaa !5
  br label %74

10:                                               ; preds = %1
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 65536
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  store i32 178145, ptr %3, align 4, !tbaa !5
  br label %73

14:                                               ; preds = %10
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = icmp sge i32 %15, 681391
  br i1 %16, label %17, label %21

17:                                               ; preds = %14
  %18 = load ptr, ptr @fp, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.qFP16_Settings_t, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !11
  store i32 %20, ptr %3, align 4, !tbaa !5
  br label %72

21:                                               ; preds = %14
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = icmp sle i32 %22, -681391
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %71

25:                                               ; preds = %21
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = icmp slt i32 %26, 0
  %28 = zext i1 %27 to i8
  store i8 %28, ptr %5, align 1, !tbaa !13
  %29 = load i8, ptr %5, align 1, !tbaa !13, !range !15, !noundef !16
  %30 = trunc i8 %29 to i1
  br i1 %30, label %31, label %34

31:                                               ; preds = %25
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sub nsw i32 0, %32
  store i32 %33, ptr %2, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %31, %25
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = add nsw i32 %35, 65536
  store i32 %36, ptr %3, align 4, !tbaa !5
  %37 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %37, ptr %4, align 4, !tbaa !5
  store i32 2, ptr %6, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %61, %34
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = icmp slt i32 %39, 30
  br i1 %40, label %41, label %64

41:                                               ; preds = %38
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = call i32 @qFP16_IntToFP(i32 noundef %44)
  %46 = call i32 @qFP16_Div(i32 noundef %43, i32 noundef %45)
  %47 = call i32 @qFP16_Mul(i32 noundef %42, i32 noundef %46)
  store i32 %47, ptr %4, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = add nsw i32 %49, %48
  store i32 %50, ptr %3, align 4, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = icmp slt i32 %51, 500
  br i1 %52, label %53, label %60

53:                                               ; preds = %41
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = icmp sgt i32 %54, 15
  br i1 %55, label %59, label %56

56:                                               ; preds = %53
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = icmp slt i32 %57, 20
  br i1 %58, label %59, label %60

59:                                               ; preds = %56, %53
  br label %64

60:                                               ; preds = %56, %41
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %6, align 4, !tbaa !5
  br label %38, !llvm.loop !17

64:                                               ; preds = %59, %38
  %65 = load i8, ptr %5, align 1, !tbaa !13, !range !15, !noundef !16
  %66 = trunc i8 %65 to i1
  br i1 %66, label %67, label %70

67:                                               ; preds = %64
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = call i32 @qFP16_Div(i32 noundef 65536, i32 noundef %68)
  store i32 %69, ptr %3, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %67, %64
  br label %71

71:                                               ; preds = %70, %24
  br label %72

72:                                               ; preds = %71, %17
  br label %73

73:                                               ; preds = %72, %13
  br label %74

74:                                               ; preds = %73, %9
  %75 = load i32, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  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 i32 %75
}

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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 4}
!12 = !{!"", !6, i64 0, !6, i64 4, !7, i64 8, !7, i64 9}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@fp = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local i32 @qFP16_IntToFP(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @qFP16_Mul(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @qFP16_Div(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @qFP16_Exp(i32 noundef %0) local_unnamed_addr #0 {
  switch i32 %0, label %3 [
    i32 0, label %27
    i32 65536, label %2
  ]

2:                                                ; preds = %1
  br label %27

3:                                                ; preds = %1
  %4 = icmp sgt i32 %0, 681390
  br i1 %4, label %5, label %9

5:                                                ; preds = %3
  %6 = load ptr, ptr @fp, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !9
  br label %27

9:                                                ; preds = %3
  %10 = icmp slt i32 %0, -681390
  br i1 %10, label %27, label %11

11:                                               ; preds = %9
  %12 = icmp slt i32 %0, 0
  %spec.select = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
  %13 = add nuw nsw i32 %spec.select, 65536
  br label %14

14:                                               ; preds = %.backedge, %11
  %.030 = phi i32 [ 2, %11 ], [ %.030.be, %.backedge ]
  %.02429 = phi i32 [ %spec.select, %11 ], [ %17, %.backedge ]
  %.02528 = phi i32 [ %13, %11 ], [ %18, %.backedge ]
  %15 = tail call i32 @qFP16_IntToFP(i32 noundef %.030)
  %16 = tail call i32 @qFP16_Div(i32 noundef %spec.select, i32 noundef %15)
  %17 = tail call i32 @qFP16_Mul(i32 noundef %.02429, i32 noundef %16)
  %18 = add nsw i32 %17, %.02528
  %19 = icmp slt i32 %17, 500
  br i1 %19, label %20, label %23

20:                                               ; preds = %14
  %21 = icmp ult i32 %.030, 16
  %22 = icmp sgt i32 %17, 19
  %or.cond.not34 = and i1 %21, %22
  br i1 %or.cond.not34, label %.backedge, label %24

23:                                               ; preds = %14
  %.old31 = icmp ult i32 %.030, 29
  br i1 %.old31, label %.backedge, label %24

.backedge:                                        ; preds = %23, %20
  %.030.be = add nuw nsw i32 %.030, 1
  br label %14, !llvm.loop !12

24:                                               ; preds = %20, %23
  br i1 %12, label %25, label %27

25:                                               ; preds = %24
  %26 = tail call i32 @qFP16_Div(i32 noundef 65536, i32 noundef %18)
  br label %27

27:                                               ; preds = %9, %1, %2, %25, %24, %5
  %.2 = phi i32 [ 178145, %2 ], [ %8, %5 ], [ %26, %25 ], [ %18, %24 ], [ 65536, %1 ], [ 0, %9 ]
  ret i32 %.2
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #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 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 4}
!10 = !{!"", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 9}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass