; LLVM IR from tyalie/Sudoku-Generator-CPP :: src/Generator/GenSudoku.ll (ZN9GenSudoku13getTotalCellsEv)

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

%class.Sudoku = type { [81 x i8], i8 }

; 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 @_ZN9GenSudoku13getTotalCellsEv(ptr noundef nonnull align 8 dereferenceable(96) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %9 = getelementptr inbounds %class.Sudoku, ptr %8, i32 0, i32 0
  store ptr %9, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds [81 x i8], ptr %10, i64 0, i64 0
  store ptr %11, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds [81 x i8], ptr %12, i64 0, i64 0
  %14 = getelementptr inbounds i8, ptr %13, i64 81
  store ptr %14, ptr %6, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %30, %1
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp ne ptr %16, %17
  br i1 %18, label %20, label %19

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

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %21, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = sext i8 %23 to i32
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %20
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %3, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %26, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i32 1
  store ptr %32, ptr %5, align 8, !tbaa !5
  br label %15

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

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


; 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(argmem: read) uwtable
define dso_local noundef i32 @_ZN9GenSudoku13getTotalCellsEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(96) %0) local_unnamed_addr #0 align 2 {
vector.ph:
  %1 = getelementptr inbounds i8, ptr %0, i64 4
  %wide.load14 = load <4 x i8>, ptr %1, align 4, !tbaa !5
  %2 = icmp ne <4 x i8> %wide.load14, zeroinitializer
  %3 = zext <4 x i1> %2 to <4 x i32>
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %wide.load14.1 = load <4 x i8>, ptr %4, align 4, !tbaa !5
  %5 = icmp ne <4 x i8> %wide.load14.1, zeroinitializer
  %6 = zext <4 x i1> %5 to <4 x i32>
  %7 = add nuw nsw <4 x i32> %3, %6
  %8 = getelementptr inbounds i8, ptr %0, i64 20
  %wide.load14.2 = load <4 x i8>, ptr %8, align 4, !tbaa !5
  %9 = icmp ne <4 x i8> %wide.load14.2, zeroinitializer
  %10 = zext <4 x i1> %9 to <4 x i32>
  %11 = add nuw nsw <4 x i32> %7, %10
  %12 = getelementptr inbounds i8, ptr %0, i64 28
  %wide.load14.3 = load <4 x i8>, ptr %12, align 4, !tbaa !5
  %13 = icmp ne <4 x i8> %wide.load14.3, zeroinitializer
  %14 = zext <4 x i1> %13 to <4 x i32>
  %15 = add nuw nsw <4 x i32> %11, %14
  %16 = getelementptr inbounds i8, ptr %0, i64 36
  %wide.load14.4 = load <4 x i8>, ptr %16, align 4, !tbaa !5
  %17 = icmp ne <4 x i8> %wide.load14.4, zeroinitializer
  %18 = zext <4 x i1> %17 to <4 x i32>
  %19 = add nuw nsw <4 x i32> %15, %18
  %20 = getelementptr inbounds i8, ptr %0, i64 44
  %wide.load14.5 = load <4 x i8>, ptr %20, align 4, !tbaa !5
  %21 = icmp ne <4 x i8> %wide.load14.5, zeroinitializer
  %22 = zext <4 x i1> %21 to <4 x i32>
  %23 = add nuw nsw <4 x i32> %19, %22
  %24 = getelementptr inbounds i8, ptr %0, i64 52
  %wide.load14.6 = load <4 x i8>, ptr %24, align 4, !tbaa !5
  %25 = icmp ne <4 x i8> %wide.load14.6, zeroinitializer
  %26 = zext <4 x i1> %25 to <4 x i32>
  %27 = add nuw nsw <4 x i32> %23, %26
  %28 = getelementptr inbounds i8, ptr %0, i64 60
  %wide.load14.7 = load <4 x i8>, ptr %28, align 4, !tbaa !5
  %29 = icmp ne <4 x i8> %wide.load14.7, zeroinitializer
  %30 = zext <4 x i1> %29 to <4 x i32>
  %31 = add <4 x i32> %27, %30
  %32 = getelementptr inbounds i8, ptr %0, i64 68
  %wide.load14.8 = load <4 x i8>, ptr %32, align 4, !tbaa !5
  %33 = icmp ne <4 x i8> %wide.load14.8, zeroinitializer
  %34 = zext <4 x i1> %33 to <4 x i32>
  %35 = add <4 x i32> %31, %34
  %36 = getelementptr inbounds i8, ptr %0, i64 76
  %wide.load14.9 = load <4 x i8>, ptr %36, align 4, !tbaa !5
  %37 = icmp ne <4 x i8> %wide.load14.9, zeroinitializer
  %38 = zext <4 x i1> %37 to <4 x i32>
  %39 = add <4 x i32> %35, %38
  %wide.load = load <4 x i8>, ptr %0, align 8, !tbaa !5
  %40 = icmp ne <4 x i8> %wide.load, zeroinitializer
  %41 = zext <4 x i1> %40 to <4 x i32>
  %42 = getelementptr inbounds i8, ptr %0, i64 8
  %wide.load.1 = load <4 x i8>, ptr %42, align 8, !tbaa !5
  %43 = icmp ne <4 x i8> %wide.load.1, zeroinitializer
  %44 = zext <4 x i1> %43 to <4 x i32>
  %45 = add nuw nsw <4 x i32> %41, %44
  %46 = getelementptr inbounds i8, ptr %0, i64 16
  %wide.load.2 = load <4 x i8>, ptr %46, align 8, !tbaa !5
  %47 = icmp ne <4 x i8> %wide.load.2, zeroinitializer
  %48 = zext <4 x i1> %47 to <4 x i32>
  %49 = add nuw nsw <4 x i32> %45, %48
  %50 = getelementptr inbounds i8, ptr %0, i64 24
  %wide.load.3 = load <4 x i8>, ptr %50, align 8, !tbaa !5
  %51 = icmp ne <4 x i8> %wide.load.3, zeroinitializer
  %52 = zext <4 x i1> %51 to <4 x i32>
  %53 = add nuw nsw <4 x i32> %49, %52
  %54 = getelementptr inbounds i8, ptr %0, i64 32
  %wide.load.4 = load <4 x i8>, ptr %54, align 8, !tbaa !5
  %55 = icmp ne <4 x i8> %wide.load.4, zeroinitializer
  %56 = zext <4 x i1> %55 to <4 x i32>
  %57 = add nuw nsw <4 x i32> %53, %56
  %58 = getelementptr inbounds i8, ptr %0, i64 40
  %wide.load.5 = load <4 x i8>, ptr %58, align 8, !tbaa !5
  %59 = icmp ne <4 x i8> %wide.load.5, zeroinitializer
  %60 = zext <4 x i1> %59 to <4 x i32>
  %61 = add nuw nsw <4 x i32> %57, %60
  %62 = getelementptr inbounds i8, ptr %0, i64 48
  %wide.load.6 = load <4 x i8>, ptr %62, align 8, !tbaa !5
  %63 = icmp ne <4 x i8> %wide.load.6, zeroinitializer
  %64 = zext <4 x i1> %63 to <4 x i32>
  %65 = add nuw nsw <4 x i32> %61, %64
  %66 = getelementptr inbounds i8, ptr %0, i64 56
  %wide.load.7 = load <4 x i8>, ptr %66, align 8, !tbaa !5
  %67 = icmp ne <4 x i8> %wide.load.7, zeroinitializer
  %68 = zext <4 x i1> %67 to <4 x i32>
  %69 = add <4 x i32> %65, %68
  %70 = getelementptr inbounds i8, ptr %0, i64 64
  %wide.load.8 = load <4 x i8>, ptr %70, align 8, !tbaa !5
  %71 = icmp ne <4 x i8> %wide.load.8, zeroinitializer
  %72 = zext <4 x i1> %71 to <4 x i32>
  %73 = add <4 x i32> %69, %72
  %74 = getelementptr inbounds i8, ptr %0, i64 72
  %wide.load.9 = load <4 x i8>, ptr %74, align 8, !tbaa !5
  %75 = icmp ne <4 x i8> %wide.load.9, zeroinitializer
  %76 = zext <4 x i1> %75 to <4 x i32>
  %77 = add <4 x i32> %73, %76
  %bin.rdx = add <4 x i32> %39, %77
  %78 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %.09.ptr = getelementptr inbounds i8, ptr %0, i64 80
  %79 = load i8, ptr %.09.ptr, align 8, !tbaa !5
  %.not10 = icmp ne i8 %79, 0
  %80 = zext i1 %.not10 to i32
  %spec.select = add nuw nsw i32 %78, %80
  ret i32 %spec.select
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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 speculatable willreturn memory(none) }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass