; LLVM IR from mhsitu/welding_robot :: common/sys_log.ll/ZN7CLogger7managerEPKc9eLogLevelS1_P13 (va_list_tag)

; 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.CLogger = type { %struct.LogTimeStamp_t, %struct.LogConfig_t, %struct.LogBuff_t, %struct.LogFilter_t, ptr }
%struct.LogTimeStamp_t = type { i8, i8, i16 }
%struct.LogConfig_t = type { i32, i8, i8 }
%struct.LogBuff_t = type { [258 x i8], i16 }
%struct.LogFilter_t = type { [33 x i8], i32, ptr, %struct._list_t }
%struct._list_t = type { ptr, ptr }

; 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 void @_ZN7CLogger7managerEPKc9eLogLevelS1_P13__va_list_tag(ptr noundef nonnull align 8 dereferenceable(344) %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #1 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = getelementptr inbounds %class.CLogger, ptr %13, i32 0, i32 1
  %16 = getelementptr inbounds %struct.LogConfig_t, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp slt i32 %14, %17
  br i1 %18, label %22, label %19

19:                                               ; preds = %5
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %19, %5
  store i32 1, ptr %12, align 4
  br label %53

23:                                               ; preds = %19
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = call noundef ptr @_ZN7CLogger12check_filterEPKc9eLogLevel(ptr noundef nonnull align 8 dereferenceable(344) %13, ptr noundef %24, i32 noundef %25)
  store ptr %26, ptr %11, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  store i32 1, ptr %12, align 4
  br label %53

29:                                               ; preds = %23
  br label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr %11, align 8, !tbaa !5
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = call noundef i32 @_ZN7CLogger9formatterEP11LogFilter_t9eLogLevelPKcP13__va_list_tag(ptr noundef nonnull align 8 dereferenceable(344) %13, ptr noundef %31, i32 noundef %32, ptr noundef %33, ptr noundef %34)
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.LogFilter_t, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !20
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %51

40:                                               ; preds = %30
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.LogFilter_t, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !20
  %44 = getelementptr inbounds %class.CLogger, ptr %13, i32 0, i32 2
  %45 = getelementptr inbounds %struct.LogBuff_t, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds [258 x i8], ptr %45, i64 0, i64 0
  %47 = getelementptr inbounds %class.CLogger, ptr %13, i32 0, i32 2
  %48 = getelementptr inbounds %struct.LogBuff_t, ptr %47, i32 0, i32 1
  %49 = load i16, ptr %48, align 2, !tbaa !21
  %50 = call noundef i32 %43(ptr noundef %46, i16 noundef zeroext %49)
  br label %52

51:                                               ; preds = %30
  store i32 1, ptr %12, align 4
  br label %53

52:                                               ; preds = %40
  store i32 0, ptr %12, align 4
  br label %53

53:                                               ; preds = %52, %51, %28, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %54 = load i32, ptr %12, align 4
  switch i32 %54, label %56 [
    i32 0, label %55
    i32 1, label %55
  ]

55:                                               ; preds = %53, %53
  ret void

56:                                               ; preds = %53
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7CLogger12check_filterEPKc9eLogLevel(ptr noundef nonnull align 8 dereferenceable(344), ptr noundef, i32 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN7CLogger9formatterEP11LogFilter_t9eLogLevelPKcP13__va_list_tag(ptr noundef nonnull align 8 dereferenceable(344), ptr noundef, i32 noundef, ptr noundef, ptr noundef) #3 align 2

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 = { inlinehint mustprogress 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 = { inlinehint 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 #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTS9eLogLevel", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTS7CLogger", !13, i64 0, !15, i64 4, !17, i64 12, !18, i64 272, !6, i64 336}
!13 = !{!"_ZTS14LogTimeStamp_t", !7, i64 0, !7, i64 1, !14, i64 2}
!14 = !{!"short", !7, i64 0}
!15 = !{!"_ZTS11LogConfig_t", !10, i64 0, !16, i64 4, !16, i64 5}
!16 = !{!"bool", !7, i64 0}
!17 = !{!"_ZTS9LogBuff_t", !7, i64 0, !14, i64 258}
!18 = !{!"_ZTS11LogFilter_t", !7, i64 0, !10, i64 36, !6, i64 40, !19, i64 48}
!19 = !{!"_ZTS7_list_t", !6, i64 0, !6, i64 8}
!20 = !{!18, !6, i64 40}
!21 = !{!12, !14, i64 270}


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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7CLogger7managerEPKc9eLogLevelS1_P13__va_list_tag(ptr noundef nonnull align 8 dereferenceable(344) %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 align 2 {
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, %2
  %9 = icmp eq i32 %2, 0
  %or.cond = or i1 %9, %8
  br i1 %or.cond, label %22, label %10

10:                                               ; preds = %5
  %11 = tail call noundef ptr @_ZN7CLogger12check_filterEPKc9eLogLevel(ptr noundef nonnull align 8 dereferenceable(344) %0, ptr noundef %1, i32 noundef %2)
  %12 = icmp eq ptr %11, null
  br i1 %12, label %22, label %13

13:                                               ; preds = %10
  %14 = tail call noundef i32 @_ZN7CLogger9formatterEP11LogFilter_t9eLogLevelPKcP13__va_list_tag(ptr noundef nonnull align 8 dereferenceable(344) %0, ptr noundef nonnull %11, i32 noundef %2, ptr noundef %3, ptr noundef %4)
  %15 = getelementptr inbounds i8, ptr %11, i64 40
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %22, label %17

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %0, i64 12
  %19 = getelementptr inbounds i8, ptr %0, i64 270
  %20 = load i16, ptr %19, align 2, !tbaa !19
  %21 = tail call noundef i32 %16(ptr noundef nonnull %18, i16 noundef zeroext %20)
  br label %22

22:                                               ; preds = %13, %10, %5, %17
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7CLogger12check_filterEPKc9eLogLevel(ptr noundef nonnull align 8 dereferenceable(344), ptr noundef, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN7CLogger9formatterEP11LogFilter_t9eLogLevelPKcP13__va_list_tag(ptr noundef nonnull align 8 dereferenceable(344), ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2 align 2

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 = { inlinehint mustprogress 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 #2 = { inlinehint 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" }

!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, !12, i64 4}
!6 = !{!"_ZTS7CLogger", !7, i64 0, !11, i64 4, !14, i64 12, !15, i64 272, !16, i64 336}
!7 = !{!"_ZTS14LogTimeStamp_t", !8, i64 0, !8, i64 1, !10, i64 2}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"_ZTS11LogConfig_t", !12, i64 0, !13, i64 4, !13, i64 5}
!12 = !{!"_ZTS9eLogLevel", !8, i64 0}
!13 = !{!"bool", !8, i64 0}
!14 = !{!"_ZTS9LogBuff_t", !8, i64 0, !10, i64 258}
!15 = !{!"_ZTS11LogFilter_t", !8, i64 0, !12, i64 36, !16, i64 40, !17, i64 48}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"_ZTS7_list_t", !16, i64 0, !16, i64 8}
!18 = !{!15, !16, i64 40}
!19 = !{!6, !10, i64 270}


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