; LLVM IR from Dovyski/opengl-demos :: libs/glm-0.9.9.3/test/gtx/gtx_integer.ll (Z9test_log2v)

; 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"

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [96 x i8], align 1
@__PRETTY_FUNCTION__._Z9test_log2v = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9test_log2v() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  store i64 1, ptr %2, align 8, !tbaa !9
  br label %5

5:                                                ; preds = %44, %0
  %6 = load i64, ptr %2, align 8, !tbaa !9
  %7 = icmp ult i64 %6, 24
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  br label %47

9:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %10 = load i64, ptr %2, align 8, !tbaa !9
  %11 = trunc i64 %10 to i32
  %12 = shl i32 1, %11
  %13 = call noundef i32 @_ZN3glm4log2IjEET_S1_(i32 noundef %12)
  store i32 %13, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %14 = load i64, ptr %2, align 8, !tbaa !9
  %15 = trunc i64 %14 to i32
  %16 = shl i32 1, %15
  %17 = sitofp i32 %16 to double
  %18 = call noundef double @_ZN3glm4log2IdEET_S1_(double noundef %17)
  %19 = fptoui double %18 to i32
  store i32 %19, ptr %4, align 4, !tbaa !5
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = uitofp i32 %20 to double
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = uitofp i32 %22 to double
  %24 = fsub double %21, %23
  %25 = call noundef double @_ZN3glm3absIdEET_S1_(double noundef %24)
  %26 = fcmp ole double %25, 2.400000e+01
  %27 = zext i1 %26 to i64
  %28 = select i1 %26, i32 0, i32 1
  %29 = load i32, ptr %1, align 4, !tbaa !5
  %30 = add nsw i32 %29, %28
  store i32 %30, ptr %1, align 4, !tbaa !5
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = icmp ne i32 %31, 0
  %33 = xor i1 %32, true
  br i1 %33, label %34, label %35

34:                                               ; preds = %9
  br label %37

35:                                               ; preds = %9
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 34, ptr noundef @__PRETTY_FUNCTION__._Z9test_log2v) #6
  unreachable

36:                                               ; No predecessors!
  br label %37

37:                                               ; preds = %36, %34
  %38 = load i64, ptr %2, align 8, !tbaa !9
  %39 = trunc i64 %38 to i32
  %40 = shl i32 1, %39
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %40, i32 noundef %41, i32 noundef %42)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %44

44:                                               ; preds = %37
  %45 = load i64, ptr %2, align 8, !tbaa !9
  %46 = add i64 %45, 1
  store i64 %46, ptr %2, align 8, !tbaa !9
  br label %5, !llvm.loop !11

47:                                               ; preds = %8
  %48 = load i32, ptr %1, align 4, !tbaa !5
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %48)
  %50 = load i32, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret i32 %50
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN3glm4log2IjEET_S1_(i32 noundef) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZN3glm4log2IdEET_S1_(double noundef) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZN3glm3absIdEET_S1_(double noundef) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

declare i32 @printf(ptr noundef, ...) #4

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

attributes #0 = { mustprogress 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 willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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 #3 = { noreturn 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 = { "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 #5 = { nounwind }
attributes #6 = { noreturn 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [96 x i8], align 1
@__PRETTY_FUNCTION__._Z9test_log2v = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9test_log2v() local_unnamed_addr #0 {
  br label %3

1:                                                ; preds = %16
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef 0)
  ret i32 0

3:                                                ; preds = %0, %16
  %.01314 = phi i64 [ 1, %0 ], [ %18, %16 ]
  %4 = trunc nuw nsw i64 %.01314 to i32
  %5 = shl nuw nsw i32 1, %4
  %6 = tail call noundef i32 @_ZN3glm4log2IjEET_S1_(i32 noundef %5)
  %7 = uitofp nneg i32 %5 to double
  %8 = tail call noundef double @_ZN3glm4log2IdEET_S1_(double noundef %7)
  %9 = fptoui double %8 to i32
  %10 = uitofp i32 %6 to double
  %11 = uitofp i32 %9 to double
  %12 = fsub double %10, %11
  %13 = tail call noundef double @_ZN3glm3absIdEET_S1_(double noundef %12)
  %14 = fcmp ugt double %13, 2.400000e+01
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 34, ptr noundef nonnull @__PRETTY_FUNCTION__._Z9test_log2v) #4
  unreachable

16:                                               ; preds = %3
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %5, i32 noundef %6, i32 noundef %9)
  %18 = add nuw nsw i64 %.01314, 1
  %exitcond.not = icmp eq i64 %18, 24
  br i1 %exitcond.not, label %1, label %3, !llvm.loop !5
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN3glm4log2IjEET_S1_(i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZN3glm4log2IdEET_S1_(double noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZN3glm3absIdEET_S1_(double noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 = { noreturn 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 #3 = { nofree 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 = { noreturn 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass