; LLVM IR from gem5/gem5 :: src/systemc/tests/systemc/misc/synth/combo/switch3/switch3.ll (Z6selectiii)

; 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_signed" = type { %"class.sc_dt::sc_value_base", i32, i32, i32, ptr }
%"class.sc_dt::sc_value_base" = type { ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef signext i16 @_Z6selectiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 personality ptr @__gxx_personality_v0 {
  %4 = alloca i16, align 2
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %"class.sc_dt::sc_signed", align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #4
  call void @_ZN5sc_dt9sc_signedC1Ei(ptr noundef nonnull align 8 dereferenceable(32) %8, i32 noundef 7)
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = ashr i32 %12, 2
  %14 = and i32 %13, 3
  switch i32 %14, label %15 [
    i32 0, label %16
    i32 1, label %29
    i32 2, label %38
    i32 3, label %49
  ]

15:                                               ; preds = %3
  br label %16

16:                                               ; preds = %15, %3
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = add nsw i32 %17, %18
  %20 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZN5sc_dt9sc_signedaSEi(ptr noundef nonnull align 8 dereferenceable(32) %8, i32 noundef %19)
          to label %21 unwind label %25

21:                                               ; preds = %16
  %22 = invoke noundef i32 @_ZNK5sc_dt9sc_signed6to_intEv(ptr noundef nonnull align 8 dereferenceable(32) %8)
          to label %23 unwind label %25

23:                                               ; preds = %21
  %24 = trunc i32 %22 to i16
  store i16 %24, ptr %4, align 2
  store i32 1, ptr %11, align 4
  br label %60

25:                                               ; preds = %56, %49, %45, %38, %34, %29, %21, %16
  %26 = landingpad { ptr, i32 }
          cleanup
  %27 = extractvalue { ptr, i32 } %26, 0
  store ptr %27, ptr %9, align 8
  %28 = extractvalue { ptr, i32 } %26, 1
  store i32 %28, ptr %10, align 4
  call void @_ZN5sc_dt9sc_signedD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #4
  br label %62

29:                                               ; preds = %3
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = sub nsw i32 %30, %31
  %33 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZN5sc_dt9sc_signedaSEi(ptr noundef nonnull align 8 dereferenceable(32) %8, i32 noundef %32)
          to label %34 unwind label %25

34:                                               ; preds = %29
  %35 = invoke noundef i32 @_ZNK5sc_dt9sc_signed6to_intEv(ptr noundef nonnull align 8 dereferenceable(32) %8)
          to label %36 unwind label %25

36:                                               ; preds = %34
  %37 = trunc i32 %35 to i16
  store i16 %37, ptr %4, align 2
  store i32 1, ptr %11, align 4
  br label %60

38:                                               ; preds = %3
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = ashr i32 %39, 16
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = shl i32 %41, 16
  %43 = add nsw i32 %40, %42
  %44 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZN5sc_dt9sc_signedaSEi(ptr noundef nonnull align 8 dereferenceable(32) %8, i32 noundef %43)
          to label %45 unwind label %25

45:                                               ; preds = %38
  %46 = invoke noundef i32 @_ZNK5sc_dt9sc_signed6to_intEv(ptr noundef nonnull align 8 dereferenceable(32) %8)
          to label %47 unwind label %25

47:                                               ; preds = %45
  %48 = trunc i32 %46 to i16
  store i16 %48, ptr %4, align 2
  store i32 1, ptr %11, align 4
  br label %60

49:                                               ; preds = %3
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = shl i32 %50, 16
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = ashr i32 %52, 16
  %54 = sub nsw i32 %51, %53
  %55 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZN5sc_dt9sc_signedaSEi(ptr noundef nonnull align 8 dereferenceable(32) %8, i32 noundef %54)
          to label %56 unwind label %25

56:                                               ; preds = %49
  %57 = invoke noundef i32 @_ZNK5sc_dt9sc_signed6to_intEv(ptr noundef nonnull align 8 dereferenceable(32) %8)
          to label %58 unwind label %25

58:                                               ; preds = %56
  %59 = trunc i32 %57 to i16
  store i16 %59, ptr %4, align 2
  store i32 1, ptr %11, align 4
  br label %60

60:                                               ; preds = %58, %47, %36, %23
  call void @_ZN5sc_dt9sc_signedD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #4
  %61 = load i16, ptr %4, align 2
  ret i16 %61

62:                                               ; preds = %25
  %63 = load ptr, ptr %9, align 8
  %64 = load i32, ptr %10, align 4
  %65 = insertvalue { ptr, i32 } poison, ptr %63, 0
  %66 = insertvalue { ptr, i32 } %65, i32 %64, 1
  resume { ptr, i32 } %66
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare void @_ZN5sc_dt9sc_signedC1Ei(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZN5sc_dt9sc_signedaSEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #0 align 2

declare i32 @__gxx_personality_v0(...)

declare noundef i32 @_ZNK5sc_dt9sc_signed6to_intEv(ptr noundef nonnull align 8 dereferenceable(32)) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5sc_dt9sc_signedD2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #3 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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

%"class.sc_dt::sc_signed" = type { %"class.sc_dt::sc_value_base", i32, i32, i32, ptr }
%"class.sc_dt::sc_value_base" = type { ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef signext i16 @_Z6selectiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %4 = alloca %"class.sc_dt::sc_signed", align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  call void @_ZN5sc_dt9sc_signedC1Ei(ptr noundef nonnull align 8 dereferenceable(32) %4, i32 noundef 7)
  %5 = lshr i32 %2, 2
  %6 = and i32 %5, 3
  switch i32 %6, label %default.unreachable11 [
    i32 0, label %7
    i32 1, label %11
    i32 2, label %13
    i32 3, label %17
  ]

default.unreachable11:                            ; preds = %3
  unreachable

7:                                                ; preds = %3
  %8 = add nsw i32 %1, %0
  br label %.invoke12

9:                                                ; preds = %.invoke12, %.invoke
  %10 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN5sc_dt9sc_signedD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %4) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  resume { ptr, i32 } %10

11:                                               ; preds = %3
  %12 = sub nsw i32 %0, %1
  br label %.invoke12

13:                                               ; preds = %3
  %14 = ashr i32 %0, 16
  %15 = shl i32 %1, 16
  %16 = add nsw i32 %15, %14
  br label %.invoke12

17:                                               ; preds = %3
  %18 = shl i32 %0, 16
  %19 = ashr i32 %1, 16
  %20 = sub nsw i32 %18, %19
  br label %.invoke12

.invoke12:                                        ; preds = %7, %11, %13, %17
  %21 = phi i32 [ %20, %17 ], [ %16, %13 ], [ %12, %11 ], [ %8, %7 ]
  %22 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZN5sc_dt9sc_signedaSEi(ptr noundef nonnull align 8 dereferenceable(32) %4, i32 noundef %21)
          to label %.invoke unwind label %9

.invoke:                                          ; preds = %.invoke12
  %23 = invoke noundef i32 @_ZNK5sc_dt9sc_signed6to_intEv(ptr noundef nonnull align 8 dereferenceable(32) %4)
          to label %24 unwind label %9

24:                                               ; preds = %.invoke
  %.0 = trunc i32 %23 to i16
  call void @_ZN5sc_dt9sc_signedD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %4) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  ret i16 %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare void @_ZN5sc_dt9sc_signedC1Ei(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZN5sc_dt9sc_signedaSEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) local_unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

declare noundef i32 @_ZNK5sc_dt9sc_signed6to_intEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5sc_dt9sc_signedD2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #3 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 #4 = { 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)"}


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