; LLVM IR from stamparm/cryptospecs :: symmetrical/sources (scop)

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

%struct.st_key = type { [384 x i64], i8, i8, i8 }

; 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: nounwind uwtable
define dso_local void @decrypt(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.st_key, ptr %16, i32 0, i32 1
  %18 = load i8, ptr %17, align 8, !tbaa !11
  store i8 %18, ptr %7, align 1, !tbaa !13
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.st_key, ptr %19, i32 0, i32 2
  %21 = load i8, ptr %20, align 1, !tbaa !14
  store i8 %21, ptr %8, align 1, !tbaa !13
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.st_key, ptr %22, i32 0, i32 3
  %24 = load i8, ptr %23, align 2, !tbaa !15
  %25 = zext i8 %24 to i64
  store i64 %25, ptr %11, align 8, !tbaa !16
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.st_key, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds [384 x i64], ptr %27, i64 0, i64 0
  store ptr %28, ptr %15, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %29, ptr %14, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %37, %3
  %31 = load ptr, ptr %14, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i64, ptr %32, i64 %34
  %36 = icmp ult ptr %31, %35
  br i1 %36, label %37, label %87

37:                                               ; preds = %30
  %38 = load ptr, ptr %15, align 8, !tbaa !5
  %39 = load i8, ptr %8, align 1, !tbaa !13
  %40 = zext i8 %39 to i32
  %41 = add nsw i32 128, %40
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i64, ptr %38, i64 %42
  %44 = load i64, ptr %43, align 8, !tbaa !16
  store i64 %44, ptr %9, align 8, !tbaa !16
  %45 = load i64, ptr %11, align 8, !tbaa !16
  %46 = load i8, ptr %8, align 1, !tbaa !13
  %47 = zext i8 %46 to i64
  %48 = add i64 %47, %45
  %49 = trunc i64 %48 to i8
  store i8 %49, ptr %8, align 1, !tbaa !13
  %50 = load ptr, ptr %15, align 8, !tbaa !5
  %51 = load i8, ptr %7, align 1, !tbaa !13
  %52 = zext i8 %51 to i64
  %53 = getelementptr inbounds i64, ptr %50, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !16
  store i64 %54, ptr %13, align 8, !tbaa !16
  %55 = load ptr, ptr %15, align 8, !tbaa !5
  %56 = load i8, ptr %8, align 1, !tbaa !13
  %57 = zext i8 %56 to i32
  %58 = add nsw i32 128, %57
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i64, ptr %55, i64 %59
  %61 = load i64, ptr %60, align 8, !tbaa !16
  store i64 %61, ptr %10, align 8, !tbaa !16
  %62 = load i8, ptr %7, align 1, !tbaa !13
  %63 = add i8 %62, 1
  store i8 %63, ptr %7, align 1, !tbaa !13
  %64 = load i64, ptr %10, align 8, !tbaa !16
  %65 = load i64, ptr %13, align 8, !tbaa !16
  %66 = add i64 %64, %65
  store i64 %66, ptr %11, align 8, !tbaa !16
  %67 = load i64, ptr %11, align 8, !tbaa !16
  %68 = load ptr, ptr %15, align 8, !tbaa !5
  %69 = load i8, ptr %8, align 1, !tbaa !13
  %70 = zext i8 %69 to i32
  %71 = add nsw i32 128, %70
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i64, ptr %68, i64 %72
  store i64 %67, ptr %73, align 8, !tbaa !16
  %74 = load i64, ptr %10, align 8, !tbaa !16
  %75 = load i8, ptr %8, align 1, !tbaa !13
  %76 = zext i8 %75 to i64
  %77 = add i64 %76, %74
  %78 = trunc i64 %77 to i8
  store i8 %78, ptr %8, align 1, !tbaa !13
  %79 = load i64, ptr %9, align 8, !tbaa !16
  %80 = load i64, ptr %10, align 8, !tbaa !16
  %81 = add i64 %79, %80
  store i64 %81, ptr %12, align 8, !tbaa !16
  %82 = load i64, ptr %12, align 8, !tbaa !16
  %83 = load ptr, ptr %14, align 8, !tbaa !5
  %84 = getelementptr inbounds i64, ptr %83, i32 1
  store ptr %84, ptr %14, align 8, !tbaa !5
  %85 = load i64, ptr %83, align 8, !tbaa !16
  %86 = sub i64 %85, %82
  store i64 %86, ptr %83, align 8, !tbaa !16
  br label %30, !llvm.loop !18

87:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 3072}
!12 = !{!"", !7, i64 0, !7, i64 3072, !7, i64 3073, !7, i64 3074}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !7, i64 3073}
!15 = !{!12, !7, i64 3074}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @decrypt(ptr noundef %0, i32 noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %1 to i64
  %5 = getelementptr inbounds i64, ptr %0, i64 %4
  %invariant.gep = getelementptr inbounds i8, ptr %2, i64 1024
  %6 = icmp sgt i32 %1, 0
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %7 = getelementptr inbounds i8, ptr %2, i64 3074
  %8 = load i8, ptr %7, align 2, !tbaa !5
  %9 = zext i8 %8 to i64
  %10 = getelementptr inbounds i8, ptr %2, i64 3073
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %2, i64 3072
  %13 = load i8, ptr %12, align 8, !tbaa !10
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.037 = phi i8 [ %23, %.lr.ph ], [ %13, %.lr.ph.preheader ]
  %.02736 = phi ptr [ %27, %.lr.ph ], [ %0, %.lr.ph.preheader ]
  %.02835 = phi i8 [ %26, %.lr.ph ], [ %11, %.lr.ph.preheader ]
  %.02934 = phi i64 [ %24, %.lr.ph ], [ %9, %.lr.ph.preheader ]
  %14 = zext i8 %.02835 to i64
  %gep = getelementptr inbounds i64, ptr %invariant.gep, i64 %14
  %15 = load i64, ptr %gep, align 8, !tbaa !11
  %16 = trunc i64 %.02934 to i8
  %17 = add i8 %.02835, %16
  %18 = zext i8 %.037 to i64
  %19 = getelementptr inbounds i64, ptr %2, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = zext i8 %17 to i64
  %gep33 = getelementptr inbounds i64, ptr %invariant.gep, i64 %21
  %22 = load i64, ptr %gep33, align 8, !tbaa !11
  %23 = add i8 %.037, 1
  %24 = add i64 %22, %20
  store i64 %24, ptr %gep33, align 8, !tbaa !11
  %25 = trunc i64 %22 to i8
  %26 = add i8 %17, %25
  %27 = getelementptr inbounds i8, ptr %.02736, i64 8
  %28 = load i64, ptr %.02736, align 8, !tbaa !11
  %29 = add i64 %22, %15
  %30 = sub i64 %28, %29
  store i64 %30, ptr %.02736, align 8, !tbaa !11
  %31 = icmp ult ptr %27, %5
  br i1 %31, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %3
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !7, i64 3074}
!6 = !{!"", !7, i64 0, !7, i64 3072, !7, i64 3073, !7, i64 3074}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!6, !7, i64 3073}
!10 = !{!6, !7, i64 3072}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass