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

; Function Attrs: nounwind uwtable
declare dso_local i32 @random_int() #0

; 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

; Function Attrs: nounwind uwtable
declare dso_local i64 @random_det(i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.ctpop.i64(i64) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @test_popcnt() #0 {
  %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 = %24, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = icmp ult i32 %5, 10000
  br i1 %6, label %7, label %27

7:                                                ; preds = %4
  %8 = call i32 @random_int()
  %9 = call i64 @random_det(i32 noundef %8)
  store i64 %9, ptr %2, align 8, !tbaa !9
  %10 = load i64, ptr %2, align 8, !tbaa !9
  %11 = call i32 @popcnt_simple(i64 noundef %10)
  %12 = load i64, ptr %2, align 8, !tbaa !9
  %13 = call i64 @llvm.ctpop.i64(i64 %12)
  %14 = trunc i64 %13 to i32
  %15 = icmp ne i32 %11, %14
  br i1 %15, label %16, label %23

16:                                               ; preds = %7
  store i32 -1, ptr %3, align 4, !tbaa !5
  store i32 10000, ptr %1, align 4, !tbaa !5
  %17 = load i64, ptr %2, align 8, !tbaa !9
  %18 = load i64, ptr %2, align 8, !tbaa !9
  %19 = call i32 @popcnt_simple(i64 noundef %18)
  %20 = load i64, ptr %2, align 8, !tbaa !9
  %21 = call i64 @llvm.ctpop.i64(i64 %20)
  %22 = trunc i64 %21 to i32
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str.4, i64 noundef %17, i32 noundef %19, i32 noundef %22) #6
  unreachable

23:                                               ; preds = %7
  br label %24

24:                                               ; preds = %23
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = add i32 %25, 1
  store i32 %26, ptr %1, align 4, !tbaa !5
  br label %4, !llvm.loop !11

27:                                               ; preds = %4
  %28 = 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 %28
}

declare i32 @popcnt_simple(i64 noundef) #4

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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 }

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @random_int() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @random_det(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.ctpop.i64(i64) #1

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

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

1:                                                ; preds = %3
  %2 = add nuw nsw i32 %.010, 1
  %exitcond.not = icmp eq i32 %2, 10000
  br i1 %exitcond.not, label %11, label %3, !llvm.loop !5

3:                                                ; preds = %0, %1
  %.010 = phi i32 [ 0, %0 ], [ %2, %1 ]
  %4 = tail call i32 @random_int()
  %5 = tail call i64 @random_det(i32 noundef %4)
  %6 = tail call i32 @popcnt_simple(i64 noundef %5) #4
  %7 = tail call range(i64 0, 65) i64 @llvm.ctpop.i64(i64 %5)
  %8 = trunc nuw nsw i64 %7 to i32
  %.not = icmp eq i32 %6, %8
  br i1 %.not, label %1, label %9

9:                                                ; preds = %3
  %10 = tail call i32 @popcnt_simple(i64 noundef %5) #4
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str.4, i64 noundef %5, i32 noundef %10, i32 noundef %8) #5
  unreachable

11:                                               ; preds = %1
  ret i32 0
}

declare i32 @popcnt_simple(i64 noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { "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 = { nounwind }
attributes #5 = { 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,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass