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

; 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_unsigned" = type { %"class.sc_dt::sc_value_base", i32, i32, i32, ptr }
%"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 i64 @_ZNK5sc_dt11sc_unsigned17concat_get_uint64Ev(ptr noundef nonnull align 8 dereferenceable(32) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %5 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %4, i32 0, i32 1
  %6 = load i32, ptr %5, align 8, !tbaa !9
  switch i32 %6, label %39 [
    i32 1, label %7
  ]

7:                                                ; preds = %1
  store i64 0, ptr %3, align 8, !tbaa !13
  %8 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %4, i32 0, i32 3
  %9 = load i32, ptr %8, align 8, !tbaa !15
  %10 = icmp sgt i32 %9, 2
  br i1 %10, label %11, label %17

11:                                               ; preds = %7
  %12 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %4, i32 0, i32 4
  %13 = load ptr, ptr %12, align 8, !tbaa !16
  %14 = getelementptr inbounds i32, ptr %13, i64 2
  %15 = load i32, ptr %14, align 4, !tbaa !17
  %16 = zext i32 %15 to i64
  store i64 %16, ptr %3, align 8, !tbaa !13
  br label %17

17:                                               ; preds = %11, %7
  %18 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %4, i32 0, i32 3
  %19 = load i32, ptr %18, align 8, !tbaa !15
  %20 = icmp sgt i32 %19, 1
  br i1 %20, label %21, label %30

21:                                               ; preds = %17
  %22 = load i64, ptr %3, align 8, !tbaa !13
  %23 = shl i64 %22, 30
  %24 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %4, i32 0, i32 4
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = getelementptr inbounds i32, ptr %25, i64 1
  %27 = load i32, ptr %26, align 4, !tbaa !17
  %28 = zext i32 %27 to i64
  %29 = or i64 %23, %28
  store i64 %29, ptr %3, align 8, !tbaa !13
  br label %30

30:                                               ; preds = %21, %17
  %31 = load i64, ptr %3, align 8, !tbaa !13
  %32 = shl i64 %31, 30
  %33 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %4, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = getelementptr inbounds i32, ptr %34, i64 0
  %36 = load i32, ptr %35, align 4, !tbaa !17
  %37 = zext i32 %36 to i64
  %38 = or i64 %32, %37
  store i64 %38, ptr %3, align 8, !tbaa !13
  br label %40

39:                                               ; preds = %1
  store i64 0, ptr %3, align 8, !tbaa !13
  br label %40

40:                                               ; preds = %39, %30
  %41 = load i64, ptr %3, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i64 %41
}

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_ZNK5sc_dt11sc_unsigned17concat_get_uint64Ev(ptr nocapture noundef nonnull readonly align 8 dereferenceable(32) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %cond = icmp eq i32 %3, 1
  br i1 %cond, label %4, label %26

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !12
  %7 = icmp sgt i32 %6, 2
  br i1 %7, label %.thread, label %14

.thread:                                          ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load i32, ptr %10, align 4, !tbaa !14
  %12 = zext i32 %11 to i64
  %13 = shl nuw nsw i64 %12, 30
  br label %._crit_edge

14:                                               ; preds = %4
  %15 = icmp eq i32 %6, 2
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 24
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !13
  br i1 %15, label %._crit_edge, label %._crit_edge5

._crit_edge:                                      ; preds = %14, %.thread
  %16 = phi ptr [ %9, %.thread ], [ %.pre, %14 ]
  %.04 = phi i64 [ %13, %.thread ], [ 0, %14 ]
  %17 = getelementptr inbounds i8, ptr %16, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %19 = zext i32 %18 to i64
  %20 = or i64 %.04, %19
  %21 = shl i64 %20, 30
  br label %._crit_edge5

._crit_edge5:                                     ; preds = %14, %._crit_edge
  %22 = phi ptr [ %16, %._crit_edge ], [ %.pre, %14 ]
  %.1 = phi i64 [ %21, %._crit_edge ], [ 0, %14 ]
  %23 = load i32, ptr %22, align 4, !tbaa !14
  %24 = zext i32 %23 to i64
  %25 = or i64 %.1, %24
  br label %26

26:                                               ; preds = %1, %._crit_edge5
  %.2 = phi i64 [ %25, %._crit_edge5 ], [ 0, %1 ]
  ret i64 %.2
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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_unsignedE", !7, i64 0, !8, i64 8, !8, i64 12, !8, i64 16, !11, 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 16}
!13 = !{!6, !11, i64 24}
!14 = !{!8, !8, i64 0}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass