; 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_output_handler = external hidden global ptr, align 8
@stderr = external global ptr, align 8
@.str.34 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.35 = 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 void @rcutils_logging_set_output_handler(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %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
  store ptr %0, ptr %2, align 8, !tbaa !5
  br label %6

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

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

17:                                               ; preds = %14
  br label %18

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

21:                                               ; preds = %18
  br label %22

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

30:                                               ; preds = %22
  br label %31

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

34:                                               ; preds = %31
  call void @rcutils_reset_error()
  br label %35

35:                                               ; preds = %34, %14
  br label %36

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

37:                                               ; preds = %36
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %38, ptr @g_rcutils_logging_output_handler, align 8, !tbaa !5
  ret void
}

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
@g_rcutils_logging_output_handler = external hidden local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.34 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.35 = 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 void @rcutils_logging_set_output_handler(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.35, 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
  store ptr %0, ptr @g_rcutils_logging_output_handler, align 8, !tbaa !12
  ret void
}

; 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