; LLVM IR from tangjz/acm-icpc :: luogu (1079)

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

@cipher = external dso_local global [1024 x i8], align 16
@key = external dso_local global [128 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @key, ptr noundef @cipher)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %5 = call i64 @strlen(ptr noundef @key) #5
  %6 = trunc i64 %5 to i32
  store i32 %6, ptr %3, align 4, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %37, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [128 x i8], ptr @key, i64 0, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = icmp ne i8 %11, 0
  br i1 %12, label %13, label %40

13:                                               ; preds = %7
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [128 x i8], ptr @key, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = icmp sge i32 %18, 97
  br i1 %19, label %20, label %28

20:                                               ; preds = %13
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [128 x i8], ptr @key, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = sext i8 %24 to i32
  %26 = sub nsw i32 %25, 97
  %27 = trunc i32 %26 to i8
  store i8 %27, ptr %23, align 1, !tbaa !9
  br label %36

28:                                               ; preds = %13
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [128 x i8], ptr @key, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = sub nsw i32 %33, 65
  %35 = trunc i32 %34 to i8
  store i8 %35, ptr %31, align 1, !tbaa !9
  br label %36

36:                                               ; preds = %28, %20
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !10

40:                                               ; preds = %7
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %99, %40
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1024 x i8], ptr @cipher, i64 0, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !9
  %46 = icmp ne i8 %45, 0
  br i1 %46, label %47, label %102

47:                                               ; preds = %41
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1024 x i8], ptr @cipher, i64 0, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !9
  %52 = sext i8 %51 to i32
  %53 = icmp sge i32 %52, 97
  br i1 %53, label %54, label %76

54:                                               ; preds = %47
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1024 x i8], ptr @cipher, i64 0, i64 %56
  %58 = load i8, ptr %57, align 1, !tbaa !9
  %59 = sext i8 %58 to i32
  %60 = sub nsw i32 %59, 97
  %61 = load i32, ptr %2, align 4, !tbaa !5
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = srem i32 %61, %62
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [128 x i8], ptr @key, i64 0, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !9
  %67 = sext i8 %66 to i32
  %68 = sub nsw i32 %60, %67
  %69 = add nsw i32 %68, 26
  %70 = srem i32 %69, 26
  %71 = add nsw i32 %70, 97
  %72 = trunc i32 %71 to i8
  %73 = load i32, ptr %2, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [1024 x i8], ptr @cipher, i64 0, i64 %74
  store i8 %72, ptr %75, align 1, !tbaa !9
  br label %98

76:                                               ; preds = %47
  %77 = load i32, ptr %2, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [1024 x i8], ptr @cipher, i64 0, i64 %78
  %80 = load i8, ptr %79, align 1, !tbaa !9
  %81 = sext i8 %80 to i32
  %82 = sub nsw i32 %81, 65
  %83 = load i32, ptr %2, align 4, !tbaa !5
  %84 = load i32, ptr %3, align 4, !tbaa !5
  %85 = srem i32 %83, %84
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [128 x i8], ptr @key, i64 0, i64 %86
  %88 = load i8, ptr %87, align 1, !tbaa !9
  %89 = sext i8 %88 to i32
  %90 = sub nsw i32 %82, %89
  %91 = add nsw i32 %90, 26
  %92 = srem i32 %91, 26
  %93 = add nsw i32 %92, 65
  %94 = trunc i32 %93 to i8
  %95 = load i32, ptr %2, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [1024 x i8], ptr @cipher, i64 0, i64 %96
  store i8 %94, ptr %97, align 1, !tbaa !9
  br label %98

98:                                               ; preds = %76, %54
  br label %99

99:                                               ; preds = %98
  %100 = load i32, ptr %2, align 4, !tbaa !5
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %2, align 4, !tbaa !5
  br label %41, !llvm.loop !12

102:                                              ; preds = %41
  %103 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, ptr noundef @cipher)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %104 = load i32, ptr %1, align 4
  ret i32 %104
}

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

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

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

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

attributes #0 = { mustprogress norecurse 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

@cipher = external dso_local global [1024 x i8], align 16
@key = external dso_local global [128 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @key, ptr noundef nonnull @cipher)
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @key) #3
  %3 = trunc i64 %2 to i32
  %4 = load i8, ptr @key, align 16, !tbaa !5
  %.not28 = icmp eq i8 %4, 0
  br i1 %.not28, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %0
  %5 = load i8, ptr @cipher, align 16, !tbaa !5
  %.not2330 = icmp eq i8 %5, 0
  br i1 %.not2330, label %._crit_edge, label %.lr.ph32

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %6 = phi i8 [ %10, %.lr.ph ], [ %4, %0 ]
  %7 = phi ptr [ %9, %.lr.ph ], [ @key, %0 ]
  %8 = icmp sgt i8 %6, 96
  %storemerge24.v = select i1 %8, i8 -97, i8 -65
  %storemerge24 = add i8 %storemerge24.v, %6
  store i8 %storemerge24, ptr %7, align 1, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %9 = getelementptr inbounds [128 x i8], ptr @key, i64 0, i64 %indvars.iv.next
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %.not = icmp eq i8 %10, 0
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !8

.lr.ph32:                                         ; preds = %.preheader, %.lr.ph32
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %.lr.ph32 ], [ 0, %.preheader ]
  %11 = phi i8 [ %27, %.lr.ph32 ], [ %5, %.preheader ]
  %12 = phi ptr [ %26, %.lr.ph32 ], [ @cipher, %.preheader ]
  %13 = sext i8 %11 to i16
  %14 = icmp sgt i8 %11, 96
  %15 = trunc nuw nsw i64 %indvars.iv33 to i32
  %16 = srem i32 %15, %3
  %17 = zext nneg i32 %16 to i64
  %18 = getelementptr inbounds [128 x i8], ptr @key, i64 0, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = sext i8 %19 to i16
  %. = select i1 %14, i16 -97, i16 -65
  %.39 = select i1 %14, i8 97, i8 65
  %21 = add nsw i16 %., %13
  %22 = sub nsw i16 %21, %20
  %.lhs.trunc = add nsw i16 %22, 26
  %23 = srem i16 %.lhs.trunc, 26
  %24 = trunc nsw i16 %23 to i8
  %25 = add nsw i8 %.39, %24
  store i8 %25, ptr %12, align 1, !tbaa !5
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %26 = getelementptr inbounds [1024 x i8], ptr @cipher, i64 0, i64 %indvars.iv.next34
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %.not23 = icmp eq i8 %27, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph32, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph32, %.preheader
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef nonnull @cipher)
  ret i32 0
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nofree norecurse 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 = { 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 = { mustprogress nofree nounwind willreturn memory(argmem: 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 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass