; LLVM IR from Waqar144/simplecrypto-cxx :: simplecrypto-cxx/hmac.ll (Z16hmac_sha256_InitI10SHA256_CTXLm64EEvP8HMAC_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 = type { %"struct.std::array", %struct.SHA256_CTX }
%"struct.std::array" = type { [64 x i8] }
%struct.SHA256_CTX = type { %"struct.std::array.0", %"struct.std::array.1", i64 }
%"struct.std::array.0" = type { [16 x i32] }
%"struct.std::array.1" = type { [8 x i32] }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z16hmac_sha256_InitI10SHA256_CTXLm64EEvP8HMAC_CTXIT_XT0_EEPKhj(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca [64 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 64, ptr %7) #6
  call void @llvm.memset.p0.i64(ptr align 16 %7, i8 0, i64 64, i1 false)
  %9 = load i32, ptr %6, align 4, !tbaa !9
  %10 = zext i32 %9 to i64
  %11 = icmp ugt i64 %10, 64
  br i1 %11, label %12, label %17

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

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

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

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

26:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %47

27:                                               ; preds = %23
  %28 = load i64, ptr %8, align 8, !tbaa !11
  %29 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !13
  %31 = zext i8 %30 to i32
  %32 = xor i32 %31, 92
  %33 = trunc i32 %32 to i8
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.HMAC_CTX, ptr %34, i32 0, i32 0
  %36 = load i64, ptr %8, align 8, !tbaa !11
  %37 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt5arrayIhLm64EEixEm(ptr noundef nonnull align 1 dereferenceable(64) %35, i64 noundef %36) #6
  store i8 %33, ptr %37, align 1, !tbaa !13
  %38 = load i64, ptr %8, align 8, !tbaa !11
  %39 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !13
  %41 = zext i8 %40 to i32
  %42 = xor i32 %41, 54
  %43 = trunc i32 %42 to i8
  store i8 %43, ptr %39, align 1, !tbaa !13
  br label %44

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

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

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

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

declare void @_Z6sha256PKhmPh(ptr noundef, i64 noundef, ptr noundef) #3

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

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

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

declare void @_Z11sha256_InitP10SHA256_CTX(ptr noundef) #3

declare void @_Z13sha256_UpdateP10SHA256_CTXPKhm(ptr noundef, ptr noundef, i64 noundef) #3

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 uwtable
define dso_local void @_Z16hmac_sha256_InitI10SHA256_CTXLm64EEvP8HMAC_CTXIT_XT0_EEPKhj(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca [64 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %4, i8 0, i64 64, i1 false)
  %5 = zext i32 %2 to i64
  %6 = icmp ugt i32 %2, 64
  br i1 %6, label %7, label %8

7:                                                ; preds = %3
  call void @_Z6sha256PKhmPh(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 64
  call void @_Z11sha256_InitP10SHA256_CTX(ptr noundef nonnull %10)
  call void @_Z13sha256_UpdateP10SHA256_CTXPKhm(ptr noundef nonnull %10, ptr noundef nonnull %4, i64 noundef 64)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #6
  ret void

11:                                               ; preds = %.preheader, %11
  %.013 = phi i64 [ %18, %11 ], [ 0, %.preheader ]
  %12 = getelementptr inbounds [64 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 @_ZNSt5arrayIhLm64EEixEm(ptr noundef nonnull align 1 dereferenceable(64) %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, 64
  br i1 %exitcond.not, label %9, label %11, !llvm.loop !8
}

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

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

declare void @_Z6sha256PKhmPh(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

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

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

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

declare void @_Z11sha256_InitP10SHA256_CTX(ptr noundef) local_unnamed_addr #3

declare void @_Z13sha256_UpdateP10SHA256_CTXPKhm(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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