; LLVM IR from jingweizhanghuai/Morn :: src/util (morn_log)

; 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.MHandle = type { i32, i32, ptr, ptr }
%struct.HandleLog = type { i32, [128 x i8], [128 x i8], [16 x i8], i64, i32, i32, %struct.MThreadSignal, i32, i32, i32, i32, ptr, i32, i32, i32, ptr, ptr }
%struct.MThreadSignal = type { %union.pthread_mutex_t, %union.pthread_cond_t, %union.pthread_rwlock_t, i32 }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { i64 }
%union.pthread_rwlock_t = type { %struct.__pthread_rwlock_arch_t }
%struct.__pthread_rwlock_arch_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i8, [7 x i8], i64, i32 }

@morn_log_level = external dso_local thread_local global i32, align 4
@morn_log_levelset = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [56 x i8], align 1
@__FUNCTION__.LogConsole = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @endLog(ptr noundef) #0

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

declare ptr @GetHandle(ptr noundef, i32 noundef, i32 noundef, ptr noundef) #2

declare ptr @mMornObject(ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @LogConsole(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %5 = call ptr @mMornObject(ptr noundef @.str, i32 noundef -1)
  %6 = call ptr @GetHandle(ptr noundef %5, i32 noundef 504, i32 noundef 1060628209, ptr noundef @endLog)
  store ptr %6, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.MHandle, ptr %7, i32 0, i32 3
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load i32, ptr %10, align 4, !tbaa !12
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.HandleLog, ptr %12, i32 0, i32 13
  store i32 %11, ptr %13, align 8, !tbaa !13
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.HandleLog, ptr %14, i32 0, i32 13
  %16 = load i32, ptr %15, align 8, !tbaa !13
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %31, label %18

18:                                               ; preds = %1
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.HandleLog, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !17
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %28, label %23

23:                                               ; preds = %18
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.HandleLog, ptr %24, i32 0, i32 15
  %26 = load i32, ptr %25, align 8, !tbaa !18
  %27 = icmp ne i32 %26, 0
  br label %28

28:                                               ; preds = %23, %18
  %29 = phi i1 [ true, %18 ], [ %27, %23 ]
  %30 = xor i1 %29, true
  br label %31

31:                                               ; preds = %28, %1
  %32 = phi i1 [ true, %1 ], [ %30, %28 ]
  %33 = zext i1 %32 to i32
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.HandleLog, ptr %34, i32 0, i32 14
  store i32 %33, ptr %35, align 4, !tbaa !19
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.HandleLog, ptr %36, i32 0, i32 14
  %38 = load i32, ptr %37, align 4, !tbaa !19
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.HandleLog, ptr %39, i32 0, i32 13
  %41 = load i32, ptr %40, align 8, !tbaa !13
  %42 = icmp ne i32 %38, %41
  br i1 %42, label %43, label %53

43:                                               ; preds = %31
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr @morn_log_levelset, align 4, !tbaa !12
  %46 = icmp sge i32 48, %45
  br i1 %46, label %47, label %50

47:                                               ; preds = %44
  %48 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @morn_log_level)
  store i32 48, ptr %48, align 4, !tbaa !12
  %49 = call ptr @mLogLevel()
  call void (i32, ptr, ...) @m_Log(i32 noundef 48, ptr noundef @.str.10, ptr noundef @.str.5, i32 noundef 231, ptr noundef @__FUNCTION__.LogConsole, ptr noundef %49)
  br label %50

50:                                               ; preds = %47, %44
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #3

; Function Attrs: nounwind uwtable
declare dso_local void @m_Log(i32 noundef, ptr noundef, ...) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @mLogLevel() #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"MHandle", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 472}
!14 = !{!"HandleLog", !11, i64 0, !7, i64 4, !7, i64 132, !7, i64 260, !15, i64 280, !11, i64 288, !11, i64 292, !16, i64 296, !11, i64 448, !11, i64 452, !11, i64 456, !11, i64 460, !6, i64 464, !11, i64 472, !11, i64 476, !11, i64 480, !6, i64 488, !6, i64 496}
!15 = !{!"long", !7, i64 0}
!16 = !{!"MThreadSignal", !7, i64 0, !7, i64 40, !7, i64 88, !11, i64 144}
!17 = !{!14, !11, i64 0}
!18 = !{!14, !11, i64 480}
!19 = !{!14, !11, i64 476}


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

@morn_log_level = external dso_local thread_local local_unnamed_addr global i32, align 4
@morn_log_levelset = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [56 x i8], align 1
@__FUNCTION__.LogConsole = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @endLog(ptr noundef) #0

declare ptr @GetHandle(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare ptr @mMornObject(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @LogConsole(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = tail call ptr @mMornObject(ptr noundef nonnull @.str, i32 noundef -1) #3
  %3 = tail call ptr @GetHandle(ptr noundef %2, i32 noundef 504, i32 noundef 1060628209, ptr noundef nonnull @endLog) #3
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = load i32, ptr %0, align 4, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %5, i64 472
  store i32 %6, ptr %7, align 8, !tbaa !12
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %8, label %15

8:                                                ; preds = %1
  %9 = load i32, ptr %5, align 8, !tbaa !16
  %.not10 = icmp eq i32 %9, 0
  br i1 %.not10, label %10, label %15

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %5, i64 480
  %12 = load i32, ptr %11, align 8, !tbaa !17
  %13 = icmp eq i32 %12, 0
  %14 = zext i1 %13 to i32
  br label %15

15:                                               ; preds = %8, %10, %1
  %16 = phi i32 [ 1, %1 ], [ 0, %8 ], [ %14, %10 ]
  %17 = getelementptr inbounds i8, ptr %5, i64 476
  store i32 %16, ptr %17, align 4, !tbaa !18
  %18 = icmp ne i32 %16, %6
  %19 = load i32, ptr @morn_log_levelset, align 4
  %20 = icmp slt i32 %19, 49
  %or.cond = select i1 %18, i1 %20, i1 false
  br i1 %or.cond, label %21, label %24

21:                                               ; preds = %15
  %22 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @morn_log_level)
  store i32 48, ptr %22, align 4, !tbaa !11
  %23 = tail call ptr @mLogLevel()
  tail call void (i32, ptr, ...) @m_Log(i32 noundef 48, ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.5, i32 noundef 231, ptr noundef nonnull @__FUNCTION__.LogConsole, ptr noundef %23)
  br label %24

24:                                               ; preds = %21, %15
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #2

; Function Attrs: nounwind uwtable
declare dso_local void @m_Log(i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @mLogLevel() local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !10, i64 16}
!6 = !{!"MHandle", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 472}
!13 = !{!"HandleLog", !7, i64 0, !8, i64 4, !8, i64 132, !8, i64 260, !14, i64 280, !7, i64 288, !7, i64 292, !15, i64 296, !7, i64 448, !7, i64 452, !7, i64 456, !7, i64 460, !10, i64 464, !7, i64 472, !7, i64 476, !7, i64 480, !10, i64 488, !10, i64 496}
!14 = !{!"long", !8, i64 0}
!15 = !{!"MThreadSignal", !8, i64 0, !8, i64 40, !8, i64 88, !7, i64 144}
!16 = !{!13, !7, i64 0}
!17 = !{!13, !7, i64 480}
!18 = !{!13, !7, i64 476}


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