; LLVM IR from scemama/slaterlib :: src (simple)

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

6:                                                ; preds = %1
  store i32 123456, ptr %3, align 4, !tbaa !9
  br label %25

7:                                                ; preds = %1
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %21, %7
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = icmp ult i32 %9, 64
  br i1 %10, label %11, label %19

11:                                               ; preds = %8
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = xor i64 %12, -1
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = zext i32 %14 to i64
  %16 = shl i64 1, %15
  %17 = and i64 %13, %16
  %18 = icmp ne i64 %17, 0
  br label %19

19:                                               ; preds = %11, %8
  %20 = phi i1 [ false, %8 ], [ %18, %11 ]
  br i1 %20, label %21, label %24

21:                                               ; preds = %19
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = add i32 %22, 1
  store i32 %23, ptr %3, align 4, !tbaa !9
  br label %8, !llvm.loop !11

24:                                               ; preds = %19
  br label %25

25:                                               ; preds = %24, %6
  %26 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %26
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

; Function Attrs: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local i32 @trailz_simple(i64 noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq i64 %0, 0
  br i1 %2, label %.critedge, label %.preheader

.preheader:                                       ; preds = %1, %11
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %11 ], [ 0, %1 ]
  %3 = shl nuw i64 1, %indvars.iv
  %4 = and i64 %3, %0
  %.not.not = icmp eq i64 %4, 0
  br i1 %.not.not, label %.preheader.1, label %.critedge.loopexit.split.loop.exit9

.preheader.1:                                     ; preds = %.preheader
  %5 = shl nuw i64 2, %indvars.iv
  %6 = and i64 %5, %0
  %.not.not.1 = icmp eq i64 %6, 0
  br i1 %.not.not.1, label %.preheader.2, label %.critedge.loopexit.split.loop.exit9.split.loop.exit15

.preheader.2:                                     ; preds = %.preheader.1
  %7 = shl nuw i64 4, %indvars.iv
  %8 = and i64 %7, %0
  %.not.not.2 = icmp eq i64 %8, 0
  br i1 %.not.not.2, label %.preheader.3, label %.critedge.loopexit.split.loop.exit9.split.loop.exit13

.preheader.3:                                     ; preds = %.preheader.2
  %9 = shl nuw i64 8, %indvars.iv
  %10 = and i64 %9, %0
  %.not.not.3 = icmp eq i64 %10, 0
  br i1 %.not.not.3, label %11, label %.critedge.loopexit.split.loop.exit9.split.loop.exit

11:                                               ; preds = %.preheader.3
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 64
  br i1 %exitcond.not.3, label %.critedge, label %.preheader, !llvm.loop !5

.critedge.loopexit.split.loop.exit9.split.loop.exit: ; preds = %.preheader.3
  %indvars.iv.next.2.le = or disjoint i64 %indvars.iv, 3
  br label %.critedge.loopexit.split.loop.exit9

.critedge.loopexit.split.loop.exit9.split.loop.exit13: ; preds = %.preheader.2
  %indvars.iv.next.1.le = or disjoint i64 %indvars.iv, 2
  br label %.critedge.loopexit.split.loop.exit9

.critedge.loopexit.split.loop.exit9.split.loop.exit15: ; preds = %.preheader.1
  %indvars.iv.next.le = or disjoint i64 %indvars.iv, 1
  br label %.critedge.loopexit.split.loop.exit9

.critedge.loopexit.split.loop.exit9:              ; preds = %.preheader, %.critedge.loopexit.split.loop.exit9.split.loop.exit15, %.critedge.loopexit.split.loop.exit9.split.loop.exit13, %.critedge.loopexit.split.loop.exit9.split.loop.exit
  %indvars.iv.lcssa = phi i64 [ %indvars.iv.next.2.le, %.critedge.loopexit.split.loop.exit9.split.loop.exit ], [ %indvars.iv.next.1.le, %.critedge.loopexit.split.loop.exit9.split.loop.exit13 ], [ %indvars.iv.next.le, %.critedge.loopexit.split.loop.exit9.split.loop.exit15 ], [ %indvars.iv, %.preheader ]
  %12 = trunc nuw nsw i64 %indvars.iv.lcssa to i32
  br label %.critedge

.critedge:                                        ; preds = %11, %.critedge.loopexit.split.loop.exit9, %1
  %.1 = phi i32 [ 123456, %1 ], [ %12, %.critedge.loopexit.split.loop.exit9 ], [ 64, %11 ]
  ret i32 %.1
}

attributes #0 = { nofree norecurse nosync nounwind 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)"}
!5 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass