; LLVM IR from Dovyski/opengl-demos :: libs/glm-0.9.9.3/test/core/core_func_integer_find_msb.ll (Z5nlz1aj)

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

; 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 i32 @_Z5nlz1aj(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = icmp sle i32 %6, 0
  br i1 %7, label %8, label %13

8:                                                ; preds = %1
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = xor i32 %9, -1
  %11 = lshr i32 %10, 26
  %12 = and i32 %11, 32
  store i32 %12, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %55

13:                                               ; preds = %1
  store i32 1, ptr %4, align 4, !tbaa !5
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = lshr i32 %14, 16
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %22

17:                                               ; preds = %13
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = add nsw i32 %18, 16
  store i32 %19, ptr %4, align 4, !tbaa !5
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = shl i32 %20, 16
  store i32 %21, ptr %3, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %17, %13
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = lshr i32 %23, 24
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %31

26:                                               ; preds = %22
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = add nsw i32 %27, 8
  store i32 %28, ptr %4, align 4, !tbaa !5
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = shl i32 %29, 8
  store i32 %30, ptr %3, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %26, %22
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = lshr i32 %32, 28
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %40

35:                                               ; preds = %31
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = add nsw i32 %36, 4
  store i32 %37, ptr %4, align 4, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = shl i32 %38, 4
  store i32 %39, ptr %3, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %35, %31
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = lshr i32 %41, 30
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %49

44:                                               ; preds = %40
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = add nsw i32 %45, 2
  store i32 %46, ptr %4, align 4, !tbaa !5
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = shl i32 %47, 2
  store i32 %48, ptr %3, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %44, %40
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = lshr i32 %51, 31
  %53 = sub i32 %50, %52
  store i32 %53, ptr %4, align 4, !tbaa !5
  %54 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %54, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %55

55:                                               ; preds = %49, %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %56 = load i32, ptr %2, align 4
  ret i32 %56
}

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


; 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 noundef i32 @_Z5nlz1aj(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i32 %0, 1
  br i1 %2, label %3, label %7

3:                                                ; preds = %1
  %4 = xor i32 %0, -1
  %5 = lshr i32 %4, 26
  %6 = and i32 %5, 32
  br label %20

7:                                                ; preds = %1
  %8 = icmp ult i32 %0, 65536
  %9 = shl nuw i32 %0, 16
  %spec.select = select i1 %8, i32 %9, i32 %0
  %spec.select25 = select i1 %8, i32 17, i32 1
  %10 = icmp ult i32 %spec.select, 16777216
  %11 = or disjoint i32 %spec.select25, 8
  %12 = shl nuw i32 %spec.select, 8
  %.119 = select i1 %10, i32 %12, i32 %spec.select
  %.1 = select i1 %10, i32 %11, i32 %spec.select25
  %13 = icmp ult i32 %.119, 268435456
  %14 = or disjoint i32 %.1, 4
  %15 = shl nuw i32 %.119, 4
  %.220 = select i1 %13, i32 %15, i32 %.119
  %.2 = select i1 %13, i32 %14, i32 %.1
  %16 = icmp ult i32 %.220, 1073741824
  %17 = or disjoint i32 %.2, 2
  %18 = shl nuw i32 %.220, 2
  %.321 = select i1 %16, i32 %18, i32 %.220
  %.3 = select i1 %16, i32 %17, i32 %.2
  %.neg = ashr i32 %.321, 31
  %19 = add nsw i32 %.neg, %.3
  br label %20

20:                                               ; preds = %7, %3
  %.022 = phi i32 [ %6, %3 ], [ %19, %7 ]
  ret i32 %.022
}

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