; LLVM IR from upupming/algorithm :: kick-start/2020/2020B-C.ll (Z3runRKcRxS1_)

; 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"

@bound = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3modxx(i64 noundef, i64 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3runRKcRxS1_(ptr noundef nonnull align 1 dereferenceable(1) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = load i8, ptr %7, align 1, !tbaa !9
  %9 = sext i8 %8 to i32
  %10 = icmp eq i32 %9, 78
  br i1 %10, label %11, label %18

11:                                               ; preds = %3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = load i64, ptr %12, align 8, !tbaa !10
  %14 = sub nsw i64 %13, 1
  %15 = load i64, ptr @bound, align 8, !tbaa !10
  %16 = call noundef i64 @_Z3modxx(i64 noundef %14, i64 noundef %15)
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 %16, ptr %17, align 8, !tbaa !10
  br label %18

18:                                               ; preds = %11, %3
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = sext i8 %20 to i32
  %22 = icmp eq i32 %21, 83
  br i1 %22, label %23, label %30

23:                                               ; preds = %18
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load i64, ptr %24, align 8, !tbaa !10
  %26 = add nsw i64 %25, 1
  %27 = load i64, ptr @bound, align 8, !tbaa !10
  %28 = call noundef i64 @_Z3modxx(i64 noundef %26, i64 noundef %27)
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 %28, ptr %29, align 8, !tbaa !10
  br label %30

30:                                               ; preds = %23, %18
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 69
  br i1 %34, label %35, label %42

35:                                               ; preds = %30
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i64, ptr %36, align 8, !tbaa !10
  %38 = add nsw i64 %37, 1
  %39 = load i64, ptr @bound, align 8, !tbaa !10
  %40 = call noundef i64 @_Z3modxx(i64 noundef %38, i64 noundef %39)
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %40, ptr %41, align 8, !tbaa !10
  br label %42

42:                                               ; preds = %35, %30
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = sext i8 %44 to i32
  %46 = icmp eq i32 %45, 87
  br i1 %46, label %47, label %54

47:                                               ; preds = %42
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load i64, ptr %48, align 8, !tbaa !10
  %50 = sub nsw i64 %49, 1
  %51 = load i64, ptr @bound, align 8, !tbaa !10
  %52 = call noundef i64 @_Z3modxx(i64 noundef %50, i64 noundef %51)
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %52, ptr %53, align 8, !tbaa !10
  br label %54

54:                                               ; preds = %47, %42
  ret void
}

attributes #0 = { mustprogress 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" }

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

@bound = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3modxx(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3runRKcRxS1_(ptr nocapture noundef nonnull readonly align 1 dereferenceable(1) %0, ptr nocapture noundef nonnull align 8 dereferenceable(8) %1, ptr nocapture noundef nonnull align 8 dereferenceable(8) %2) local_unnamed_addr #0 {
  %4 = load i8, ptr %0, align 1, !tbaa !5
  %5 = icmp eq i8 %4, 78
  br i1 %5, label %6, label %11

6:                                                ; preds = %3
  %7 = load i64, ptr %2, align 8, !tbaa !8
  %8 = add nsw i64 %7, -1
  %9 = load i64, ptr @bound, align 8, !tbaa !8
  %10 = tail call noundef i64 @_Z3modxx(i64 noundef %8, i64 noundef %9)
  store i64 %10, ptr %2, align 8, !tbaa !8
  %.pr = load i8, ptr %0, align 1, !tbaa !5
  br label %11

11:                                               ; preds = %6, %3
  %12 = phi i8 [ %.pr, %6 ], [ %4, %3 ]
  %13 = icmp eq i8 %12, 83
  br i1 %13, label %14, label %19

14:                                               ; preds = %11
  %15 = load i64, ptr %2, align 8, !tbaa !8
  %16 = add nsw i64 %15, 1
  %17 = load i64, ptr @bound, align 8, !tbaa !8
  %18 = tail call noundef i64 @_Z3modxx(i64 noundef %16, i64 noundef %17)
  store i64 %18, ptr %2, align 8, !tbaa !8
  %.pre = load i8, ptr %0, align 1, !tbaa !5
  br label %19

19:                                               ; preds = %14, %11
  %20 = phi i8 [ %.pre, %14 ], [ %12, %11 ]
  %21 = icmp eq i8 %20, 69
  br i1 %21, label %22, label %27

22:                                               ; preds = %19
  %23 = load i64, ptr %1, align 8, !tbaa !8
  %24 = add nsw i64 %23, 1
  %25 = load i64, ptr @bound, align 8, !tbaa !8
  %26 = tail call noundef i64 @_Z3modxx(i64 noundef %24, i64 noundef %25)
  store i64 %26, ptr %1, align 8, !tbaa !8
  %.pr12 = load i8, ptr %0, align 1, !tbaa !5
  br label %27

27:                                               ; preds = %22, %19
  %28 = phi i8 [ %.pr12, %22 ], [ %20, %19 ]
  %29 = icmp eq i8 %28, 87
  br i1 %29, label %30, label %35

30:                                               ; preds = %27
  %31 = load i64, ptr %1, align 8, !tbaa !8
  %32 = add nsw i64 %31, -1
  %33 = load i64, ptr @bound, align 8, !tbaa !8
  %34 = tail call noundef i64 @_Z3modxx(i64 noundef %32, i64 noundef %33)
  store i64 %34, ptr %1, align 8, !tbaa !8
  br label %35

35:                                               ; preds = %30, %27
  ret void
}

attributes #0 = { mustprogress 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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !6, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass