; LLVM IR from jingweizhanghuai/Morn :: example (log_file_rotate)

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

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [15 x i8], align 1
@morn_log_levelset = external global i32, align 4
@morn_log_level = external thread_local global i32, align 4
@.str.5 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [81 x i8], align 1
@__FUNCTION__.main = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %5 = call ptr @mMornObject(ptr noundef @.str, i32 noundef -1)
  %6 = call ptr @m_PropertyWrite(ptr noundef %5, ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef -1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 65536, ptr %2, align 4, !tbaa !5
  %7 = call ptr @mMornObject(ptr noundef @.str, i32 noundef -1)
  %8 = call ptr @m_PropertyWrite(ptr noundef %7, ptr noundef @.str.3, ptr noundef %2, i32 noundef 4)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 5, ptr %3, align 4, !tbaa !5
  %9 = call ptr @mMornObject(ptr noundef @.str, i32 noundef -1)
  %10 = call ptr @m_PropertyWrite(ptr noundef %9, ptr noundef @.str.4, ptr noundef %3, i32 noundef 4)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %29, %0
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 100000
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %32

15:                                               ; preds = %11
  %16 = call i32 @usleep(i32 noundef 1000)
  br label %17

17:                                               ; preds = %15
  %18 = load i32, ptr @morn_log_levelset, align 4, !tbaa !5
  %19 = icmp sge i32 32, %18
  br i1 %19, label %20, label %26

20:                                               ; preds = %17
  %21 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @morn_log_level)
  store i32 32, ptr %21, align 4, !tbaa !5
  %22 = call ptr (...) @mTimeNowString()
  %23 = call i32 (...) @mThreadID()
  %24 = call ptr (...) @mLogLevel()
  %25 = load i32, ptr %4, align 4, !tbaa !5
  call void (i32, ptr, ...) @m_Log(i32 noundef 32, ptr noundef @.str.5, ptr noundef %22, i32 noundef %23, ptr noundef @.str.6, i32 noundef 12, ptr noundef @__FUNCTION__.main, ptr noundef %24, i32 noundef %25)
  br label %26

26:                                               ; preds = %20, %17
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %4, align 4, !tbaa !5
  br label %11, !llvm.loop !9

32:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

declare ptr @m_PropertyWrite(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

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

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

declare i32 @usleep(i32 noundef) #1

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

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

declare ptr @mTimeNowString(...) #1

declare i32 @mThreadID(...) #1

declare ptr @mLogLevel(...) #1

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

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(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [15 x i8], align 1
@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.5 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [81 x i8], align 1
@__FUNCTION__.main = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call ptr @mMornObject(ptr noundef nonnull @.str, i32 noundef -1) #4
  %4 = tail call ptr @m_PropertyWrite(ptr noundef %3, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef -1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  store i32 65536, ptr %1, align 4, !tbaa !5
  %5 = tail call ptr @mMornObject(ptr noundef nonnull @.str, i32 noundef -1) #4
  %6 = call ptr @m_PropertyWrite(ptr noundef %5, ptr noundef nonnull @.str.3, ptr noundef nonnull %1, i32 noundef 4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  store i32 5, ptr %2, align 4, !tbaa !5
  %7 = call ptr @mMornObject(ptr noundef nonnull @.str, i32 noundef -1) #4
  %8 = call ptr @m_PropertyWrite(ptr noundef %7, ptr noundef nonnull @.str.4, ptr noundef nonnull %2, i32 noundef 4) #4
  %9 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @morn_log_level)
  br label %11

10:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0

11:                                               ; preds = %0, %19
  %.03 = phi i32 [ 0, %0 ], [ %20, %19 ]
  %12 = call i32 @usleep(i32 noundef 1000) #4
  %13 = load i32, ptr @morn_log_levelset, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 33
  br i1 %14, label %15, label %19

15:                                               ; preds = %11
  store i32 32, ptr %9, align 4, !tbaa !5
  %16 = call ptr (...) @mTimeNowString() #4
  %17 = call i32 (...) @mThreadID() #4
  %18 = call ptr (...) @mLogLevel() #4
  call void (i32, ptr, ...) @m_Log(i32 noundef 32, ptr noundef nonnull @.str.5, ptr noundef %16, i32 noundef %17, ptr noundef nonnull @.str.6, i32 noundef 12, ptr noundef nonnull @__FUNCTION__.main, ptr noundef %18, i32 noundef %.03) #4
  br label %19

19:                                               ; preds = %11, %15
  %20 = add nuw nsw i32 %.03, 1
  %exitcond.not = icmp eq i32 %20, 100000
  br i1 %exitcond.not, label %10, label %11, !llvm.loop !9
}

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

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

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

declare i32 @usleep(i32 noundef) local_unnamed_addr #1

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

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

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

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

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

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

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 willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass