; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/datatypes/int/sc_int_base.ll (ZN5sc_dt13sc_int_subrefaSEx)

; 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_subref_r" = type <{ %"class.sc_dt::sc_value_base", i32, [4 x i8], ptr, i32, [4 x i8] }>
%"class.sc_dt::sc_value_base" = type { ptr }
%"class.sc_dt::sc_int_base" = type { %"class.sc_dt::sc_value_base", i64, i32, i32 }

@_ZN5sc_dt8mask_intE = external constant [64 x [64 x i64]], align 16

; 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 uwtable
define dso_local noundef nonnull align 8 dereferenceable(28) ptr @_ZN5sc_dt13sc_int_subrefaSEx(ptr noundef nonnull align 8 dereferenceable(28) %0, i64 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %8 = getelementptr inbounds %"class.sc_dt::sc_int_subref_r", ptr %7, i32 0, i32 3
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds %"class.sc_dt::sc_int_base", ptr %9, i32 0, i32 1
  %11 = load i64, ptr %10, align 8, !tbaa !15
  store i64 %11, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %12 = getelementptr inbounds %"class.sc_dt::sc_int_subref_r", ptr %7, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !17
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [64 x [64 x i64]], ptr @_ZN5sc_dt8mask_intE, i64 0, i64 %14
  %16 = getelementptr inbounds %"class.sc_dt::sc_int_subref_r", ptr %7, i32 0, i32 4
  %17 = load i32, ptr %16, align 8, !tbaa !18
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [64 x i64], ptr %15, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !9
  store i64 %20, ptr %6, align 8, !tbaa !9
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = and i64 %22, %21
  store i64 %23, ptr %5, align 8, !tbaa !9
  %24 = load i64, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds %"class.sc_dt::sc_int_subref_r", ptr %7, i32 0, i32 4
  %26 = load i32, ptr %25, align 8, !tbaa !18
  %27 = zext i32 %26 to i64
  %28 = shl i64 %24, %27
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = xor i64 %29, -1
  %31 = and i64 %28, %30
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = or i64 %32, %31
  store i64 %33, ptr %5, align 8, !tbaa !9
  %34 = load i64, ptr %5, align 8, !tbaa !9
  %35 = getelementptr inbounds %"class.sc_dt::sc_int_subref_r", ptr %7, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = getelementptr inbounds %"class.sc_dt::sc_int_base", ptr %36, i32 0, i32 1
  store i64 %34, ptr %37, align 8, !tbaa !15
  %38 = getelementptr inbounds %"class.sc_dt::sc_int_subref_r", ptr %7, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  call void @_ZN5sc_dt11sc_int_base11extend_signEv(ptr noundef nonnull align 8 dereferenceable(24) %39)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %7
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5sc_dt11sc_int_base11extend_signEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 #3 = { 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, !6, i64 16}
!12 = !{!"_ZTSN5sc_dt15sc_int_subref_rE", !13, i64 0, !14, i64 8, !6, i64 16, !14, i64 24}
!13 = !{!"_ZTSN5sc_dt13sc_value_baseE"}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !10, i64 8}
!16 = !{!"_ZTSN5sc_dt11sc_int_baseE", !13, i64 0, !10, i64 8, !14, i64 16, !14, i64 20}
!17 = !{!12, !14, i64 8}
!18 = !{!12, !14, i64 24}


; 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_dt8mask_intE = external local_unnamed_addr constant [64 x [64 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef nonnull align 8 dereferenceable(28) ptr @_ZN5sc_dt13sc_int_subrefaSEx(ptr noundef nonnull readonly returned align 8 dereferenceable(28) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !15
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load i32, ptr %10, align 8, !tbaa !16
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [64 x [64 x i64]], ptr @_ZN5sc_dt8mask_intE, i64 0, i64 %9, i64 %12
  %14 = load i64, ptr %13, align 8, !tbaa !17
  %15 = and i64 %14, %6
  %16 = zext nneg i32 %11 to i64
  %17 = shl i64 %1, %16
  %18 = xor i64 %14, -1
  %19 = and i64 %17, %18
  %20 = or i64 %19, %15
  store i64 %20, ptr %5, align 8, !tbaa !12
  tail call void @_ZN5sc_dt11sc_int_base11extend_signEv(ptr noundef nonnull align 8 dereferenceable(24) %4)
  ret ptr %0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5sc_dt11sc_int_base11extend_signEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

attributes #0 = { 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" }

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass