; LLVM IR from jingweizhanghuai/Morn :: test (test_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"

@morn_log_levelset = external global i32, align 4
@morn_log_level = external thread_local global i32, align 4
@.str.3 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [63 x i8], align 1
@__FUNCTION__.thread_log = external hidden unnamed_addr constant [11 x i8], align 1

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

declare void @m_Log(i32 noundef, ptr noundef, ...) #1

declare ptr @mLogLevel(...) #1

declare ptr @mTimeNowString(...) #1

declare i32 @mThreadID(...) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @thread_log(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %4

4:                                                ; preds = %21, %1
  %5 = load i32, ptr %3, align 4, !tbaa !9
  %6 = icmp slt i32 %5, 100
  br i1 %6, label %8, label %7

7:                                                ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %24

8:                                                ; preds = %4
  br label %9

9:                                                ; preds = %8
  %10 = load i32, ptr @morn_log_levelset, align 4, !tbaa !9
  %11 = icmp sge i32 32, %10
  br i1 %11, label %12, label %18

12:                                               ; preds = %9
  %13 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @morn_log_level)
  store i32 32, ptr %13, align 4, !tbaa !9
  %14 = call ptr (...) @mTimeNowString()
  %15 = call i32 (...) @mThreadID()
  %16 = call ptr (...) @mLogLevel()
  %17 = load i32, ptr %3, align 4, !tbaa !9
  call void (i32, ptr, ...) @m_Log(i32 noundef 32, ptr noundef @.str.33, ptr noundef %14, i32 noundef %15, ptr noundef @.str.3, i32 noundef 103, ptr noundef @__FUNCTION__.thread_log, ptr noundef %16, i32 noundef %17)
  br label %18

18:                                               ; preds = %12, %9
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  %22 = load i32, ptr %3, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %3, align 4, !tbaa !9
  br label %4, !llvm.loop !11

24:                                               ; preds = %7
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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_levelset = external local_unnamed_addr global i32, align 4
@morn_log_level = external thread_local local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [63 x i8], align 1
@__FUNCTION__.thread_log = external hidden unnamed_addr constant [11 x i8], align 1

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

declare void @m_Log(i32 noundef, ptr noundef, ...) local_unnamed_addr #1

declare ptr @mLogLevel(...) local_unnamed_addr #1

declare ptr @mTimeNowString(...) local_unnamed_addr #1

declare i32 @mThreadID(...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @thread_log(ptr nocapture noundef readnone %0) local_unnamed_addr #2 {
  %2 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @morn_log_level)
  %3 = load i32, ptr @morn_log_levelset, align 4, !tbaa !5
  %4 = icmp slt i32 %3, 33
  br i1 %4, label %.split, label %.split5.us

.split5.us:                                       ; preds = %11, %1
  ret void

.split:                                           ; preds = %1, %11
  %5 = phi i32 [ %12, %11 ], [ %3, %1 ]
  %.03 = phi i32 [ %13, %11 ], [ 0, %1 ]
  %6 = icmp slt i32 %5, 33
  br i1 %6, label %7, label %11

7:                                                ; preds = %.split
  store i32 32, ptr %2, align 4, !tbaa !5
  %8 = tail call ptr (...) @mTimeNowString() #3
  %9 = tail call i32 (...) @mThreadID() #3
  %10 = tail call ptr (...) @mLogLevel() #3
  tail call void (i32, ptr, ...) @m_Log(i32 noundef 32, ptr noundef nonnull @.str.33, ptr noundef %8, i32 noundef %9, ptr noundef nonnull @.str.3, i32 noundef 103, ptr noundef nonnull @__FUNCTION__.thread_log, ptr noundef %10, i32 noundef %.03) #3
  %.pre = load i32, ptr @morn_log_levelset, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %.split, %7
  %12 = phi i32 [ %5, %.split ], [ %.pre, %7 ]
  %13 = add nuw nsw i32 %.03, 1
  %exitcond.not = icmp eq i32 %13, 100
  br i1 %exitcond.not, label %.split5.us, label %.split, !llvm.loop !9
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.unswitch.partial.disable"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass