; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/kernel (sc_name_gen)

; 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_core::sc_name_gen" = type { %"class.sc_core::sc_strhash", [8192 x i8] }
%"class.sc_core::sc_strhash" = type { %"class.sc_core::sc_phash_base" }
%"class.sc_core::sc_phash_base" = type { ptr, i32, i32, i32, i32, double, ptr, ptr, ptr }

@_ZN7sc_core22SC_ID_GEN_UNIQUE_NAME_E = external constant [0 x i8], align 1
@.str = external hidden unnamed_addr constant [87 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 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 uwtable
define dso_local noundef ptr @_ZN7sc_core11sc_name_gen15gen_unique_nameEPKcb(ptr noundef nonnull align 8 dereferenceable(8248) %0, ptr noundef %1, i1 noundef zeroext %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = zext i1 %2 to i8
  store i8 %8, ptr %6, align 1, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  call void @_ZN7sc_core17sc_report_handler6reportENS_11sc_severityEPKcS3_S3_i(i32 noundef 2, ptr noundef @_ZN7sc_core22SC_ID_GEN_UNIQUE_NAME_E, ptr noundef null, ptr noundef @.str, i32 noundef 66)
  br label %13

13:                                               ; preds = %12, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %14 = getelementptr inbounds %"class.sc_core::sc_name_gen", ptr %9, i32 0, i32 0
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call noundef ptr @_ZNK7sc_core10sc_strhashIPiEixEPKc(ptr noundef nonnull align 8 dereferenceable(56) %14, ptr noundef %15)
  store ptr %16, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %40

19:                                               ; preds = %13
  %20 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 4) #6
  store i32 0, ptr %20, align 4, !tbaa !11
  store ptr %20, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.sc_core::sc_name_gen", ptr %9, i32 0, i32 0
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = call noundef i32 @_ZN7sc_core10sc_strhashIPiE6insertEPcS1_(ptr noundef nonnull align 8 dereferenceable(56) %21, ptr noundef %22, ptr noundef %23)
  %25 = load i8, ptr %6, align 1, !tbaa !9, !range !13, !noundef !14
  %26 = trunc i8 %25 to i1
  br i1 %26, label %27, label %32

27:                                               ; preds = %19
  %28 = getelementptr inbounds %"class.sc_core::sc_name_gen", ptr %9, i32 0, i32 1
  %29 = getelementptr inbounds [8192 x i8], ptr %28, i64 0, i64 0
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %29, ptr noundef @.str.1, ptr noundef %30) #5
  br label %39

32:                                               ; preds = %19
  %33 = getelementptr inbounds %"class.sc_core::sc_name_gen", ptr %9, i32 0, i32 1
  %34 = getelementptr inbounds [8192 x i8], ptr %33, i64 0, i64 0
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %34, ptr noundef @.str.2, ptr noundef %35, i32 noundef %37) #5
  br label %39

39:                                               ; preds = %32, %27
  br label %48

40:                                               ; preds = %13
  %41 = getelementptr inbounds %"class.sc_core::sc_name_gen", ptr %9, i32 0, i32 1
  %42 = getelementptr inbounds [8192 x i8], ptr %41, i64 0, i64 0
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load i32, ptr %44, align 4, !tbaa !11
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %44, align 4, !tbaa !11
  %47 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %42, ptr noundef @.str.2, ptr noundef %43, i32 noundef %46) #5
  br label %48

48:                                               ; preds = %40, %39
  %49 = getelementptr inbounds %"class.sc_core::sc_name_gen", ptr %9, i32 0, i32 1
  %50 = getelementptr inbounds [8192 x i8], ptr %49, i64 0, i64 0
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret ptr %50
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK7sc_core10sc_strhashIPiEixEPKc(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) #1 align 2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7sc_core10sc_strhashIPiE6insertEPcS1_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef, ptr noundef) #1 align 2

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

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 = { "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 = { nobuiltin allocsize(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 = { nounwind }
attributes #6 = { builtin allocsize(0) }

!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 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


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

@_ZN7sc_core22SC_ID_GEN_UNIQUE_NAME_E = external constant [0 x i8], align 1
@.str = external hidden unnamed_addr constant [87 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull ptr @_ZN7sc_core11sc_name_gen15gen_unique_nameEPKcb(ptr noundef nonnull align 8 dereferenceable(8248) %0, ptr noundef %1, i1 noundef zeroext %2) local_unnamed_addr #0 align 2 {
  %4 = icmp eq ptr %1, null
  br i1 %4, label %5, label %6

5:                                                ; preds = %3
  tail call void @_ZN7sc_core17sc_report_handler6reportENS_11sc_severityEPKcS3_S3_i(i32 noundef 2, ptr noundef nonnull @_ZN7sc_core22SC_ID_GEN_UNIQUE_NAME_E, ptr noundef null, ptr noundef nonnull @.str, i32 noundef 66)
  br label %6

6:                                                ; preds = %5, %3
  %7 = tail call noundef ptr @_ZNK7sc_core10sc_strhashIPiEixEPKc(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1)
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %18

9:                                                ; preds = %6
  %10 = tail call noalias noundef nonnull dereferenceable(4) ptr @_Znwm(i64 noundef 4) #4
  store i32 0, ptr %10, align 4, !tbaa !5
  %11 = tail call noundef i32 @_ZN7sc_core10sc_strhashIPiE6insertEPcS1_(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1, ptr noundef nonnull %10)
  %12 = getelementptr inbounds i8, ptr %0, i64 56
  br i1 %2, label %13, label %15

13:                                               ; preds = %9
  %14 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef %1) #5
  br label %23

15:                                               ; preds = %9
  %16 = load i32, ptr %10, align 4, !tbaa !5
  %17 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %1, i32 noundef %16) #5
  br label %23

18:                                               ; preds = %6
  %19 = getelementptr inbounds i8, ptr %0, i64 56
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %7, align 4, !tbaa !5
  %22 = tail call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %19, ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef %1, i32 noundef %21) #5
  br label %23

23:                                               ; preds = %13, %15, %18
  %24 = getelementptr inbounds i8, ptr %0, i64 56
  ret ptr %24
}

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

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #2

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

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

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 = { "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 = { nobuiltin allocsize(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 = { 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 #4 = { builtin allocsize(0) }
attributes #5 = { 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"}


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