; LLVM IR from vergecurrency/verge :: src/crypto/hmac_sha256.ll (ZN12CHMAC_SHA256C2EPKhm)

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

%class.CSHA256 = type { [8 x i32], [64 x i8], i64 }
%class.CHMAC_SHA256 = type { %class.CSHA256, %class.CSHA256 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12CHMAC_SHA256C2EPKhm(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca [64 x i8], align 16
  %8 = alloca %class.CSHA256, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %11 = load ptr, ptr %4, align 8
  %12 = getelementptr inbounds %class.CHMAC_SHA256, ptr %11, i32 0, i32 0
  call void @_ZN7CSHA256C1Ev(ptr noundef nonnull align 8 dereferenceable(104) %12)
  %13 = getelementptr inbounds %class.CHMAC_SHA256, ptr %11, i32 0, i32 1
  call void @_ZN7CSHA256C1Ev(ptr noundef nonnull align 8 dereferenceable(104) %13)
  call void @llvm.lifetime.start.p0(i64 64, ptr %7) #5
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = icmp ule i64 %14, 64
  br i1 %15, label %16, label %25

16:                                               ; preds = %3
  %17 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %17, ptr align 1 %18, i64 %19, i1 false)
  %20 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %20, i64 %21
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = sub i64 64, %23
  call void @llvm.memset.p0.i64(ptr align 1 %22, i8 0, i64 %24, i1 false)
  br label %32

25:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 104, ptr %8) #5
  call void @_ZN7CSHA256C1Ev(ptr noundef nonnull align 8 dereferenceable(104) %8)
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = call noundef nonnull align 8 dereferenceable(104) ptr @_ZN7CSHA2565WriteEPKhm(ptr noundef nonnull align 8 dereferenceable(104) %8, ptr noundef %26, i64 noundef %27)
  %29 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  call void @_ZN7CSHA2568FinalizeEPh(ptr noundef nonnull align 8 dereferenceable(104) %28, ptr noundef %29)
  call void @llvm.lifetime.end.p0(i64 104, ptr %8) #5
  %30 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %31 = getelementptr inbounds i8, ptr %30, i64 32
  call void @llvm.memset.p0.i64(ptr align 1 %31, i8 0, i64 32, i1 false)
  br label %32

32:                                               ; preds = %25, %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %33

33:                                               ; preds = %45, %32
  %34 = load i32, ptr %9, align 4, !tbaa !11
  %35 = icmp slt i32 %34, 64
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %48

37:                                               ; preds = %33
  %38 = load i32, ptr %9, align 4, !tbaa !11
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !13
  %42 = zext i8 %41 to i32
  %43 = xor i32 %42, 92
  %44 = trunc i32 %43 to i8
  store i8 %44, ptr %40, align 1, !tbaa !13
  br label %45

45:                                               ; preds = %37
  %46 = load i32, ptr %9, align 4, !tbaa !11
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %9, align 4, !tbaa !11
  br label %33, !llvm.loop !14

48:                                               ; preds = %36
  %49 = getelementptr inbounds %class.CHMAC_SHA256, ptr %11, i32 0, i32 0
  %50 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %51 = call noundef nonnull align 8 dereferenceable(104) ptr @_ZN7CSHA2565WriteEPKhm(ptr noundef nonnull align 8 dereferenceable(104) %49, ptr noundef %50, i64 noundef 64)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %52

52:                                               ; preds = %64, %48
  %53 = load i32, ptr %10, align 4, !tbaa !11
  %54 = icmp slt i32 %53, 64
  br i1 %54, label %56, label %55

55:                                               ; preds = %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %67

56:                                               ; preds = %52
  %57 = load i32, ptr %10, align 4, !tbaa !11
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 %58
  %60 = load i8, ptr %59, align 1, !tbaa !13
  %61 = zext i8 %60 to i32
  %62 = xor i32 %61, 106
  %63 = trunc i32 %62 to i8
  store i8 %63, ptr %59, align 1, !tbaa !13
  br label %64

64:                                               ; preds = %56
  %65 = load i32, ptr %10, align 4, !tbaa !11
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %10, align 4, !tbaa !11
  br label %52, !llvm.loop !16

67:                                               ; preds = %55
  %68 = getelementptr inbounds %class.CHMAC_SHA256, ptr %11, i32 0, i32 1
  %69 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %70 = call noundef nonnull align 8 dereferenceable(104) ptr @_ZN7CSHA2565WriteEPKhm(ptr noundef nonnull align 8 dereferenceable(104) %68, ptr noundef %69, i64 noundef 64)
  call void @llvm.lifetime.end.p0(i64 64, ptr %7) #5
  ret void
}

declare void @_ZN7CSHA256C1Ev(ptr noundef nonnull align 8 dereferenceable(104)) unnamed_addr #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

declare noundef nonnull align 8 dereferenceable(104) ptr @_ZN7CSHA2565WriteEPKhm(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef, i64 noundef) #1

declare void @_ZN7CSHA2568FinalizeEPh(ptr noundef nonnull align 8 dereferenceable(104), 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 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

%class.CSHA256 = type { [8 x i32], [64 x i8], i64 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12CHMAC_SHA256C2EPKhm(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr noundef %1, i64 noundef %2) unnamed_addr #0 align 2 {
  %4 = alloca [64 x i8], align 16
  %5 = alloca %class.CSHA256, align 8
  tail call void @_ZN7CSHA256C1Ev(ptr noundef nonnull align 8 dereferenceable(104) %0)
  %6 = getelementptr inbounds i8, ptr %0, i64 104
  tail call void @_ZN7CSHA256C1Ev(ptr noundef nonnull align 8 dereferenceable(104) %6)
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #5
  %7 = icmp ult i64 %2, 65
  br i1 %7, label %8, label %11

8:                                                ; preds = %3
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %4, ptr align 1 %1, i64 %2, i1 false)
  %9 = getelementptr inbounds i8, ptr %4, i64 %2
  %10 = sub nuw nsw i64 64, %2
  call void @llvm.memset.p0.i64(ptr nonnull align 1 %9, i8 0, i64 %10, i1 false)
  br label %vector.body

11:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %5) #5
  call void @_ZN7CSHA256C1Ev(ptr noundef nonnull align 8 dereferenceable(104) %5)
  %12 = call noundef nonnull align 8 dereferenceable(104) ptr @_ZN7CSHA2565WriteEPKhm(ptr noundef nonnull align 8 dereferenceable(104) %5, ptr noundef %1, i64 noundef %2)
  call void @_ZN7CSHA2568FinalizeEPh(ptr noundef nonnull align 8 dereferenceable(104) %12, ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %5) #5
  %13 = getelementptr inbounds i8, ptr %4, i64 32
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %13, i8 0, i64 32, i1 false)
  br label %vector.body

vector.body:                                      ; preds = %11, %8
  %14 = getelementptr inbounds i8, ptr %4, i64 16
  %wide.load = load <16 x i8>, ptr %4, align 16, !tbaa !5
  %wide.load22 = load <16 x i8>, ptr %14, align 16, !tbaa !5
  %15 = xor <16 x i8> %wide.load, <i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92>
  %16 = xor <16 x i8> %wide.load22, <i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92>
  store <16 x i8> %15, ptr %4, align 16, !tbaa !5
  store <16 x i8> %16, ptr %14, align 16, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %4, i64 32
  %18 = getelementptr inbounds i8, ptr %4, i64 48
  %wide.load.1 = load <16 x i8>, ptr %17, align 16, !tbaa !5
  %wide.load22.1 = load <16 x i8>, ptr %18, align 16, !tbaa !5
  %19 = xor <16 x i8> %wide.load.1, <i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92>
  %20 = xor <16 x i8> %wide.load22.1, <i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92, i8 92>
  store <16 x i8> %19, ptr %17, align 16, !tbaa !5
  store <16 x i8> %20, ptr %18, align 16, !tbaa !5
  %21 = call noundef nonnull align 8 dereferenceable(104) ptr @_ZN7CSHA2565WriteEPKhm(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull %4, i64 noundef 64)
  %22 = getelementptr inbounds i8, ptr %4, i64 16
  %wide.load29 = load <16 x i8>, ptr %4, align 16, !tbaa !5
  %wide.load30 = load <16 x i8>, ptr %22, align 16, !tbaa !5
  %23 = xor <16 x i8> %wide.load29, <i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106>
  %24 = xor <16 x i8> %wide.load30, <i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106>
  store <16 x i8> %23, ptr %4, align 16, !tbaa !5
  store <16 x i8> %24, ptr %22, align 16, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %4, i64 32
  %26 = getelementptr inbounds i8, ptr %4, i64 48
  %wide.load29.1 = load <16 x i8>, ptr %25, align 16, !tbaa !5
  %wide.load30.1 = load <16 x i8>, ptr %26, align 16, !tbaa !5
  %27 = xor <16 x i8> %wide.load29.1, <i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106>
  %28 = xor <16 x i8> %wide.load30.1, <i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106, i8 106>
  store <16 x i8> %27, ptr %25, align 16, !tbaa !5
  store <16 x i8> %28, ptr %26, align 16, !tbaa !5
  %29 = call noundef nonnull align 8 dereferenceable(104) ptr @_ZN7CSHA2565WriteEPKhm(ptr noundef nonnull align 8 dereferenceable(104) %6, ptr noundef nonnull %4, i64 noundef 64)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #5
  ret void
}

declare void @_ZN7CSHA256C1Ev(ptr noundef nonnull align 8 dereferenceable(104)) unnamed_addr #1

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

declare noundef nonnull align 8 dereferenceable(104) ptr @_ZN7CSHA2565WriteEPKhm(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef, i64 noundef) local_unnamed_addr #1

declare void @_ZN7CSHA2568FinalizeEPh(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef) local_unnamed_addr #1

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

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass