; LLVM IR from HarshCasper/NeoAlgo :: C/cryptography (caesar_cipher)

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

@count = external dso_local global i32, align 4
@data = external dso_local global [50 x i8], align 16
@temp = external dso_local global i8, align 1
@key = external dso_local global i32, align 4
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @decryption() #1 {
  store i32 0, ptr @count, align 4, !tbaa !5
  br label %1

1:                                                ; preds = %72, %0
  %2 = load i32, ptr @count, align 4, !tbaa !5
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds [50 x i8], ptr @data, i64 0, i64 %3
  %5 = load i8, ptr %4, align 1, !tbaa !9
  %6 = sext i8 %5 to i32
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %8, label %75

8:                                                ; preds = %1
  %9 = load i32, ptr @count, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [50 x i8], ptr @data, i64 0, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !9
  store i8 %12, ptr @temp, align 1, !tbaa !9
  %13 = load i8, ptr @temp, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = icmp sge i32 %14, 97
  br i1 %15, label %16, label %41

16:                                               ; preds = %8
  %17 = load i8, ptr @temp, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = icmp sle i32 %18, 122
  br i1 %19, label %20, label %41

20:                                               ; preds = %16
  %21 = load i8, ptr @temp, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = load i32, ptr @key, align 4, !tbaa !5
  %24 = sub nsw i32 %22, %23
  %25 = trunc i32 %24 to i8
  store i8 %25, ptr @temp, align 1, !tbaa !9
  %26 = load i8, ptr @temp, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = icmp slt i32 %27, 97
  br i1 %28, label %29, label %36

29:                                               ; preds = %20
  %30 = load i8, ptr @temp, align 1, !tbaa !9
  %31 = sext i8 %30 to i32
  %32 = add nsw i32 %31, 122
  %33 = sub nsw i32 %32, 97
  %34 = add nsw i32 %33, 1
  %35 = trunc i32 %34 to i8
  store i8 %35, ptr @temp, align 1, !tbaa !9
  br label %36

36:                                               ; preds = %29, %20
  %37 = load i8, ptr @temp, align 1, !tbaa !9
  %38 = load i32, ptr @count, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [50 x i8], ptr @data, i64 0, i64 %39
  store i8 %37, ptr %40, align 1, !tbaa !9
  br label %71

41:                                               ; preds = %16, %8
  %42 = load i8, ptr @temp, align 1, !tbaa !9
  %43 = sext i8 %42 to i32
  %44 = icmp sge i32 %43, 65
  br i1 %44, label %45, label %70

45:                                               ; preds = %41
  %46 = load i8, ptr @temp, align 1, !tbaa !9
  %47 = sext i8 %46 to i32
  %48 = icmp sle i32 %47, 90
  br i1 %48, label %49, label %70

49:                                               ; preds = %45
  %50 = load i8, ptr @temp, align 1, !tbaa !9
  %51 = sext i8 %50 to i32
  %52 = load i32, ptr @key, align 4, !tbaa !5
  %53 = sub nsw i32 %51, %52
  %54 = trunc i32 %53 to i8
  store i8 %54, ptr @temp, align 1, !tbaa !9
  %55 = load i8, ptr @temp, align 1, !tbaa !9
  %56 = sext i8 %55 to i32
  %57 = icmp slt i32 %56, 65
  br i1 %57, label %58, label %65

58:                                               ; preds = %49
  %59 = load i8, ptr @temp, align 1, !tbaa !9
  %60 = sext i8 %59 to i32
  %61 = add nsw i32 %60, 90
  %62 = sub nsw i32 %61, 65
  %63 = add nsw i32 %62, 1
  %64 = trunc i32 %63 to i8
  store i8 %64, ptr @temp, align 1, !tbaa !9
  br label %65

65:                                               ; preds = %58, %49
  %66 = load i8, ptr @temp, align 1, !tbaa !9
  %67 = load i32, ptr @count, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [50 x i8], ptr @data, i64 0, i64 %68
  store i8 %66, ptr %69, align 1, !tbaa !9
  br label %70

70:                                               ; preds = %65, %45, %41
  br label %71

71:                                               ; preds = %70, %36
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr @count, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr @count, align 4, !tbaa !5
  br label %1, !llvm.loop !10

75:                                               ; preds = %1
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef @data)
  ret void
}

attributes #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 = { 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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

@count = external dso_local local_unnamed_addr global i32, align 4
@data = external dso_local global [50 x i8], align 16
@temp = external dso_local local_unnamed_addr global i8, align 1
@key = external dso_local local_unnamed_addr global i32, align 4
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local void @decryption() local_unnamed_addr #1 {
  %1 = load i8, ptr @data, align 16, !tbaa !5
  %.not11 = icmp eq i8 %1, 0
  br i1 %.not11, label %17, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %2 = load i32, ptr @key, align 4
  %3 = trunc i32 %2 to i8
  br label %4

4:                                                ; preds = %.lr.ph, %13
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %13 ]
  %5 = phi i8 [ %1, %.lr.ph ], [ %15, %13 ]
  %6 = phi ptr [ @data, %.lr.ph ], [ %14, %13 ]
  %7 = add i8 %5, -97
  %or.cond = icmp ult i8 %7, 26
  br i1 %or.cond, label %.sink.split, label %8

8:                                                ; preds = %4
  %9 = add i8 %5, -65
  %or.cond5 = icmp ult i8 %9, 26
  br i1 %or.cond5, label %.sink.split, label %13

.sink.split:                                      ; preds = %8, %4
  %.sink18 = phi i8 [ 97, %4 ], [ 65, %8 ]
  %10 = sub i8 %5, %3
  %11 = icmp slt i8 %10, %.sink18
  %12 = add i8 %10, 26
  %spec.select = select i1 %11, i8 %12, i8 %10
  store i8 %spec.select, ptr %6, align 1, !tbaa !5
  br label %13

13:                                               ; preds = %.sink.split, %8
  %spec.select13 = phi i8 [ %5, %8 ], [ %spec.select, %.sink.split ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = getelementptr inbounds [50 x i8], ptr @data, i64 0, i64 %indvars.iv.next
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %.not = icmp eq i8 %15, 0
  br i1 %.not, label %._crit_edge, label %4, !llvm.loop !8

._crit_edge:                                      ; preds = %13
  %16 = trunc nuw nsw i64 %indvars.iv.next to i32
  store i8 %spec.select13, ptr @temp, align 1, !tbaa !5
  br label %17

17:                                               ; preds = %._crit_edge, %0
  %storemerge.lcssa = phi i32 [ %16, %._crit_edge ], [ 0, %0 ]
  store i32 %storemerge.lcssa, ptr @count, align 4, !tbaa !10
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef nonnull @data)
  ret void
}

attributes #0 = { 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 #1 = { nofree 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/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SimplifyCFGPass,TailCallElimPass