; LLVM IR from tangjz/acm-icpc :: usaco/Training/Chapter 1 Getting started/crypt1.ll (Z3dfsi)

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

@used = external dso_local global [10 x i32], align 16
@num = external dso_local global [6 x i32], align 16
@ans = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5checkv() #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsi(i32 noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 5
  br i1 %5, label %6, label %12

6:                                                ; preds = %1
  %7 = call noundef zeroext i1 @_Z5checkv()
  br i1 %7, label %8, label %11

8:                                                ; preds = %6
  %9 = load i32, ptr @ans, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr @ans, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %8, %6
  br label %34

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %31, %12
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = icmp sle i32 %14, 9
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %34

17:                                               ; preds = %13
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [10 x i32], ptr @used, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %30

23:                                               ; preds = %17
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [6 x i32], ptr @num, i64 0, i64 %26
  store i32 %24, ptr %27, align 4, !tbaa !5
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  call void @_Z3dfsi(i32 noundef %29)
  br label %30

30:                                               ; preds = %23, %17
  br label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %3, align 4, !tbaa !5
  br label %13, !llvm.loop !9

34:                                               ; preds = %16, %11
  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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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"}


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

@used = external dso_local local_unnamed_addr global [10 x i32], align 16
@num = external dso_local local_unnamed_addr global [6 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5checkv() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsi(i32 noundef %0) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %36, %1
  %.tr = phi i32 [ %0, %1 ], [ %5, %36 ]
  %2 = icmp eq i32 %.tr, 5
  br i1 %2, label %7, label %.preheader

.preheader:                                       ; preds = %tailrecurse
  %3 = sext i32 %.tr to i64
  %4 = getelementptr inbounds [6 x i32], ptr @num, i64 0, i64 %3
  %5 = add nsw i32 %.tr, 1
  %6 = load i32, ptr getelementptr inbounds (i8, ptr @used, i64 4), align 4, !tbaa !5
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %13, label %12

7:                                                ; preds = %tailrecurse
  %8 = tail call noundef zeroext i1 @_Z5checkv()
  br i1 %8, label %9, label %.loopexit

9:                                                ; preds = %7
  %10 = load i32, ptr @ans, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @ans, align 4, !tbaa !5
  br label %.loopexit

12:                                               ; preds = %.preheader
  store i32 1, ptr %4, align 4, !tbaa !5
  tail call void @_Z3dfsi(i32 noundef %5)
  br label %13

13:                                               ; preds = %.preheader, %12
  %14 = load i32, ptr getelementptr inbounds (i8, ptr @used, i64 8), align 8, !tbaa !5
  %.not.1 = icmp eq i32 %14, 0
  br i1 %.not.1, label %16, label %15

15:                                               ; preds = %13
  store i32 2, ptr %4, align 4, !tbaa !5
  tail call void @_Z3dfsi(i32 noundef %5)
  br label %16

16:                                               ; preds = %15, %13
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @used, i64 12), align 4, !tbaa !5
  %.not.2 = icmp eq i32 %17, 0
  br i1 %.not.2, label %19, label %18

18:                                               ; preds = %16
  store i32 3, ptr %4, align 4, !tbaa !5
  tail call void @_Z3dfsi(i32 noundef %5)
  br label %19

19:                                               ; preds = %18, %16
  %20 = load i32, ptr getelementptr inbounds (i8, ptr @used, i64 16), align 16, !tbaa !5
  %.not.3 = icmp eq i32 %20, 0
  br i1 %.not.3, label %22, label %21

21:                                               ; preds = %19
  store i32 4, ptr %4, align 4, !tbaa !5
  tail call void @_Z3dfsi(i32 noundef %5)
  br label %22

22:                                               ; preds = %21, %19
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @used, i64 20), align 4, !tbaa !5
  %.not.4 = icmp eq i32 %23, 0
  br i1 %.not.4, label %25, label %24

24:                                               ; preds = %22
  store i32 5, ptr %4, align 4, !tbaa !5
  tail call void @_Z3dfsi(i32 noundef %5)
  br label %25

25:                                               ; preds = %24, %22
  %26 = load i32, ptr getelementptr inbounds (i8, ptr @used, i64 24), align 8, !tbaa !5
  %.not.5 = icmp eq i32 %26, 0
  br i1 %.not.5, label %28, label %27

27:                                               ; preds = %25
  store i32 6, ptr %4, align 4, !tbaa !5
  tail call void @_Z3dfsi(i32 noundef %5)
  br label %28

28:                                               ; preds = %27, %25
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @used, i64 28), align 4, !tbaa !5
  %.not.6 = icmp eq i32 %29, 0
  br i1 %.not.6, label %31, label %30

30:                                               ; preds = %28
  store i32 7, ptr %4, align 4, !tbaa !5
  tail call void @_Z3dfsi(i32 noundef %5)
  br label %31

31:                                               ; preds = %30, %28
  %32 = load i32, ptr getelementptr inbounds (i8, ptr @used, i64 32), align 16, !tbaa !5
  %.not.7 = icmp eq i32 %32, 0
  br i1 %.not.7, label %34, label %33

33:                                               ; preds = %31
  store i32 8, ptr %4, align 4, !tbaa !5
  tail call void @_Z3dfsi(i32 noundef %5)
  br label %34

34:                                               ; preds = %33, %31
  %35 = load i32, ptr getelementptr inbounds (i8, ptr @used, i64 36), align 4, !tbaa !5
  %.not.8 = icmp eq i32 %35, 0
  br i1 %.not.8, label %.loopexit, label %36

36:                                               ; preds = %34
  store i32 9, ptr %4, align 4, !tbaa !5
  br label %tailrecurse

.loopexit:                                        ; preds = %34, %7, %9
  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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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