; LLVM IR from ros2/rcutils :: src (logging)

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

%struct.rcutils_allocator_s = type { ptr, ptr, ptr, ptr, ptr }
%struct.rcutils_hash_map_s = type { ptr }
%struct.rcutils_error_string_s = type { [1024 x i8] }

@g_rcutils_logging_initialized = external dso_local global i8, align 1
@.str.7 = external hidden unnamed_addr constant [60 x i8], align 1
@g_rcutils_logging_allocator = external hidden global %struct.rcutils_allocator_s, align 8
@.str.10 = external hidden unnamed_addr constant [54 x i8], align 1
@stderr = external global ptr, align 8
@g_rcutils_logging_severities_map = external hidden global %struct.rcutils_hash_map_s, align 8
@g_rcutils_logging_severities_map_valid = external hidden global i8, align 1
@.str.27 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [49 x i8], align 1
@g_num_log_msg_handlers = external hidden global i64, align 8

declare void @rcutils_set_error_state(ptr noundef, ptr noundef, i64 noundef) #0

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

declare i32 @rcutils_snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #0

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #0

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

declare void @rcutils_get_error_string(ptr dead_on_unwind writable sret(%struct.rcutils_error_string_s) align 1) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @rcutils_logging_shutdown() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca [1024 x i8], align 16
  %7 = alloca i32, align 4
  %8 = alloca %struct.rcutils_error_string_s, align 1
  %9 = alloca [1024 x i8], align 16
  %10 = alloca i32, align 4
  %11 = alloca %struct.rcutils_error_string_s, align 1
  %12 = load i8, ptr @g_rcutils_logging_initialized, align 1, !tbaa !5, !range !9, !noundef !10
  %13 = trunc i8 %12 to i1
  br i1 %13, label %15, label %14

14:                                               ; preds = %0
  store i32 0, ptr %1, align 4
  br label %83

15:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !11
  %16 = load i8, ptr @g_rcutils_logging_severities_map_valid, align 1, !tbaa !5, !range !9, !noundef !10
  %17 = trunc i8 %16 to i1
  br i1 %17, label %18, label %81

18:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store ptr null, ptr %3, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %19 = call i32 @rcutils_hash_map_get_next_key_and_data(ptr noundef @g_rcutils_logging_severities_map, ptr noundef null, ptr noundef %3, ptr noundef %4)
  store i32 %19, ptr %5, align 4, !tbaa !11
  br label %20

20:                                               ; preds = %49, %18
  %21 = load i32, ptr %5, align 4, !tbaa !11
  %22 = icmp eq i32 0, %21
  br i1 %22, label %23, label %54

23:                                               ; preds = %20
  %24 = call i32 @rcutils_hash_map_unset(ptr noundef @g_rcutils_logging_severities_map, ptr noundef %3)
  store i32 %24, ptr %5, align 4, !tbaa !11
  %25 = load i32, ptr %5, align 4, !tbaa !11
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %49

27:                                               ; preds = %23
  br label %28

28:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 1024, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %29 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  call void @rcutils_get_error_string(ptr dead_on_unwind writable sret(%struct.rcutils_error_string_s) align 1 %8)
  %30 = getelementptr inbounds %struct.rcutils_error_string_s, ptr %8, i32 0, i32 0
  %31 = getelementptr inbounds [1024 x i8], ptr %30, i64 0, i64 0
  %32 = call i32 (ptr, i64, ptr, ...) @rcutils_snprintf(ptr noundef %29, i64 noundef 1024, ptr noundef @.str.27, ptr noundef %31)
  store i32 %32, ptr %7, align 4, !tbaa !11
  %33 = load i32, ptr %7, align 4, !tbaa !11
  %34 = icmp slt i32 %33, 0
  br i1 %34, label %35, label %41

35:                                               ; preds = %28
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr @stderr, align 8, !tbaa !13
  %38 = call i64 @fwrite(ptr noundef @.str.10, i64 noundef 1, i64 noundef 53, ptr noundef %37)
  br label %39

39:                                               ; preds = %36
  br label %40

40:                                               ; preds = %39
  br label %46

41:                                               ; preds = %28
  br label %42

42:                                               ; preds = %41
  %43 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  call void @rcutils_set_error_state(ptr noundef %43, ptr noundef @.str.7, i64 noundef 786)
  br label %44

44:                                               ; preds = %42
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 1024, ptr %6) #3
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  br label %54

49:                                               ; preds = %23
  %50 = load ptr, ptr getelementptr inbounds (%struct.rcutils_allocator_s, ptr @g_rcutils_logging_allocator, i32 0, i32 1), align 8, !tbaa !15
  %51 = load ptr, ptr %3, align 8, !tbaa !13
  %52 = load ptr, ptr getelementptr inbounds (%struct.rcutils_allocator_s, ptr @g_rcutils_logging_allocator, i32 0, i32 4), align 8, !tbaa !17
  call void %50(ptr noundef %51, ptr noundef %52)
  %53 = call i32 @rcutils_hash_map_get_next_key_and_data(ptr noundef @g_rcutils_logging_severities_map, ptr noundef null, ptr noundef %3, ptr noundef %4)
  store i32 %53, ptr %5, align 4, !tbaa !11
  br label %20, !llvm.loop !18

54:                                               ; preds = %48, %20
  %55 = call i32 @rcutils_hash_map_fini(ptr noundef @g_rcutils_logging_severities_map)
  store i32 %55, ptr %5, align 4, !tbaa !11
  %56 = load i32, ptr %5, align 4, !tbaa !11
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %80

58:                                               ; preds = %54
  br label %59

59:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 1024, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %60 = getelementptr inbounds [1024 x i8], ptr %9, i64 0, i64 0
  call void @rcutils_get_error_string(ptr dead_on_unwind writable sret(%struct.rcutils_error_string_s) align 1 %11)
  %61 = getelementptr inbounds %struct.rcutils_error_string_s, ptr %11, i32 0, i32 0
  %62 = getelementptr inbounds [1024 x i8], ptr %61, i64 0, i64 0
  %63 = call i32 (ptr, i64, ptr, ...) @rcutils_snprintf(ptr noundef %60, i64 noundef 1024, ptr noundef @.str.28, ptr noundef %62)
  store i32 %63, ptr %10, align 4, !tbaa !11
  %64 = load i32, ptr %10, align 4, !tbaa !11
  %65 = icmp slt i32 %64, 0
  br i1 %65, label %66, label %72

66:                                               ; preds = %59
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr @stderr, align 8, !tbaa !13
  %69 = call i64 @fwrite(ptr noundef @.str.10, i64 noundef 1, i64 noundef 53, ptr noundef %68)
  br label %70

70:                                               ; preds = %67
  br label %71

71:                                               ; preds = %70
  br label %77

72:                                               ; preds = %59
  br label %73

73:                                               ; preds = %72
  %74 = getelementptr inbounds [1024 x i8], ptr %9, i64 0, i64 0
  call void @rcutils_set_error_state(ptr noundef %74, ptr noundef @.str.7, i64 noundef 799)
  br label %75

75:                                               ; preds = %73
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76, %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1024, ptr %9) #3
  br label %78

78:                                               ; preds = %77
  br label %79

79:                                               ; preds = %78
  store i32 40, ptr %2, align 4, !tbaa !11
  br label %80

80:                                               ; preds = %79, %54
  store i8 0, ptr @g_rcutils_logging_severities_map_valid, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %81

81:                                               ; preds = %80, %15
  store i64 0, ptr @g_num_log_msg_handlers, align 8, !tbaa !20
  store i8 0, ptr @g_rcutils_logging_initialized, align 1, !tbaa !5
  %82 = load i32, ptr %2, align 4, !tbaa !11
  store i32 %82, ptr %1, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %83

83:                                               ; preds = %81, %14
  %84 = load i32, ptr %1, align 4
  ret i32 %84
}

declare i32 @rcutils_hash_map_get_next_key_and_data(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

declare i32 @rcutils_hash_map_unset(ptr noundef, ptr noundef) #0

declare i32 @rcutils_hash_map_fini(ptr noundef) #0

attributes #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 = { 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 #3 = { 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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!16, !14, i64 8}
!16 = !{!"rcutils_allocator_s", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!17 = !{!16, !14, i64 32}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !21, i64 0}
!21 = !{!"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"

%struct.rcutils_allocator_s = type { ptr, ptr, ptr, ptr, ptr }
%struct.rcutils_hash_map_s = type { ptr }
%struct.rcutils_error_string_s = type { [1024 x i8] }

@g_rcutils_logging_initialized = external dso_local local_unnamed_addr global i8, align 1
@.str.7 = external hidden unnamed_addr constant [60 x i8], align 1
@g_rcutils_logging_allocator = external hidden local_unnamed_addr global %struct.rcutils_allocator_s, align 8
@.str.10 = external hidden unnamed_addr constant [54 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@g_rcutils_logging_severities_map = external hidden global %struct.rcutils_hash_map_s, align 8
@g_rcutils_logging_severities_map_valid = external hidden local_unnamed_addr global i8, align 1
@.str.27 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [49 x i8], align 1
@g_num_log_msg_handlers = external hidden local_unnamed_addr global i64, align 8

declare void @rcutils_set_error_state(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

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

declare i32 @rcutils_snprintf(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #2

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

declare void @rcutils_get_error_string(ptr dead_on_unwind writable sret(%struct.rcutils_error_string_s) align 1) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 41) i32 @rcutils_logging_shutdown() local_unnamed_addr #3 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca [1024 x i8], align 16
  %4 = alloca %struct.rcutils_error_string_s, align 1
  %5 = alloca [1024 x i8], align 16
  %6 = alloca %struct.rcutils_error_string_s, align 1
  %7 = load i8, ptr @g_rcutils_logging_initialized, align 1, !tbaa !5, !range !9, !noundef !10
  %8 = trunc nuw i8 %7 to i1
  br i1 %8, label %9, label %41

9:                                                ; preds = %0
  %10 = load i8, ptr @g_rcutils_logging_severities_map_valid, align 1, !tbaa !5, !range !9, !noundef !10
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %12, label %40

12:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  store ptr null, ptr %1, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %13 = call i32 @rcutils_hash_map_get_next_key_and_data(ptr noundef nonnull @g_rcutils_logging_severities_map, ptr noundef null, ptr noundef nonnull %1, ptr noundef nonnull %2) #4
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %12, %24
  %15 = call i32 @rcutils_hash_map_unset(ptr noundef nonnull @g_rcutils_logging_severities_map, ptr noundef nonnull %1) #4
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %24, label %16

16:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %3) #4
  call void @rcutils_get_error_string(ptr dead_on_unwind nonnull writable sret(%struct.rcutils_error_string_s) align 1 %4) #4
  %17 = call i32 (ptr, i64, ptr, ...) @rcutils_snprintf(ptr noundef nonnull %3, i64 noundef 1024, ptr noundef nonnull @.str.27, ptr noundef nonnull %4) #4
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  %20 = load ptr, ptr @stderr, align 8, !tbaa !11
  %21 = call i64 @fwrite(ptr noundef nonnull @.str.10, i64 noundef 1, i64 noundef 53, ptr noundef %20) #5
  br label %23

22:                                               ; preds = %16
  call void @rcutils_set_error_state(ptr noundef nonnull %3, ptr noundef nonnull @.str.7, i64 noundef 786) #4
  br label %23

23:                                               ; preds = %22, %19
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %3) #4
  br label %.loopexit

24:                                               ; preds = %.lr.ph
  %25 = load ptr, ptr getelementptr inbounds (i8, ptr @g_rcutils_logging_allocator, i64 8), align 8, !tbaa !13
  %26 = load ptr, ptr %1, align 8, !tbaa !11
  %27 = load ptr, ptr getelementptr inbounds (i8, ptr @g_rcutils_logging_allocator, i64 32), align 8, !tbaa !15
  call void %25(ptr noundef %26, ptr noundef %27) #4
  %28 = call i32 @rcutils_hash_map_get_next_key_and_data(ptr noundef nonnull @g_rcutils_logging_severities_map, ptr noundef null, ptr noundef nonnull %1, ptr noundef nonnull %2) #4
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %.lr.ph, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %24, %12, %23
  %30 = call i32 @rcutils_hash_map_fini(ptr noundef nonnull @g_rcutils_logging_severities_map) #4
  %.not9 = icmp eq i32 %30, 0
  br i1 %.not9, label %39, label %31

31:                                               ; preds = %.loopexit
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %5) #4
  call void @rcutils_get_error_string(ptr dead_on_unwind nonnull writable sret(%struct.rcutils_error_string_s) align 1 %6) #4
  %32 = call i32 (ptr, i64, ptr, ...) @rcutils_snprintf(ptr noundef nonnull %5, i64 noundef 1024, ptr noundef nonnull @.str.28, ptr noundef nonnull %6) #4
  %33 = icmp slt i32 %32, 0
  br i1 %33, label %34, label %37

34:                                               ; preds = %31
  %35 = load ptr, ptr @stderr, align 8, !tbaa !11
  %36 = call i64 @fwrite(ptr noundef nonnull @.str.10, i64 noundef 1, i64 noundef 53, ptr noundef %35) #5
  br label %38

37:                                               ; preds = %31
  call void @rcutils_set_error_state(ptr noundef nonnull %5, ptr noundef nonnull @.str.7, i64 noundef 799) #4
  br label %38

38:                                               ; preds = %37, %34
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %5) #4
  br label %39

39:                                               ; preds = %38, %.loopexit
  %.07 = phi i32 [ 40, %38 ], [ 0, %.loopexit ]
  store i8 0, ptr @g_rcutils_logging_severities_map_valid, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  br label %40

40:                                               ; preds = %39, %9
  %.1 = phi i32 [ %.07, %39 ], [ 0, %9 ]
  store i64 0, ptr @g_num_log_msg_handlers, align 8, !tbaa !18
  store i8 0, ptr @g_rcutils_logging_initialized, align 1, !tbaa !5
  br label %41

41:                                               ; preds = %0, %40
  %.0 = phi i32 [ %.1, %40 ], [ 0, %0 ]
  ret i32 %.0
}

declare i32 @rcutils_hash_map_get_next_key_and_data(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @rcutils_hash_map_unset(ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @rcutils_hash_map_fini(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 #3 = { 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 }
attributes #5 = { cold }

!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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"rcutils_allocator_s", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!15 = !{!14, !12, i64 32}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !19, i64 0}
!19 = !{!"long", !7, i64 0}


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