; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/datatypes/int/sc_int_base.ll (ZNK5sc_dt11sc_int_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_int_base" = type { %"class.sc_dt::sc_value_base", i64, i32, i32 }
%"class.sc_dt::sc_value_base" = type { ptr }

@_ZN5sc_dt9UINT_ZEROE = external constant i64, align 8

; 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_dt11sc_int_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
  %7 = load i64, ptr @_ZN5sc_dt9UINT_ZEROE, align 8, !tbaa !9
  %8 = xor i64 %7, -1
  store i64 %8, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %9 = getelementptr inbounds %"class.sc_dt::sc_int_base", ptr %6, i32 0, i32 1
  %10 = load i64, ptr %9, align 8, !tbaa !11
  %11 = load i64, ptr %3, align 8, !tbaa !9
  %12 = getelementptr inbounds %"class.sc_dt::sc_int_base", ptr %6, i32 0, i32 3
  %13 = load i32, ptr %12, align 4, !tbaa !15
  %14 = zext i32 %13 to i64
  %15 = lshr i64 %11, %14
  %16 = and i64 %10, %15
  store i64 %16, 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 !16
  br label %17

17:                                               ; preds = %37, %1
  %18 = load i32, ptr %5, align 4, !tbaa !16
  %19 = ashr i32 %18, 1
  store i32 %19, ptr %5, align 4, !tbaa !16
  %20 = load i32, ptr %5, align 4, !tbaa !16
  %21 = load i64, ptr %3, align 8, !tbaa !9
  %22 = zext i32 %20 to i64
  %23 = lshr i64 %21, %22
  store i64 %23, ptr %3, align 8, !tbaa !9
  %24 = load i64, ptr %4, align 8, !tbaa !9
  %25 = load i64, ptr %3, align 8, !tbaa !9
  %26 = load i32, ptr %5, align 4, !tbaa !16
  %27 = zext i32 %26 to i64
  %28 = shl i64 %25, %27
  %29 = and i64 %24, %28
  %30 = load i32, ptr %5, align 4, !tbaa !16
  %31 = zext i32 %30 to i64
  %32 = lshr i64 %29, %31
  %33 = load i64, ptr %4, align 8, !tbaa !9
  %34 = load i64, ptr %3, align 8, !tbaa !9
  %35 = and i64 %33, %34
  %36 = xor i64 %32, %35
  store i64 %36, ptr %4, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %17
  %38 = load i32, ptr %5, align 4, !tbaa !16
  %39 = icmp ne i32 %38, 1
  br i1 %39, label %17, label %40, !llvm.loop !17

40:                                               ; preds = %37
  %41 = load i64, ptr %4, align 8, !tbaa !9
  %42 = icmp ne i64 %41, 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 %42
}

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_dt11sc_int_baseE", !13, i64 0, !10, i64 8, !14, i64 16, !14, i64 20}
!13 = !{!"_ZTSN5sc_dt13sc_value_baseE"}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !14, i64 20}
!16 = !{!14, !14, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

@_ZN5sc_dt9UINT_ZEROE = external local_unnamed_addr constant i64, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef zeroext i1 @_ZNK5sc_dt11sc_int_base10xor_reduceEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0) local_unnamed_addr #0 align 2 {
  %2 = load i64, ptr @_ZN5sc_dt9UINT_ZEROE, align 8, !tbaa !5
  %3 = xor i64 %2, -1
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %0, i64 20
  %7 = load i32, ptr %6, align 4, !tbaa !13
  %8 = zext nneg i32 %7 to i64
  %9 = lshr i64 %3, %8
  %10 = and i64 %9, %5
  %11 = lshr i64 %3, 32
  %12 = and i64 %10, %3
  %13 = lshr i64 %12, 32
  %14 = and i64 %11, %10
  %15 = xor i64 %13, %14
  %16 = lshr i64 %3, 48
  %17 = lshr i64 %15, 16
  %18 = xor i64 %17, %15
  %19 = and i64 %18, %16
  %20 = lshr i64 %3, 56
  %21 = lshr i64 %19, 8
  %22 = xor i64 %21, %19
  %23 = and i64 %22, %20
  %24 = lshr i64 %3, 60
  %25 = lshr i64 %23, 4
  %26 = xor i64 %25, %23
  %27 = and i64 %26, %24
  %28 = lshr i64 %3, 62
  %29 = lshr i64 %27, 2
  %30 = xor i64 %29, %27
  %31 = and i64 %30, %28
  %32 = lshr i64 %3, 63
  %33 = lshr i64 %31, 1
  %34 = xor i64 %33, %31
  %35 = and i64 %34, %32
  %36 = icmp ne i64 %35, 0
  ret i1 %36
}

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


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