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

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

@_ZN5sc_dt15NB_DEFAULT_BASEE = external constant i32, align 4
@.str.13 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [83 x i8], align 1
@_ZN7sc_core24SC_ID_CONVERSION_FAILED_E = external constant [0 x i8], align 1

; 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
declare dso_local noundef i32 @_ZN5sc_dt8fsm_moveEcRiS0_S0_(i8 noundef signext, ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN5sc_dt17get_base_and_signEPKcRiS2_(ptr noundef %0, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca [8192 x i8], align 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 3, ptr %8, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 1, ptr %13, align 4, !tbaa !9
  %14 = load i32, ptr @_ZN5sc_dt15NB_DEFAULT_BASEE, align 4, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %14, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %16, ptr %11, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %45, %3
  %18 = load ptr, ptr %11, align 8, !tbaa !5
  %19 = load i8, ptr %18, align 1, !tbaa !11
  %20 = icmp ne i8 %19, 0
  br i1 %20, label %21, label %46

21:                                               ; preds = %17
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = sext i8 %23 to i32
  %25 = call i32 @isspace(i32 noundef %24) #7
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %30

27:                                               ; preds = %21
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i32 1
  store ptr %29, ptr %11, align 8, !tbaa !5
  br label %45

30:                                               ; preds = %21
  %31 = load ptr, ptr %11, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call noundef i32 @_ZN5sc_dt8fsm_moveEcRiS0_S0_(i8 noundef signext %32, ptr noundef nonnull align 4 dereferenceable(4) %33, ptr noundef nonnull align 4 dereferenceable(4) %34, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = add nsw i32 %36, %35
  store i32 %37, ptr %10, align 4, !tbaa !9
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = icmp eq i32 %38, 3
  br i1 %39, label %40, label %41

40:                                               ; preds = %30
  br label %46

41:                                               ; preds = %30
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i32 1
  store ptr %43, ptr %11, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %41
  br label %45

45:                                               ; preds = %44, %27
  br label %17, !llvm.loop !12

46:                                               ; preds = %40, %17
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = sext i32 %47 to i64
  %50 = getelementptr inbounds i8, ptr %48, i64 %49
  store ptr %50, ptr %4, align 8, !tbaa !5
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i8, ptr %51, align 1, !tbaa !11
  %53 = sext i8 %52 to i32
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %59

55:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8192, ptr %12) #6
  %56 = getelementptr inbounds [8192 x i8], ptr %12, i64 0, i64 0
  %57 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %56, ptr noundef @.str.14) #6
  %58 = getelementptr inbounds [8192 x i8], ptr %12, i64 0, i64 0
  call void @_ZN7sc_core17sc_report_handler6reportENS_11sc_severityEPKcS3_S3_i(i32 noundef 2, ptr noundef @_ZN7sc_core24SC_ID_CONVERSION_FAILED_E, ptr noundef %58, ptr noundef @.str.13, i32 noundef 223)
  call void @llvm.lifetime.end.p0(i64 8192, ptr %12) #6
  br label %59

59:                                               ; preds = %55, %46
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  ret ptr %60
}

; Function Attrs: inlinehint mustprogress nounwind willreturn memory(read) uwtable
declare i32 @isspace(i32 noundef) #3

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #4

declare void @_ZN7sc_core17sc_report_handler6reportENS_11sc_severityEPKcS3_S3_i(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #5

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 = { 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 #3 = { inlinehint mustprogress nounwind willreturn memory(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" }
attributes #4 = { nounwind "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 #5 = { "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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_dt15NB_DEFAULT_BASEE = external local_unnamed_addr constant i32, align 4
@.str.13 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [83 x i8], align 1
@_ZN7sc_core24SC_ID_CONVERSION_FAILED_E = external constant [0 x i8], align 1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5sc_dt8fsm_moveEcRiS0_S0_(i8 noundef signext, ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN5sc_dt17get_base_and_signEPKcRiS2_(ptr noundef readonly %0, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2) local_unnamed_addr #2 {
  %4 = alloca i32, align 4
  %5 = alloca [8192 x i8], align 16
  store i32 1, ptr %2, align 4, !tbaa !5
  %6 = load i32, ptr @_ZN5sc_dt15NB_DEFAULT_BASEE, align 4, !tbaa !5
  store i32 %6, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  store i32 0, ptr %4, align 4, !tbaa !5
  %7 = load i8, ptr %0, align 1, !tbaa !9
  %.not18 = icmp eq i8 %7, 0
  br i1 %.not18, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %3, %16
  %8 = phi i8 [ %17, %16 ], [ %7, %3 ]
  %.020 = phi ptr [ %.1, %16 ], [ %0, %3 ]
  %.01419 = phi i32 [ %.115, %16 ], [ 0, %3 ]
  %9 = sext i8 %8 to i32
  %10 = call i32 @isspace(i32 noundef %9) #7
  %.not17 = icmp eq i32 %10, 0
  br i1 %.not17, label %11, label %16

11:                                               ; preds = %.lr.ph
  %12 = call noundef i32 @_ZN5sc_dt8fsm_moveEcRiS0_S0_(i8 noundef signext %8, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %13 = add nsw i32 %12, %.01419
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 3
  br i1 %15, label %._crit_edge, label %16

16:                                               ; preds = %11, %.lr.ph
  %.115 = phi i32 [ %.01419, %.lr.ph ], [ %13, %11 ]
  %.1 = getelementptr inbounds i8, ptr %.020, i64 1
  %17 = load i8, ptr %.1, align 1, !tbaa !9
  %.not = icmp eq i8 %17, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %16, %11
  %.2.ph = phi i32 [ %.115, %16 ], [ %13, %11 ]
  %.phi.trans.insert = sext i32 %.2.ph to i64
  %.phi.trans.insert23 = getelementptr inbounds i8, ptr %0, i64 %.phi.trans.insert
  %.pre = load i8, ptr %.phi.trans.insert23, align 1, !tbaa !9
  %18 = sext i32 %.2.ph to i64
  %19 = icmp eq i8 %.pre, 0
  br i1 %19, label %._crit_edge.thread, label %21

._crit_edge.thread:                               ; preds = %3, %._crit_edge
  %.226 = phi i64 [ %18, %._crit_edge ], [ 0, %3 ]
  call void @llvm.lifetime.start.p0(i64 8192, ptr nonnull %5) #6
  %20 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %5, ptr noundef nonnull dereferenceable(1) @.str.14) #6
  call void @_ZN7sc_core17sc_report_handler6reportENS_11sc_severityEPKcS3_S3_i(i32 noundef 2, ptr noundef nonnull @_ZN7sc_core24SC_ID_CONVERSION_FAILED_E, ptr noundef nonnull %5, ptr noundef nonnull @.str.13, i32 noundef 223)
  call void @llvm.lifetime.end.p0(i64 8192, ptr nonnull %5) #6
  br label %21

21:                                               ; preds = %._crit_edge.thread, %._crit_edge
  %.225 = phi i64 [ %.226, %._crit_edge.thread ], [ %18, %._crit_edge ]
  %22 = getelementptr inbounds i8, ptr %0, i64 %.225
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  ret ptr %22
}

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @isspace(i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #4

declare void @_ZN7sc_core17sc_report_handler6reportENS_11sc_severityEPKcS3_S3_i(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #5

attributes #0 = { mustprogress 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 = { 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 #3 = { inlinehint mustprogress nofree nounwind willreturn memory(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" }
attributes #4 = { nofree nounwind "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 #5 = { "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass