; 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
@stderr = external global ptr, align 8
@.str.34 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [103 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

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

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) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rcutils_logging_get_logger_level(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.rcutils_allocator_s, align 8
  %5 = alloca %struct.rcutils_error_string_s, align 1
  %6 = alloca %struct.rcutils_error_string_s, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %1
  %8 = load i8, ptr @g_rcutils_logging_initialized, align 1, !tbaa !9, !range !11, !noundef !12
  %9 = trunc i8 %8 to i1
  %10 = xor i1 %9, true
  %11 = zext i1 %10 to i32
  %12 = sext i32 %11 to i64
  %13 = call i64 @llvm.expect.i64(i64 %12, i64 0)
  %14 = icmp ne i64 %13, 0
  br i1 %14, label %15, label %37

15:                                               ; preds = %7
  call void @rcutils_get_default_allocator(ptr dead_on_unwind writable sret(%struct.rcutils_allocator_s) align 8 %4)
  %16 = call i32 @rcutils_logging_initialize_with_allocator(ptr noundef byval(%struct.rcutils_allocator_s) align 8 %4)
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %36

18:                                               ; preds = %15
  br label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr @stderr, align 8, !tbaa !5
  %21 = call i64 @fwrite(ptr noundef @.str.38, i64 noundef 1, i64 noundef 102, ptr noundef %20)
  br label %22

22:                                               ; preds = %19
  br label %23

23:                                               ; preds = %22
  call void @rcutils_get_error_string(ptr dead_on_unwind writable sret(%struct.rcutils_error_string_s) align 1 %5)
  %24 = getelementptr inbounds %struct.rcutils_error_string_s, ptr %5, i32 0, i32 0
  %25 = getelementptr inbounds [1024 x i8], ptr %24, i64 0, i64 0
  call void @rcutils_get_error_string(ptr dead_on_unwind writable sret(%struct.rcutils_error_string_s) align 1 %6)
  %26 = getelementptr inbounds %struct.rcutils_error_string_s, ptr %6, i32 0, i32 0
  %27 = getelementptr inbounds [1024 x i8], ptr %26, i64 0, i64 0
  %28 = call i64 @strlen(ptr noundef %27) #4
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = call i64 @fwrite(ptr noundef %25, i64 noundef 1, i64 noundef %28, ptr noundef %29)
  br label %31

31:                                               ; preds = %23
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = call i64 @fwrite(ptr noundef @.str.34, i64 noundef 1, i64 noundef 1, ptr noundef %33)
  br label %35

35:                                               ; preds = %32
  call void @rcutils_reset_error()
  br label %36

36:                                               ; preds = %35, %15
  br label %37

37:                                               ; preds = %36, %7
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = icmp eq ptr null, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %38
  store i32 -1, ptr %2, align 4
  br label %47

42:                                               ; preds = %38
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = call i64 @strlen(ptr noundef %44) #4
  %46 = call i32 @rcutils_logging_get_logger_leveln(ptr noundef %43, i64 noundef %45)
  store i32 %46, ptr %2, align 4
  br label %47

47:                                               ; preds = %42, %41
  %48 = load i32, ptr %2, align 4
  ret i32 %48
}

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

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(none) }
attributes #3 = { 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 #4 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}


; 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
@stderr = external local_unnamed_addr global ptr, align 8
@.str.34 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [103 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: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #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 #3

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

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

9:                                                ; preds = %7
  %10 = load ptr, ptr @stderr, align 8, !tbaa !12
  %11 = call i64 @fwrite(ptr noundef nonnull @.str.38, i64 noundef 1, i64 noundef 102, ptr noundef %10) #6
  call void @rcutils_get_error_string(ptr dead_on_unwind nonnull writable sret(%struct.rcutils_error_string_s) align 1 %3) #5
  call void @rcutils_get_error_string(ptr dead_on_unwind nonnull writable sret(%struct.rcutils_error_string_s) align 1 %4) #5
  %12 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %4) #7
  %13 = load ptr, ptr @stderr, align 8, !tbaa !12
  %14 = call i64 @fwrite(ptr noundef nonnull %3, i64 noundef 1, i64 noundef %12, ptr noundef %13) #6
  %15 = 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 %15)
  call void @rcutils_reset_error() #5
  br label %16

16:                                               ; preds = %1, %9, %7
  %17 = icmp eq ptr %0, null
  br i1 %17, label %21, label %18

18:                                               ; preds = %16
  %19 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #7
  %20 = call i32 @rcutils_logging_get_logger_leveln(ptr noundef nonnull %0, i64 noundef %19)
  br label %21

21:                                               ; preds = %16, %18
  %.0 = phi i32 [ %20, %18 ], [ -1, %16 ]
  ret i32 %.0
}

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

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

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 = { 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 = { 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 #4 = { nofree nounwind }
attributes #5 = { nounwind }
attributes #6 = { cold }
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 = !{!"_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}


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