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

; 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.3 = external hidden unnamed_addr constant [27 x i8], align 1

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.ctpop.i64(i64) #1

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

4:                                                ; preds = %31, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = icmp ult i32 %5, 64
  br i1 %6, label %7, label %34

7:                                                ; preds = %4
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = zext i32 %8 to i64
  %10 = shl i64 1, %9
  store i64 %10, ptr %2, align 8, !tbaa !9
  %11 = load i64, ptr %2, align 8, !tbaa !9
  %12 = call i32 @trailz_simple(i64 noundef %11)
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = icmp ne i32 %12, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %7
  store i32 -1, ptr %3, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %15, %7
  %17 = load i64, ptr %2, align 8, !tbaa !9
  %18 = call i32 @trailz_simple(i64 noundef %17)
  %19 = load i64, ptr %2, align 8, !tbaa !9
  %20 = call i64 @llvm.cttz.i64(i64 %19, i1 true)
  %21 = trunc i64 %20 to i32
  %22 = icmp ne i32 %18, %21
  br i1 %22, label %23, label %30

23:                                               ; preds = %16
  store i32 -1, ptr %3, align 4, !tbaa !5
  %24 = load i64, ptr %2, align 8, !tbaa !9
  %25 = load i64, ptr %2, align 8, !tbaa !9
  %26 = call i32 @trailz_simple(i64 noundef %25)
  %27 = load i64, ptr %2, align 8, !tbaa !9
  %28 = call i64 @llvm.ctpop.i64(i64 %27)
  %29 = trunc i64 %28 to i32
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str.3, i64 noundef %24, i32 noundef %26, i32 noundef %29) #6
  unreachable

30:                                               ; preds = %16
  br label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = add i32 %32, 1
  store i32 %33, ptr %1, align 4, !tbaa !5
  br label %4, !llvm.loop !11

34:                                               ; preds = %4
  store i64 0, ptr %2, align 8, !tbaa !9
  %35 = load i64, ptr %2, align 8, !tbaa !9
  %36 = call i32 @trailz_simple(i64 noundef %35)
  %37 = icmp ne i32 %36, 123456
  br i1 %37, label %38, label %39

38:                                               ; preds = %34
  store i32 -1, ptr %3, align 4, !tbaa !5
  br label %39

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

declare i32 @trailz_simple(i64 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.cttz.i64(i64, i1 immarg) #1

; Function Attrs: noreturn
declare void @err(i32 noundef, ptr noundef, ...) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { "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 "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 }

!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 = !{!"long 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.3 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @test_trailz() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %0, %8
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %8 ]
  %.018 = phi i32 [ 0, %0 ], [ %spec.select, %8 ]
  %2 = shl nuw i64 1, %indvars.iv
  %3 = tail call i32 @trailz_simple(i64 noundef %2) #3
  %4 = tail call i32 @trailz_simple(i64 noundef %2) #3
  %5 = zext i32 %4 to i64
  %.not14 = icmp eq i64 %indvars.iv, %5
  br i1 %.not14, label %8, label %6

6:                                                ; preds = %1
  %7 = tail call i32 @trailz_simple(i64 noundef %2) #3
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str.3, i64 noundef %2, i32 noundef %7, i32 noundef 1) #4
  unreachable

8:                                                ; preds = %1
  %9 = zext i32 %3 to i64
  %.not13 = icmp eq i64 %indvars.iv, %9
  %spec.select = select i1 %.not13, i32 %.018, i32 -1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 64
  br i1 %exitcond.not, label %10, label %1, !llvm.loop !5

10:                                               ; preds = %8
  %11 = tail call i32 @trailz_simple(i64 noundef 0) #3
  %.not = icmp eq i32 %11, 123456
  %spec.select15 = select i1 %.not, i32 %spec.select, i32 -1
  ret i32 %spec.select15
}

declare i32 @trailz_simple(i64 noundef) local_unnamed_addr #1

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

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 = { "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 "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 = { nounwind }
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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass