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

; 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_Div(i32 noundef, i32 noundef) #1

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

7:                                                ; preds = %1
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 65536
  br i1 %9, label %10, label %21

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

13:                                               ; preds = %10
  store i32 -1048576, ptr %3, align 4, !tbaa !5
  br label %20

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = call i32 @qFP16_Div(i32 noundef 65536, i32 noundef %15)
  store i32 %16, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = call i32 @qFP16_log2i(i32 noundef %17)
  %19 = sub nsw i32 0, %18
  store i32 %19, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %20

20:                                               ; preds = %14, %13
  br label %24

21:                                               ; preds = %7
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = call i32 @qFP16_log2i(i32 noundef %22)
  store i32 %23, ptr %3, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %21, %20
  br label %25

25:                                               ; preds = %24, %1
  %26 = load ptr, ptr @fp, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.qFP16_Settings_t, ptr %26, i32 0, i32 3
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = zext i8 %28 to i32
  %30 = icmp eq i32 1, %29
  br i1 %30, label %31, label %39

31:                                               ; preds = %25
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = icmp eq i32 -2147483648, %32
  br i1 %33, label %34, label %38

34:                                               ; preds = %31
  %35 = load ptr, ptr @fp, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.qFP16_Settings_t, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 4, !tbaa !13
  store i32 %37, ptr %3, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %34, %31
  br label %39

39:                                               ; preds = %38, %25
  %40 = load i32, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %40
}

; Function Attrs: nounwind uwtable
declare hidden i32 @qFP16_log2i(i32 noundef) #1

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, !7, i64 9}
!12 = !{!"", !6, i64 0, !6, i64 4, !7, i64 8, !7, i64 9}
!13 = !{!12, !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"

@fp = external hidden local_unnamed_addr global ptr, align 8

; 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_Log2(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp sgt i32 %0, 0
  br i1 %2, label %3, label %13

3:                                                ; preds = %1
  %4 = icmp ult i32 %0, 65536
  br i1 %4, label %5, label %11

5:                                                ; preds = %3
  %6 = icmp eq i32 %0, 1
  br i1 %6, label %.thread, label %7

7:                                                ; preds = %5
  %8 = tail call i32 @qFP16_Div(i32 noundef 65536, i32 noundef %0)
  %9 = tail call i32 @qFP16_log2i(i32 noundef %8)
  %10 = sub nsw i32 0, %9
  br label %.thread

11:                                               ; preds = %3
  %12 = tail call i32 @qFP16_log2i(i32 noundef %0)
  br label %13

13:                                               ; preds = %11, %1
  %.0 = phi i32 [ %12, %11 ], [ -2147483648, %1 ]
  %14 = load ptr, ptr @fp, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 9
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = icmp eq i8 %16, 1
  %18 = icmp eq i32 %.0, -2147483648
  %or.cond = select i1 %17, i1 %18, i1 false
  br i1 %or.cond, label %19, label %.thread

19:                                               ; preds = %13
  %20 = load i32, ptr %14, align 4, !tbaa !12
  br label %.thread

.thread:                                          ; preds = %5, %7, %19, %13
  %.1 = phi i32 [ %20, %19 ], [ %.0, %13 ], [ -1048576, %5 ], [ %10, %7 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare hidden i32 @qFP16_log2i(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" }

!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, !7, i64 9}
!10 = !{!"", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 9}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 0}


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