; LLVM IR from NTHU-LSALAB/Gemini :: src/comm.ll (Z16multiple_attemptSt8functionIFivEEii)

; 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.1 = external hidden unnamed_addr constant [15 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z16multiple_attemptSt8functionIFivEEii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %36, %3
  %11 = load i32, ptr %8, align 4, !tbaa !9
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 2, ptr %9, align 4
  br label %39

15:                                               ; preds = %10
  %16 = call noundef i32 @_ZNKSt8functionIFivEEclEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  store i32 %16, ptr %7, align 4, !tbaa !9
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  store i32 2, ptr %9, align 4
  br label %39

20:                                               ; preds = %15
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = icmp eq i32 %21, -1
  br i1 %22, label %23, label %26

23:                                               ; preds = %20
  %24 = call ptr @__errno_location() #6
  %25 = load i32, ptr %24, align 4, !tbaa !9
  store i32 %25, ptr %7, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %23, %20
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = call ptr @strerror(i32 noundef %28) #5
  call void (ptr, ...) @_Z5ERRORPKcz(ptr noundef @.str.1, i32 noundef %27, ptr noundef %29)
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = icmp sgt i32 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %26
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = call i32 @sleep(i32 noundef %33)
  br label %35

35:                                               ; preds = %32, %26
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %8, align 4, !tbaa !9
  br label %10, !llvm.loop !11

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

40:                                               ; preds = %39
  %41 = load i32, ptr %7, align 4, !tbaa !9
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret i32 %41
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNKSt8functionIFivEEclEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #2

declare void @_Z5ERRORPKcz(ptr noundef, ...) #3

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #4

declare i32 @sleep(i32 noundef) #3

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

!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++ 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.1 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z16multiple_attemptSt8functionIFivEEii(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
.lr.ph:
  %.not14 = icmp sgt i32 %1, 0
  tail call void @llvm.assume(i1 %.not14)
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %8
  %.015.us = phi i32 [ %11, %8 ], [ 1, %.lr.ph ]
  %4 = tail call noundef i32 @_ZNKSt8functionIFivEEclEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  switch i32 %4, label %8 [
    i32 0, label %._crit_edge
    i32 -1, label %5
  ]

5:                                                ; preds = %.lr.ph.split.us
  %6 = tail call ptr @__errno_location() #5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %5, %.lr.ph.split.us
  %.1.us = phi i32 [ %7, %5 ], [ %4, %.lr.ph.split.us ]
  %9 = tail call ptr @strerror(i32 noundef %.1.us) #6
  tail call void (ptr, ...) @_Z5ERRORPKcz(ptr noundef nonnull @.str.1, i32 noundef %.015.us, ptr noundef %9)
  %10 = tail call i32 @sleep(i32 noundef %2)
  %11 = add nuw i32 %.015.us, 1
  %exitcond21.not = icmp eq i32 %.015.us, %1
  br i1 %exitcond21.not, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !9

.lr.ph.split:                                     ; preds = %.lr.ph, %16
  %.015 = phi i32 [ %18, %16 ], [ 1, %.lr.ph ]
  %12 = tail call noundef i32 @_ZNKSt8functionIFivEEclEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  switch i32 %12, label %16 [
    i32 0, label %._crit_edge
    i32 -1, label %13
  ]

13:                                               ; preds = %.lr.ph.split
  %14 = tail call ptr @__errno_location() #5
  %15 = load i32, ptr %14, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %.lr.ph.split, %13
  %.1 = phi i32 [ %15, %13 ], [ %12, %.lr.ph.split ]
  %17 = tail call ptr @strerror(i32 noundef %.1) #6
  tail call void (ptr, ...) @_Z5ERRORPKcz(ptr noundef nonnull @.str.1, i32 noundef %.015, ptr noundef %17)
  %18 = add nuw i32 %.015, 1
  %exitcond.not = icmp eq i32 %.015, %1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !9

._crit_edge:                                      ; preds = %16, %.lr.ph.split, %8, %.lr.ph.split.us
  %.2 = phi i32 [ %4, %.lr.ph.split.us ], [ %.1.us, %8 ], [ %12, %.lr.ph.split ], [ %.1, %16 ]
  ret i32 %.2
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNKSt8functionIFivEEclEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #1

declare void @_Z5ERRORPKcz(ptr noundef, ...) local_unnamed_addr #2

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #3

declare i32 @sleep(i32 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)
declare void @llvm.assume(i1 noundef) #4

attributes #0 = { mustprogress 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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 "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 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }
attributes #5 = { nounwind willreturn memory(none) }
attributes #6 = { 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass