; LLVM IR from Waqar144/simplecrypto-cxx :: simplecrypto-cxx/hmac.ll (Z16hmac_sha512_InitI10SHA512_CTXLm128EEvP8HMAC_CTXIT_XT0_EEPKhj)

; 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.HMAC_CTX.2 = type { %"struct.std::array.3", %struct.SHA512_CTX }
%"struct.std::array.3" = type { [128 x i8] }
%struct.SHA512_CTX = type { %"struct.std::array.4", %"struct.std::array.5", %"struct.std::array.6" }
%"struct.std::array.4" = type { [8 x i64] }
%"struct.std::array.5" = type { [2 x i64] }
%"struct.std::array.6" = type { [16 x i64] }

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; 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) #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z16hmac_sha512_InitI10SHA512_CTXLm128EEvP8HMAC_CTXIT_XT0_EEPKhj(ptr noundef %0, ptr noundef %1, i32 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca [128 x i8], align 16
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 128, ptr %7) #6
  %9 = getelementptr inbounds [128 x i8], ptr %7, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %9, i8 0, i64 128, i1 false)
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = zext i32 %10 to i64
  %12 = icmp ugt i64 %11, 128
  br i1 %12, label %13, label %18

13:                                               ; preds = %3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [128 x i8], ptr %7, i64 0, i64 0
  call void @_Z6sha512PKhmPh(ptr noundef %14, i64 noundef %16, ptr noundef %17)
  br label %23

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

23:                                               ; preds = %18, %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  store i64 0, ptr %8, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %45, %23
  %25 = load i64, ptr %8, align 8, !tbaa !11
  %26 = icmp ult i64 %25, 128
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %48

28:                                               ; preds = %24
  %29 = load i64, ptr %8, align 8, !tbaa !11
  %30 = getelementptr inbounds [128 x i8], ptr %7, i64 0, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !13
  %32 = zext i8 %31 to i32
  %33 = xor i32 %32, 92
  %34 = trunc i32 %33 to i8
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.HMAC_CTX.2, ptr %35, i32 0, i32 0
  %37 = load i64, ptr %8, align 8, !tbaa !11
  %38 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt5arrayIhLm128EEixEm(ptr noundef nonnull align 1 dereferenceable(128) %36, i64 noundef %37) #6
  store i8 %34, ptr %38, align 1, !tbaa !13
  %39 = load i64, ptr %8, align 8, !tbaa !11
  %40 = getelementptr inbounds [128 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, 54
  %44 = trunc i32 %43 to i8
  store i8 %44, ptr %40, align 1, !tbaa !13
  br label %45

45:                                               ; preds = %28
  %46 = load i64, ptr %8, align 8, !tbaa !11
  %47 = add i64 %46, 1
  store i64 %47, ptr %8, align 8, !tbaa !11
  br label %24, !llvm.loop !14

48:                                               ; preds = %27
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.HMAC_CTX.2, ptr %49, i32 0, i32 1
  call void @_Z11sha512_InitP10SHA512_CTX(ptr noundef %50)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.HMAC_CTX.2, ptr %51, i32 0, i32 1
  %53 = getelementptr inbounds [128 x i8], ptr %7, i64 0, i64 0
  call void @_Z13sha512_UpdateP10SHA512_CTXPKhm(ptr noundef %52, ptr noundef %53, i64 noundef 128)
  %54 = getelementptr inbounds [128 x i8], ptr %7, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %54, i8 0, i64 128, i1 false)
  call void @llvm.lifetime.end.p0(i64 128, ptr %7) #6
  ret void
}

declare void @_Z6sha512PKhmPh(ptr noundef, i64 noundef, ptr noundef) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt5arrayIhLm128EEixEm(ptr noundef nonnull align 1 dereferenceable(128), i64 noundef) #5 align 2

declare void @_Z11sha512_InitP10SHA512_CTX(ptr noundef) #4

declare void @_Z13sha512_UpdateP10SHA512_CTXPKhm(ptr noundef, ptr noundef, i64 noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { "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 #5 = { 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 #6 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; 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) #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z16hmac_sha512_InitI10SHA512_CTXLm128EEvP8HMAC_CTXIT_XT0_EEPKhj(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #3 {
  %4 = alloca [128 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %4) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(128) %4, i8 0, i64 128, i1 false)
  %5 = zext i32 %2 to i64
  %6 = icmp ugt i32 %2, 128
  br i1 %6, label %7, label %8

7:                                                ; preds = %3
  call void @_Z6sha512PKhmPh(ptr noundef %1, i64 noundef %5, ptr noundef nonnull %4)
  br label %.preheader

.preheader:                                       ; preds = %8, %7
  br label %11

8:                                                ; preds = %3
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %4, ptr align 1 %1, i64 %5, i1 false)
  br label %.preheader

9:                                                ; preds = %11
  %10 = getelementptr inbounds i8, ptr %0, i64 128
  call void @_Z11sha512_InitP10SHA512_CTX(ptr noundef nonnull %10)
  call void @_Z13sha512_UpdateP10SHA512_CTXPKhm(ptr noundef nonnull %10, ptr noundef nonnull %4, i64 noundef 128)
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %4) #6
  ret void

11:                                               ; preds = %.preheader, %11
  %.013 = phi i64 [ %18, %11 ], [ 0, %.preheader ]
  %12 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 %.013
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = xor i8 %13, 92
  %15 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt5arrayIhLm128EEixEm(ptr noundef nonnull align 1 dereferenceable(128) %0, i64 noundef %.013) #6
  store i8 %14, ptr %15, align 1, !tbaa !5
  %16 = load i8, ptr %12, align 1, !tbaa !5
  %17 = xor i8 %16, 54
  store i8 %17, ptr %12, align 1, !tbaa !5
  %18 = add nuw nsw i64 %.013, 1
  %exitcond.not = icmp eq i64 %18, 128
  br i1 %exitcond.not, label %9, label %11, !llvm.loop !8
}

declare void @_Z6sha512PKhmPh(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt5arrayIhLm128EEixEm(ptr noundef nonnull align 1 dereferenceable(128), i64 noundef) local_unnamed_addr #5 align 2

declare void @_Z11sha512_InitP10SHA512_CTX(ptr noundef) local_unnamed_addr #4

declare void @_Z13sha512_UpdateP10SHA512_CTXPKhm(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { "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 #5 = { 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 #6 = { 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"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass