; 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_error_string_s = type { [1024 x i8] }

@g_rcutils_logging_initialized = external dso_local global i8, align 1
@g_rcutils_logging_default_logger_level = external hidden global i32, align 4
@.str.10 = external hidden unnamed_addr constant [54 x i8], align 1
@stderr = external global ptr, align 8
@.str.34 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.52 = external hidden unnamed_addr constant [104 x i8], align 1
@.str.53 = external hidden unnamed_addr constant [63 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @rcutils_logging_initialize_with_allocator(ptr noundef byval(%struct.rcutils_allocator_s) align 8) #0

declare void @rcutils_get_default_allocator(ptr dead_on_unwind writable sret(%struct.rcutils_allocator_s) align 8) #1

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

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

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

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

declare void @rcutils_reset_error() #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local i32 @rcutils_logging_get_logger_effective_level(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @rcutils_logging_logger_is_enabled_for(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %struct.rcutils_allocator_s, align 8
  %7 = alloca %struct.rcutils_error_string_s, align 1
  %8 = alloca %struct.rcutils_error_string_s, align 1
  %9 = alloca i32, align 4
  %10 = alloca [1024 x i8], align 16
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %2
  %14 = load i8, ptr @g_rcutils_logging_initialized, align 1, !tbaa !11, !range !13, !noundef !14
  %15 = trunc i8 %14 to i1
  %16 = xor i1 %15, true
  %17 = zext i1 %16 to i32
  %18 = sext i32 %17 to i64
  %19 = call i64 @llvm.expect.i64(i64 %18, i64 0)
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %21, label %43

21:                                               ; preds = %13
  call void @rcutils_get_default_allocator(ptr dead_on_unwind writable sret(%struct.rcutils_allocator_s) align 8 %6)
  %22 = call i32 @rcutils_logging_initialize_with_allocator(ptr noundef byval(%struct.rcutils_allocator_s) align 8 %6)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %42

24:                                               ; preds = %21
  br label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr @stderr, align 8, !tbaa !5
  %27 = call i64 @fwrite(ptr noundef @.str.52, i64 noundef 1, i64 noundef 103, ptr noundef %26)
  br label %28

28:                                               ; preds = %25
  br label %29

29:                                               ; preds = %28
  call void @rcutils_get_error_string(ptr dead_on_unwind writable sret(%struct.rcutils_error_string_s) align 1 %7)
  %30 = getelementptr inbounds %struct.rcutils_error_string_s, ptr %7, i32 0, i32 0
  %31 = getelementptr inbounds [1024 x i8], ptr %30, i64 0, i64 0
  call void @rcutils_get_error_string(ptr dead_on_unwind writable sret(%struct.rcutils_error_string_s) align 1 %8)
  %32 = getelementptr inbounds %struct.rcutils_error_string_s, ptr %8, i32 0, i32 0
  %33 = getelementptr inbounds [1024 x i8], ptr %32, i64 0, i64 0
  %34 = call i64 @strlen(ptr noundef %33) #5
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = call i64 @fwrite(ptr noundef %31, i64 noundef 1, i64 noundef %34, ptr noundef %35)
  br label %37

37:                                               ; preds = %29
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr @stderr, align 8, !tbaa !5
  %40 = call i64 @fwrite(ptr noundef @.str.34, i64 noundef 1, i64 noundef 1, ptr noundef %39)
  br label %41

41:                                               ; preds = %38
  call void @rcutils_reset_error()
  br label %42

42:                                               ; preds = %41, %21
  br label %43

43:                                               ; preds = %42, %13
  br label %44

44:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %45 = load i32, ptr @g_rcutils_logging_default_logger_level, align 4, !tbaa !9
  store i32 %45, ptr %9, align 4, !tbaa !9
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %80

48:                                               ; preds = %44
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = call i32 @rcutils_logging_get_logger_effective_level(ptr noundef %49)
  store i32 %50, ptr %9, align 4, !tbaa !9
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = icmp eq i32 -1, %51
  br i1 %52, label %53, label %79

53:                                               ; preds = %48
  br label %54

54:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 1024, ptr %10) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %55 = getelementptr inbounds [1024 x i8], ptr %10, i64 0, i64 0
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = call i32 (ptr, i64, ptr, ...) @rcutils_snprintf(ptr noundef %55, i64 noundef 1024, ptr noundef @.str.53, ptr noundef %56, i32 noundef %57)
  store i32 %58, ptr %11, align 4, !tbaa !9
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = icmp slt i32 %59, 0
  br i1 %60, label %61, label %67

61:                                               ; preds = %54
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr @stderr, align 8, !tbaa !5
  %64 = call i64 @fwrite(ptr noundef @.str.10, i64 noundef 1, i64 noundef 53, ptr noundef %63)
  br label %65

65:                                               ; preds = %62
  br label %66

66:                                               ; preds = %65
  br label %76

67:                                               ; preds = %54
  br label %68

68:                                               ; preds = %67
  %69 = getelementptr inbounds [1024 x i8], ptr %10, i64 0, i64 0
  %70 = getelementptr inbounds [1024 x i8], ptr %10, i64 0, i64 0
  %71 = call i64 @strlen(ptr noundef %70) #5
  %72 = load ptr, ptr @stderr, align 8, !tbaa !5
  %73 = call i64 @fwrite(ptr noundef %69, i64 noundef 1, i64 noundef %71, ptr noundef %72)
  br label %74

74:                                               ; preds = %68
  br label %75

75:                                               ; preds = %74
  br label %76

76:                                               ; preds = %75, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 1024, ptr %10) #6
  br label %77

77:                                               ; preds = %76
  br label %78

78:                                               ; preds = %77
  store i1 false, ptr %3, align 1
  store i32 1, ptr %12, align 4
  br label %84

79:                                               ; preds = %48
  br label %80

80:                                               ; preds = %79, %44
  %81 = load i32, ptr %5, align 4, !tbaa !9
  %82 = load i32, ptr %9, align 4, !tbaa !9
  %83 = icmp sge i32 %81, %82
  store i1 %83, ptr %3, align 1
  store i32 1, ptr %12, align 4
  br label %84

84:                                               ; preds = %80, %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  %85 = load i1, ptr %3, align 1
  ret i1 %85
}

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #4 = { nounwind willreturn memory(read) "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 willreturn memory(read) }
attributes #6 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !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"

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

@g_rcutils_logging_initialized = external dso_local local_unnamed_addr global i8, align 1
@g_rcutils_logging_default_logger_level = external hidden local_unnamed_addr global i32, align 4
@.str.10 = external hidden unnamed_addr constant [54 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.34 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.52 = external hidden unnamed_addr constant [104 x i8], align 1
@.str.53 = external hidden unnamed_addr constant [63 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @rcutils_logging_initialize_with_allocator(ptr noundef byval(%struct.rcutils_allocator_s) align 8) local_unnamed_addr #0

declare void @rcutils_get_default_allocator(ptr dead_on_unwind writable sret(%struct.rcutils_allocator_s) align 8) local_unnamed_addr #1

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

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

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

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

declare void @rcutils_reset_error() local_unnamed_addr #1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare dso_local i32 @rcutils_logging_get_logger_effective_level(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @rcutils_logging_logger_is_enabled_for(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.rcutils_allocator_s, align 8
  %4 = alloca %struct.rcutils_error_string_s, align 1
  %5 = alloca %struct.rcutils_error_string_s, align 1
  %6 = alloca [1024 x i8], align 16
  %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 %18, label %9, !prof !11

9:                                                ; preds = %2
  call void @rcutils_get_default_allocator(ptr dead_on_unwind nonnull writable sret(%struct.rcutils_allocator_s) align 8 %3) #6
  %10 = call i32 @rcutils_logging_initialize_with_allocator(ptr noundef nonnull byval(%struct.rcutils_allocator_s) align 8 %3)
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %18, label %11

11:                                               ; preds = %9
  %12 = load ptr, ptr @stderr, align 8, !tbaa !12
  %13 = call i64 @fwrite(ptr noundef nonnull @.str.52, i64 noundef 1, i64 noundef 103, ptr noundef %12) #7
  call void @rcutils_get_error_string(ptr dead_on_unwind nonnull writable sret(%struct.rcutils_error_string_s) align 1 %4) #6
  call void @rcutils_get_error_string(ptr dead_on_unwind nonnull writable sret(%struct.rcutils_error_string_s) align 1 %5) #6
  %14 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %5) #8
  %15 = load ptr, ptr @stderr, align 8, !tbaa !12
  %16 = call i64 @fwrite(ptr noundef nonnull %4, i64 noundef 1, i64 noundef %14, ptr noundef %15) #7
  %17 = load ptr, ptr @stderr, align 8, !tbaa !12
  %char = load i8, ptr @.str.34, align 1
  %chari = sext i8 %char to i32
  %fputc = call i32 @fputc(i32 %chari, ptr %17)
  call void @rcutils_reset_error() #6
  br label %18

18:                                               ; preds = %2, %11, %9
  %19 = load i32, ptr @g_rcutils_logging_default_logger_level, align 4, !tbaa !14
  %.not11 = icmp eq ptr %0, null
  br i1 %.not11, label %34, label %20

20:                                               ; preds = %18
  %21 = call i32 @rcutils_logging_get_logger_effective_level(ptr noundef nonnull %0)
  %22 = icmp eq i32 %21, -1
  br i1 %22, label %23, label %34

23:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %6) #6
  %24 = call i32 (ptr, i64, ptr, ...) @rcutils_snprintf(ptr noundef nonnull %6, i64 noundef 1024, ptr noundef nonnull @.str.53, ptr noundef nonnull %0, i32 noundef %1) #6
  %25 = icmp slt i32 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %23
  %27 = load ptr, ptr @stderr, align 8, !tbaa !12
  %28 = call i64 @fwrite(ptr noundef nonnull @.str.10, i64 noundef 1, i64 noundef 53, ptr noundef %27) #7
  br label %33

29:                                               ; preds = %23
  %30 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %6) #8
  %31 = load ptr, ptr @stderr, align 8, !tbaa !12
  %32 = call i64 @fwrite(ptr noundef nonnull %6, i64 noundef 1, i64 noundef %30, ptr noundef %31) #7
  br label %33

33:                                               ; preds = %29, %26
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %6) #6
  br label %36

34:                                               ; preds = %20, %18
  %.08 = phi i32 [ %21, %20 ], [ %19, %18 ]
  %35 = icmp sle i32 %.08, %1
  br label %36

36:                                               ; preds = %34, %33
  %.0 = phi i1 [ false, %33 ], [ %35, %34 ]
  ret i1 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @fputc(i32 noundef, ptr nocapture noundef) local_unnamed_addr #5

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { nofree nounwind }
attributes #6 = { nounwind }
attributes #7 = { cold }
attributes #8 = { 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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}


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