; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/datatypes/int (sc_uint_base)

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

@_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_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
  %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_uint_base", ptr %6, i32 0, i32 1
  %10 = load i64, ptr %9, align 8, !tbaa !11
  store i64 %10, 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 %11

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

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

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

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"

@_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_dt12sc_uint_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 = lshr i64 %3, 32
  %7 = and i64 %5, %3
  %8 = lshr i64 %7, 32
  %9 = and i64 %6, %5
  %10 = xor i64 %8, %9
  %11 = lshr i64 %3, 48
  %12 = lshr i64 %10, 16
  %13 = xor i64 %12, %10
  %14 = and i64 %13, %11
  %15 = lshr i64 %3, 56
  %16 = lshr i64 %14, 8
  %17 = xor i64 %16, %14
  %18 = and i64 %17, %15
  %19 = lshr i64 %3, 60
  %20 = lshr i64 %18, 4
  %21 = xor i64 %20, %18
  %22 = and i64 %21, %19
  %23 = lshr i64 %3, 62
  %24 = lshr i64 %22, 2
  %25 = xor i64 %24, %22
  %26 = and i64 %25, %23
  %27 = lshr i64 %3, 63
  %28 = lshr i64 %26, 1
  %29 = xor i64 %28, %26
  %30 = and i64 %29, %27
  %31 = icmp ne i64 %30, 0
  ret i1 %31
}

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_dt12sc_uint_baseE", !11, i64 0, !6, i64 8, !12, i64 16, !12, i64 20}
!11 = !{!"_ZTSN5sc_dt13sc_value_baseE"}
!12 = !{!"int", !7, i64 0}


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