; LLVM IR from gem5/gem5 :: src/systemc/dt/int/sc_uint_base.ll (ZNK5sc_dt12sc_uint_base10xor_reduceEv)

; 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.sc_dt::sc_uint_base" = type { %"class.sc_dt::sc_value_base", i64, i32, i32 }
%"class.sc_dt::sc_value_base" = type { ptr }

; 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 zeroext i1 @_ZNK5sc_dt12sc_uint_base10xor_reduceEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 -1, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %7 = getelementptr inbounds %"class.sc_dt::sc_uint_base", ptr %6, i32 0, i32 1
  %8 = load i64, ptr %7, align 8, !tbaa !11
  store i64 %8, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 64, ptr %5, align 4, !tbaa !15
  br label %9

9:                                                ; preds = %29, %1
  %10 = load i32, ptr %5, align 4, !tbaa !15
  %11 = ashr i32 %10, 1
  store i32 %11, ptr %5, align 4, !tbaa !15
  %12 = load i32, ptr %5, align 4, !tbaa !15
  %13 = load i64, ptr %3, align 8, !tbaa !9
  %14 = zext i32 %12 to i64
  %15 = lshr i64 %13, %14
  store i64 %15, ptr %3, align 8, !tbaa !9
  %16 = load i64, ptr %4, align 8, !tbaa !9
  %17 = load i64, ptr %3, align 8, !tbaa !9
  %18 = load i32, ptr %5, align 4, !tbaa !15
  %19 = zext i32 %18 to i64
  %20 = shl i64 %17, %19
  %21 = and i64 %16, %20
  %22 = load i32, ptr %5, align 4, !tbaa !15
  %23 = zext i32 %22 to i64
  %24 = lshr i64 %21, %23
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = load i64, ptr %3, align 8, !tbaa !9
  %27 = and i64 %25, %26
  %28 = xor i64 %24, %27
  store i64 %28, ptr %4, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %9
  %30 = load i32, ptr %5, align 4, !tbaa !15
  %31 = icmp ne i32 %30, 1
  br i1 %31, label %9, label %32, !llvm.loop !16

32:                                               ; preds = %29
  %33 = load i64, ptr %4, align 8, !tbaa !9
  %34 = icmp ne i64 %33, 0
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i1 %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 = !{!"long long", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTSN5sc_dt12sc_uint_baseE", !13, i64 0, !10, i64 8, !14, i64 16, !14, i64 20}
!13 = !{!"_ZTSN5sc_dt13sc_value_baseE"}
!14 = !{!"int", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef zeroext i1 @_ZNK5sc_dt12sc_uint_base10xor_reduceEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = lshr i64 %3, 32
  %5 = and i64 %3, 4294967295
  %6 = xor i64 %4, %5
  %7 = lshr i64 %6, 16
  %8 = and i64 %6, 65535
  %9 = xor i64 %7, %8
  %10 = lshr i64 %9, 8
  %11 = and i64 %9, 255
  %12 = xor i64 %10, %11
  %13 = lshr i64 %12, 4
  %14 = xor i64 %13, %12
  %15 = lshr i64 %14, 2
  %16 = xor i64 %15, %14
  %17 = lshr i64 %16, 1
  %18 = xor i64 %17, %16
  %19 = and i64 %18, 1
  %20 = icmp ne i64 %19, 0
  ret i1 %20
}

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

!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, !8, i64 8}
!6 = !{!"_ZTSN5sc_dt12sc_uint_baseE", !7, i64 0, !8, i64 8, !11, i64 16, !11, i64 20}
!7 = !{!"_ZTSN5sc_dt13sc_value_baseE"}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass