; LLVM IR from gem5/gem5 :: src/systemc/dt/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 }

; 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
  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_int_base", ptr %6, i32 0, i32 1
  %8 = load i64, ptr %7, align 8, !tbaa !11
  %9 = load i64, ptr %3, align 8, !tbaa !9
  %10 = getelementptr inbounds %"class.sc_dt::sc_int_base", ptr %6, i32 0, i32 3
  %11 = load i32, ptr %10, align 4, !tbaa !15
  %12 = zext i32 %11 to i64
  %13 = lshr i64 %9, %12
  %14 = and i64 %8, %13
  store i64 %14, 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 %15

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

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

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

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"

; 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 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 20
  %5 = load i32, ptr %4, align 4, !tbaa !12
  %6 = zext nneg i32 %5 to i64
  %7 = lshr i64 -1, %6
  %8 = and i64 %7, %3
  %9 = lshr i64 %8, 32
  %10 = and i64 %8, 4294967295
  %11 = xor i64 %9, %10
  %12 = lshr i64 %11, 16
  %13 = and i64 %11, 65535
  %14 = xor i64 %12, %13
  %15 = lshr i64 %14, 8
  %16 = and i64 %14, 255
  %17 = xor i64 %15, %16
  %18 = lshr i64 %17, 4
  %19 = xor i64 %18, %17
  %20 = lshr i64 %19, 2
  %21 = xor i64 %20, %19
  %22 = lshr i64 %21, 1
  %23 = xor i64 %22, %21
  %24 = and i64 %23, 1
  %25 = icmp ne i64 %24, 0
  ret i1 %25
}

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_dt11sc_int_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}
!12 = !{!6, !11, i64 20}


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