; LLVM IR from jingweizhanghuai/Morn :: test (test_coroutine)

; 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.2 = external hidden unnamed_addr constant [23 x i8], align 1
@test2.Info = external hidden global ptr, align 8
@test2.Info.3 = external hidden global ptr, align 8

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

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

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

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

declare void @m_Coroutine(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @test2_1(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @test2(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca [2 x ptr], align 16
  %5 = alloca [2 x ptr], align 16
  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 %6

6:                                                ; preds = %34, %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %11, label %10

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

11:                                               ; preds = %6
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %12)
  br label %14

14:                                               ; preds = %11
  br label %15

15:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #4
  store ptr @test2_1, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds ptr, ptr %4, i64 1
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %17, ptr %16, align 8, !tbaa !5
  %18 = load ptr, ptr @test2.Info, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %25, label %20

20:                                               ; preds = %15
  %21 = getelementptr inbounds [2 x ptr], ptr %4, i64 0, i64 0
  %22 = load ptr, ptr @test2.Info, align 8, !tbaa !5
  %23 = call i32 @memcmp(ptr noundef %21, ptr noundef %22, i64 noundef 16) #5
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %20, %15
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = call ptr @m_CoroutineInfo(ptr noundef @test2_1, ptr noundef %26, ptr noundef inttoptr (i64 -1 to ptr))
  store ptr %27, ptr @test2.Info, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %25, %20
  %29 = load ptr, ptr @test2.Info, align 8, !tbaa !5
  call void @m_Coroutine(ptr noundef %29)
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #4
  br label %30

30:                                               ; preds = %28
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %3, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %3, align 4, !tbaa !9
  br label %6, !llvm.loop !11

37:                                               ; preds = %10
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #4
  store ptr @test2_1, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds ptr, ptr %5, i64 1
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %41, ptr %40, align 8, !tbaa !5
  %42 = load ptr, ptr @test2.Info.3, align 8, !tbaa !5
  %43 = icmp eq ptr %42, null
  br i1 %43, label %49, label %44

44:                                               ; preds = %39
  %45 = getelementptr inbounds [2 x ptr], ptr %5, i64 0, i64 0
  %46 = load ptr, ptr @test2.Info.3, align 8, !tbaa !5
  %47 = call i32 @memcmp(ptr noundef %45, ptr noundef %46, i64 noundef 16) #5
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %52

49:                                               ; preds = %44, %39
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = call ptr @m_CoroutineInfo(ptr noundef @test2_1, ptr noundef %50, ptr noundef inttoptr (i64 -1 to ptr))
  store ptr %51, ptr @test2.Info.3, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %49, %44
  %53 = load ptr, ptr @test2.Info.3, align 8, !tbaa !5
  call void @m_Coroutine(ptr noundef %53)
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #4
  br label %54

54:                                               ; preds = %52
  br label %55

55:                                               ; preds = %54
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 }
attributes #5 = { 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 = !{!"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"

@.str.2 = external hidden unnamed_addr constant [23 x i8], align 1
@test2.Info = external hidden local_unnamed_addr global ptr, align 8
@test2.Info.3 = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @test2_1(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @test2(ptr noundef %0) local_unnamed_addr #3 {
  %2 = alloca [2 x ptr], align 16
  %3 = alloca [2 x ptr], align 16
  %4 = load i32, ptr %0, align 4, !tbaa !5
  %.not11 = icmp eq i32 %4, 0
  br i1 %.not11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %2, i64 8
  br label %9

._crit_edge:                                      ; preds = %16, %1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #5
  store ptr @test2_1, ptr %3, align 16, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %0, ptr %6, align 8, !tbaa !9
  %7 = load ptr, ptr @test2.Info.3, align 8, !tbaa !9
  %8 = icmp eq ptr %7, null
  br i1 %8, label %21, label %20

9:                                                ; preds = %.lr.ph, %16
  %.012 = phi i32 [ 0, %.lr.ph ], [ %18, %16 ]
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.012)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #5
  store ptr @test2_1, ptr %2, align 16, !tbaa !9
  store ptr %0, ptr %5, align 8, !tbaa !9
  %11 = load ptr, ptr @test2.Info, align 8, !tbaa !9
  %12 = icmp eq ptr %11, null
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  %bcmp9 = call i32 @bcmp(ptr noundef nonnull dereferenceable(16) %2, ptr noundef nonnull dereferenceable(16) %11, i64 16)
  %.not10 = icmp eq i32 %bcmp9, 0
  br i1 %.not10, label %16, label %14

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

16:                                               ; preds = %14, %13
  %17 = phi ptr [ %15, %14 ], [ %11, %13 ]
  tail call void @m_Coroutine(ptr noundef %17) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #5
  %18 = add nuw nsw i32 %.012, 1
  %19 = load i32, ptr %0, align 4, !tbaa !5
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %._crit_edge, label %9, !llvm.loop !11

20:                                               ; preds = %._crit_edge
  %bcmp = call i32 @bcmp(ptr noundef nonnull dereferenceable(16) %3, ptr noundef nonnull dereferenceable(16) %7, i64 16)
  %.not8 = icmp eq i32 %bcmp, 0
  br i1 %.not8, label %23, label %21

21:                                               ; preds = %20, %._crit_edge
  %22 = tail call ptr @m_CoroutineInfo(ptr noundef nonnull @test2_1, ptr noundef nonnull %0, ptr noundef nonnull inttoptr (i64 -1 to ptr)) #5
  store ptr %22, ptr @test2.Info.3, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %21, %20
  %24 = phi ptr [ %22, %21 ], [ %7, %20 ]
  tail call void @m_Coroutine(ptr noundef %24) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #5
  ret void
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass