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

; 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 [23 x i8], align 1
@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 [60 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [74 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
  store i32 0, ptr %1, align 4
  %3 = call ptr @mMornObject(ptr noundef @.str, i32 noundef -1)
  %4 = call ptr @m_PropertyWrite(ptr noundef %3, ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef -1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %23, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 2000
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %26

9:                                                ; preds = %5
  %10 = call i32 @usleep(i32 noundef 10000)
  br label %11

11:                                               ; preds = %9
  %12 = load i32, ptr @morn_log_levelset, align 4, !tbaa !5
  %13 = icmp sge i32 32, %12
  br i1 %13, label %14, label %20

14:                                               ; preds = %11
  %15 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @morn_log_level)
  store i32 32, ptr %15, align 4, !tbaa !5
  %16 = call ptr (...) @mTimeNowString()
  %17 = call i32 (...) @mThreadID()
  %18 = call ptr (...) @mLogLevel()
  %19 = load i32, ptr %2, align 4, !tbaa !5
  call void (i32, ptr, ...) @m_Log(i32 noundef 32, ptr noundef @.str.3, ptr noundef %16, i32 noundef %17, ptr noundef @.str.4, i32 noundef 10, ptr noundef @__FUNCTION__.main, ptr noundef %18, i32 noundef %19)
  br label %20

20:                                               ; preds = %14, %11
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !9

26:                                               ; preds = %8
  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 [23 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.3 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [74 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 = tail call ptr @mMornObject(ptr noundef nonnull @.str, i32 noundef -1) #3
  %2 = tail call ptr @m_PropertyWrite(ptr noundef %1, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef -1) #3
  %3 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @morn_log_level)
  br label %5

4:                                                ; preds = %13
  ret i32 0

5:                                                ; preds = %0, %13
  %.03 = phi i32 [ 0, %0 ], [ %14, %13 ]
  %6 = tail call i32 @usleep(i32 noundef 10000) #3
  %7 = load i32, ptr @morn_log_levelset, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 33
  br i1 %8, label %9, label %13

9:                                                ; preds = %5
  store i32 32, ptr %3, align 4, !tbaa !5
  %10 = tail call ptr (...) @mTimeNowString() #3
  %11 = tail call i32 (...) @mThreadID() #3
  %12 = tail call ptr (...) @mLogLevel() #3
  tail call void (i32, ptr, ...) @m_Log(i32 noundef 32, ptr noundef nonnull @.str.3, ptr noundef %10, i32 noundef %11, ptr noundef nonnull @.str.4, i32 noundef 10, ptr noundef nonnull @__FUNCTION__.main, ptr noundef %12, i32 noundef %.03) #3
  br label %13

13:                                               ; preds = %5, %9
  %14 = add nuw nsw i32 %.03, 1
  %exitcond.not = icmp eq i32 %14, 2000
  br i1 %exitcond.not, label %4, label %5, !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

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) #2

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

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, !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