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

; 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.6 = external hidden unnamed_addr constant [39 x i8], align 1
@main.Info = external hidden global ptr, align 8
@__const.main.Key = external hidden unnamed_addr constant [2 x ptr], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @test1() #0

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

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #4

declare ptr @m_CoroutineInfo(ptr noundef, ptr noundef, ptr noundef) #2

declare void @m_Coroutine(ptr 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 i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [2 x ptr], align 16
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %4

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

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

8:                                                ; preds = %4
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %9)
  br label %11

11:                                               ; preds = %8
  br label %12

12:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %3, ptr align 16 @__const.main.Key, i64 16, i1 false)
  %13 = load ptr, ptr @main.Info, align 8, !tbaa !9
  %14 = icmp eq ptr %13, null
  br i1 %14, label %20, label %15

15:                                               ; preds = %12
  %16 = getelementptr inbounds [2 x ptr], ptr %3, i64 0, i64 0
  %17 = load ptr, ptr @main.Info, align 8, !tbaa !9
  %18 = call i32 @memcmp(ptr noundef %16, ptr noundef %17, i64 noundef 16) #6
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %15, %12
  %21 = call ptr @m_CoroutineInfo(ptr noundef @test1, ptr noundef inttoptr (i64 -1 to ptr), ptr noundef inttoptr (i64 -1 to ptr))
  store ptr %21, ptr @main.Info, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %20, %15
  %23 = load ptr, ptr @main.Info, align 8, !tbaa !9
  call void @m_Coroutine(ptr noundef %23)
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #5
  br label %24

24:                                               ; preds = %22
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  br label %28

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

31:                                               ; preds = %7
  ret i32 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 nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind willreturn memory(read) "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

@.str.6 = external hidden unnamed_addr constant [39 x i8], align 1
@main.Info = external hidden local_unnamed_addr global ptr, align 8
@__const.main.Key = external hidden unnamed_addr constant [2 x ptr], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @test1() #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

declare ptr @m_CoroutineInfo(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @m_Coroutine(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef 0)
  %2 = load ptr, ptr @main.Info, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %5, label %4

4:                                                ; preds = %0
  %bcmp = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(16) @__const.main.Key, ptr noundef nonnull dereferenceable(16) %2, i64 16)
  %.not = icmp eq i32 %bcmp, 0
  br i1 %.not, label %7, label %5

5:                                                ; preds = %4, %0
  %6 = tail call ptr @m_CoroutineInfo(ptr noundef nonnull @test1, ptr noundef nonnull inttoptr (i64 -1 to ptr), ptr noundef nonnull inttoptr (i64 -1 to ptr)) #4
  store ptr %6, ptr @main.Info, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %5, %4
  %8 = phi ptr [ %6, %5 ], [ %2, %4 ]
  tail call void @m_Coroutine(ptr noundef %8) #4
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef 1)
  %10 = load ptr, ptr @main.Info, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %7
  %bcmp.1 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(16) @__const.main.Key, ptr noundef nonnull dereferenceable(16) %10, i64 16)
  %.not.1 = icmp eq i32 %bcmp.1, 0
  br i1 %.not.1, label %15, label %13

13:                                               ; preds = %12, %7
  %14 = tail call ptr @m_CoroutineInfo(ptr noundef nonnull @test1, ptr noundef nonnull inttoptr (i64 -1 to ptr), ptr noundef nonnull inttoptr (i64 -1 to ptr)) #4
  store ptr %14, ptr @main.Info, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %13, %12
  %16 = phi ptr [ %14, %13 ], [ %10, %12 ]
  tail call void @m_Coroutine(ptr noundef %16) #4
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef 2)
  %18 = load ptr, ptr @main.Info, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %15
  %bcmp.2 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(16) @__const.main.Key, ptr noundef nonnull dereferenceable(16) %18, i64 16)
  %.not.2 = icmp eq i32 %bcmp.2, 0
  br i1 %.not.2, label %23, label %21

21:                                               ; preds = %20, %15
  %22 = tail call ptr @m_CoroutineInfo(ptr noundef nonnull @test1, ptr noundef nonnull inttoptr (i64 -1 to ptr), ptr noundef nonnull inttoptr (i64 -1 to ptr)) #4
  store ptr %22, ptr @main.Info, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %21, %20
  %24 = phi ptr [ %22, %21 ], [ %18, %20 ]
  tail call void @m_Coroutine(ptr noundef %24) #4
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef 3)
  %26 = load ptr, ptr @main.Info, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %23
  %bcmp.3 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(16) @__const.main.Key, ptr noundef nonnull dereferenceable(16) %26, i64 16)
  %.not.3 = icmp eq i32 %bcmp.3, 0
  br i1 %.not.3, label %31, label %29

29:                                               ; preds = %28, %23
  %30 = tail call ptr @m_CoroutineInfo(ptr noundef nonnull @test1, ptr noundef nonnull inttoptr (i64 -1 to ptr), ptr noundef nonnull inttoptr (i64 -1 to ptr)) #4
  store ptr %30, ptr @main.Info, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %29, %28
  %32 = phi ptr [ %30, %29 ], [ %26, %28 ]
  tail call void @m_Coroutine(ptr noundef %32) #4
  ret i32 0
}

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #3

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 = { nofree nounwind "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 = { "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 = { nofree nounwind willreturn memory(argmem: read) }
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"}


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