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

; Function Attrs: nounwind uwtable
define dso_local void @test1() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [2 x ptr], align 16
  %3 = alloca [2 x ptr], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %43, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %5)
  br label %7

7:                                                ; preds = %4
  br label %8

8:                                                ; preds = %7
  call void @llvm.lifetime.start.p0(i64 16, ptr %2) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %2, ptr align 16 @__const.test1.Key, i64 16, i1 false)
  %9 = load ptr, ptr @test1.Info, align 8, !tbaa !9
  %10 = icmp eq ptr %9, null
  br i1 %10, label %16, label %11

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

16:                                               ; preds = %11, %8
  %17 = call ptr @m_CoroutineInfo(ptr noundef @test2, ptr noundef inttoptr (i64 -1 to ptr), ptr noundef inttoptr (i64 -1 to ptr))
  store ptr %17, ptr @test1.Info, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %16, %11
  %19 = load ptr, ptr @test1.Info, align 8, !tbaa !9
  call void @m_Coroutine(ptr noundef %19)
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #5
  br label %20

20:                                               ; preds = %18
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %24)
  br label %26

26:                                               ; preds = %23
  br label %27

27:                                               ; preds = %26
  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.test1.Key.3, i64 16, i1 false)
  %28 = load ptr, ptr @test1.Info.2, align 8, !tbaa !9
  %29 = icmp eq ptr %28, null
  br i1 %29, label %35, label %30

30:                                               ; preds = %27
  %31 = getelementptr inbounds [2 x ptr], ptr %3, i64 0, i64 0
  %32 = load ptr, ptr @test1.Info.2, align 8, !tbaa !9
  %33 = call i32 @memcmp(ptr noundef %31, ptr noundef %32, i64 noundef 16) #6
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %30, %27
  %36 = call ptr @m_CoroutineInfo(ptr noundef @test3, ptr noundef inttoptr (i64 -1 to ptr), ptr noundef inttoptr (i64 -1 to ptr))
  store ptr %36, ptr @test1.Info.2, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %35, %30
  %38 = load ptr, ptr @test1.Info.2, align 8, !tbaa !9
  call void @m_Coroutine(ptr noundef %38)
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #5
  br label %39

39:                                               ; preds = %37
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %1, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %1, align 4, !tbaa !5
  br label %4
}

; 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
declare dso_local void @test2() #0

; Function Attrs: nounwind uwtable
declare dso_local void @test3() #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}


; 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 [38 x i8], align 1
@test1.Info = external hidden local_unnamed_addr global ptr, align 8
@__const.test1.Key = external hidden unnamed_addr constant [2 x ptr], align 16
@.str.1 = external hidden unnamed_addr constant [38 x i8], align 1
@test1.Info.2 = external hidden local_unnamed_addr global ptr, align 8
@__const.test1.Key.3 = external hidden unnamed_addr constant [2 x ptr], align 16

; Function Attrs: noreturn nounwind uwtable
define dso_local void @test1() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %16, %0
  %.0 = phi i32 [ 0, %0 ], [ %18, %16 ]
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %.0)
  %3 = load ptr, ptr @test1.Info, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %6, label %5

5:                                                ; preds = %1
  %bcmp = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(16) @__const.test1.Key, ptr noundef nonnull dereferenceable(16) %3, i64 16)
  %.not = icmp eq i32 %bcmp, 0
  br i1 %.not, label %8, label %6

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

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

13:                                               ; preds = %8
  %bcmp5 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(16) @__const.test1.Key.3, ptr noundef nonnull dereferenceable(16) %11, i64 16)
  %.not6 = icmp eq i32 %bcmp5, 0
  br i1 %.not6, label %16, label %14

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

16:                                               ; preds = %14, %13
  %17 = phi ptr [ %15, %14 ], [ %11, %13 ]
  tail call void @m_Coroutine(ptr noundef %17) #5
  %18 = add nuw nsw i32 %.0, 1
  br label %1
}

; 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
declare dso_local void @test2() #3

; Function Attrs: nounwind uwtable
declare dso_local void @test3() #3

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

attributes #0 = { noreturn 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 = { 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 = { nofree nounwind willreturn memory(argmem: read) }
attributes #5 = { 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,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass