; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/datatypes/int (sc_int_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_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 }

@_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 nounwind uwtable
define dso_local noundef zeroext i1 @_ZNK5sc_dt15sc_int_subref_r15concat_get_ctrlEPji(ptr noundef nonnull align 8 dereferenceable(28) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = sdiv i32 %12, 30
  store i32 %13, ptr %7, align 4, !tbaa !9
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = getelementptr inbounds %"class.sc_dt::sc_int_subref_r", ptr %11, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds %"class.sc_dt::sc_int_subref_r", ptr %11, i32 0, i32 4
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = sub nsw i32 %16, %18
  %20 = add nsw i32 %14, %19
  store i32 %20, ptr %9, align 4, !tbaa !9
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = sdiv i32 %21, 30
  store i32 %22, ptr %8, align 4, !tbaa !9
  %23 = getelementptr inbounds %"class.sc_dt::sc_int_subref_r", ptr %11, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [64 x [64 x i64]], ptr @_ZN5sc_dt8mask_intE, i64 0, i64 %25
  %27 = getelementptr inbounds %"class.sc_dt::sc_int_subref_r", ptr %11, i32 0, i32 4
  %28 = load i32, ptr %27, align 8, !tbaa !14
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [64 x i64], ptr %26, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !15
  %32 = xor i64 %31, -1
  store i64 %32, ptr %10, align 8, !tbaa !15
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i32, ptr %33, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = zext i32 %37 to i64
  %39 = load i64, ptr %10, align 8, !tbaa !15
  %40 = and i64 %38, %39
  %41 = trunc i64 %40 to i32
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %42, i64 %44
  store i32 %41, ptr %45, align 4, !tbaa !9
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = sub nsw i32 %46, %47
  switch i32 %48, label %85 [
    i32 1, label %49
    i32 2, label %56
    i32 3, label %68
  ]

49:                                               ; preds = %3
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %7, align 4, !tbaa !9
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  store i32 0, ptr %55, align 4, !tbaa !9
  br label %85

56:                                               ; preds = %3
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %7, align 4, !tbaa !9
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %7, align 4, !tbaa !9
  %62 = sext i32 %60 to i64
  %63 = getelementptr inbounds i32, ptr %59, i64 %62
  store i32 0, ptr %63, align 4, !tbaa !9
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i32, ptr %64, i64 %66
  store i32 0, ptr %67, align 4, !tbaa !9
  br label %85

68:                                               ; preds = %3
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %7, align 4, !tbaa !9
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = load i32, ptr %7, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %7, align 4, !tbaa !9
  %74 = sext i32 %72 to i64
  %75 = getelementptr inbounds i32, ptr %71, i64 %74
  store i32 0, ptr %75, align 4, !tbaa !9
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = load i32, ptr %7, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %7, align 4, !tbaa !9
  %79 = sext i32 %77 to i64
  %80 = getelementptr inbounds i32, ptr %76, i64 %79
  store i32 0, ptr %80, align 4, !tbaa !9
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load i32, ptr %7, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i32, ptr %81, i64 %83
  store i32 0, ptr %84, align 4, !tbaa !9
  br label %85

85:                                               ; preds = %68, %56, %49, %3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i1 false
}

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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTSN5sc_dt15sc_int_subref_rE", !13, i64 0, !10, i64 8, !6, i64 16, !10, i64 24}
!13 = !{!"_ZTSN5sc_dt13sc_value_baseE"}
!14 = !{!12, !10, i64 24}
!15 = !{!16, !16, i64 0}
!16 = !{!"long long", !7, i64 0}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef zeroext i1 @_ZNK5sc_dt15sc_int_subref_r15concat_get_ctrlEPji(ptr nocapture noundef nonnull readonly align 8 dereferenceable(28) %0, ptr nocapture noundef %1, i32 noundef %2) unnamed_addr #0 align 2 {
  %4 = sdiv i32 %2, 30
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !12
  %9 = add i32 %6, %2
  %10 = sub i32 %9, %8
  %11 = sdiv i32 %10, 30
  %12 = sext i32 %6 to i64
  %13 = sext i32 %8 to i64
  %14 = getelementptr inbounds [64 x [64 x i64]], ptr @_ZN5sc_dt8mask_intE, i64 0, i64 %12, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !13
  %16 = sext i32 %4 to i64
  %17 = getelementptr inbounds i32, ptr %1, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !15
  %19 = trunc i64 %15 to i32
  %20 = xor i32 %19, -1
  %21 = and i32 %18, %20
  store i32 %21, ptr %17, align 4, !tbaa !15
  %22 = sub nsw i32 %11, %4
  switch i32 %22, label %27 [
    i32 1, label %.sink.split
    i32 2, label %.sink.split.sink.split
    i32 3, label %23
  ]

23:                                               ; preds = %3
  %24 = getelementptr i8, ptr %17, i64 4
  store i32 0, ptr %24, align 4, !tbaa !15
  br label %.sink.split.sink.split

.sink.split.sink.split:                           ; preds = %3, %23
  %.sink26 = phi i64 [ 8, %23 ], [ 4, %3 ]
  %.sink25.ph = phi i64 [ 12, %23 ], [ 8, %3 ]
  %25 = getelementptr i8, ptr %17, i64 %.sink26
  store i32 0, ptr %25, align 4, !tbaa !15
  br label %.sink.split

.sink.split:                                      ; preds = %.sink.split.sink.split, %3
  %.sink25 = phi i64 [ 4, %3 ], [ %.sink25.ph, %.sink.split.sink.split ]
  %26 = getelementptr i8, ptr %17, i64 %.sink25
  store i32 0, ptr %26, align 4, !tbaa !15
  br label %27

27:                                               ; preds = %.sink.split, %3
  ret i1 false
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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_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 = !{!6, !8, i64 24}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !9, i64 0}
!15 = !{!8, !8, i64 0}


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