; LLVM IR from louk78/crypto_project :: hmac (hmac_sha256)

; 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.sha256_ctx_t = type { [64 x i8], [8 x i32], i32, [2 x i32] }

; Function Attrs: nounwind uwtable
define dso_local void @hmac_sha256(ptr noundef %0, i64 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca [64 x i8], align 16
  %12 = alloca [64 x i8], align 16
  %13 = alloca [32 x i8], align 16
  %14 = alloca %struct.sha256_ctx_t, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !11
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 64, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 108, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %16 = load i32, ptr %9, align 4, !tbaa !11
  %17 = icmp ule i32 %16, 64
  br i1 %17, label %18, label %29

18:                                               ; preds = %5
  %19 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %19, i8 0, i64 64, i1 false)
  %20 = getelementptr inbounds [64 x i8], ptr %12, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %20, i8 0, i64 64, i1 false)
  %21 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load i32, ptr %9, align 4, !tbaa !11
  %24 = zext i32 %23 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %21, ptr align 1 %22, i64 %24, i1 false)
  %25 = getelementptr inbounds [64 x i8], ptr %12, i64 0, i64 0
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load i32, ptr %9, align 4, !tbaa !11
  %28 = zext i32 %27 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %25, ptr align 1 %26, i64 %28, i1 false)
  br label %35

29:                                               ; preds = %5
  call void @sha256_init(ptr noundef %14)
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !11
  call void @sha256_update(ptr noundef %14, ptr noundef %30, i32 noundef %31)
  %32 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  call void @sha256_finish(ptr noundef %14, ptr noundef %32)
  %33 = getelementptr inbounds [64 x i8], ptr %12, i64 0, i64 0
  %34 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %33, ptr align 16 %34, i64 64, i1 false)
  br label %35

35:                                               ; preds = %29, %18
  store i32 0, ptr %15, align 4, !tbaa !11
  br label %36

36:                                               ; preds = %60, %35
  %37 = load i32, ptr %15, align 4, !tbaa !11
  %38 = icmp slt i32 %37, 64
  br i1 %38, label %39, label %63

39:                                               ; preds = %36
  %40 = load i32, ptr %15, align 4, !tbaa !11
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !13
  %44 = zext i8 %43 to i32
  %45 = xor i32 %44, 54
  %46 = trunc i32 %45 to i8
  %47 = load i32, ptr %15, align 4, !tbaa !11
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 %48
  store i8 %46, ptr %49, align 1, !tbaa !13
  %50 = load i32, ptr %15, align 4, !tbaa !11
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [64 x i8], ptr %12, i64 0, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !13
  %54 = zext i8 %53 to i32
  %55 = xor i32 %54, 92
  %56 = trunc i32 %55 to i8
  %57 = load i32, ptr %15, align 4, !tbaa !11
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [64 x i8], ptr %12, i64 0, i64 %58
  store i8 %56, ptr %59, align 1, !tbaa !13
  br label %60

60:                                               ; preds = %39
  %61 = load i32, ptr %15, align 4, !tbaa !11
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %15, align 4, !tbaa !11
  br label %36, !llvm.loop !14

63:                                               ; preds = %36
  call void @sha256_init(ptr noundef %14)
  %64 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  call void @sha256_update(ptr noundef %14, ptr noundef %64, i32 noundef 64)
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load i64, ptr %7, align 8, !tbaa !9
  %67 = trunc i64 %66 to i32
  call void @sha256_update(ptr noundef %14, ptr noundef %65, i32 noundef %67)
  %68 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  call void @sha256_finish(ptr noundef %14, ptr noundef %68)
  call void @sha256_init(ptr noundef %14)
  %69 = getelementptr inbounds [64 x i8], ptr %12, i64 0, i64 0
  call void @sha256_update(ptr noundef %14, ptr noundef %69, i32 noundef 64)
  %70 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  call void @sha256_update(ptr noundef %14, ptr noundef %70, i32 noundef 32)
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  call void @sha256_finish(ptr noundef %14, ptr noundef %71)
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 108, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %11) #5
  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

; 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

declare void @sha256_init(ptr noundef) #4

declare void @sha256_update(ptr noundef, ptr noundef, i32 noundef) #4

declare void @sha256_finish(ptr noundef, ptr noundef) #4

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

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


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

%struct.sha256_ctx_t = type { [64 x i8], [8 x i32], i32, [2 x i32] }

; Function Attrs: nounwind uwtable
define dso_local void @hmac_sha256(ptr noundef %0, i64 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca [64 x i8], align 16
  %7 = alloca [64 x i8], align 16
  %8 = alloca [32 x i8], align 16
  %9 = alloca %struct.sha256_ctx_t, align 4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %7) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %8) #5
  call void @llvm.lifetime.start.p0(i64 108, ptr nonnull %9) #5
  %10 = icmp ult i32 %3, 65
  br i1 %10, label %11, label %13

11:                                               ; preds = %5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %6, i8 0, i64 64, i1 false)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %7, i8 0, i64 64, i1 false)
  %12 = zext nneg i32 %3 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %6, ptr align 1 %2, i64 %12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %7, ptr align 1 %2, i64 %12, i1 false)
  br label %vector.body

13:                                               ; preds = %5
  call void @sha256_init(ptr noundef nonnull %9) #5
  call void @sha256_update(ptr noundef nonnull %9, ptr noundef %2, i32 noundef %3) #5
  call void @sha256_finish(ptr noundef nonnull %9, ptr noundef nonnull %6) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %7, ptr noundef nonnull align 16 dereferenceable(64) %6, i64 64, i1 false)
  br label %vector.body

vector.body:                                      ; preds = %13, %11
  %14 = getelementptr inbounds i8, ptr %6, i64 16
  %wide.load = load <16 x i8>, ptr %6, align 16, !tbaa !5
  %wide.load18 = load <16 x i8>, ptr %14, align 16, !tbaa !5
  %15 = xor <16 x i8> %wide.load, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
  %16 = xor <16 x i8> %wide.load18, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
  store <16 x i8> %15, ptr %6, align 16, !tbaa !5
  store <16 x i8> %16, ptr %14, align 16, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %7, i64 16
  %wide.load19 = load <16 x i8>, ptr %7, align 16, !tbaa !5
  %wide.load20 = load <16 x i8>, ptr %17, align 16, !tbaa !5
  %18 = xor <16 x i8> %wide.load19, <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>
  %19 = xor <16 x i8> %wide.load20, <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> %18, ptr %7, align 16, !tbaa !5
  store <16 x i8> %19, ptr %17, align 16, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %6, i64 32
  %21 = getelementptr inbounds i8, ptr %6, i64 48
  %wide.load.1 = load <16 x i8>, ptr %20, align 16, !tbaa !5
  %wide.load18.1 = load <16 x i8>, ptr %21, align 16, !tbaa !5
  %22 = xor <16 x i8> %wide.load.1, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
  %23 = xor <16 x i8> %wide.load18.1, <i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54, i8 54>
  store <16 x i8> %22, ptr %20, align 16, !tbaa !5
  store <16 x i8> %23, ptr %21, align 16, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %7, i64 32
  %25 = getelementptr inbounds i8, ptr %7, i64 48
  %wide.load19.1 = load <16 x i8>, ptr %24, align 16, !tbaa !5
  %wide.load20.1 = load <16 x i8>, ptr %25, align 16, !tbaa !5
  %26 = xor <16 x i8> %wide.load19.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>
  %27 = xor <16 x i8> %wide.load20.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> %26, ptr %24, align 16, !tbaa !5
  store <16 x i8> %27, ptr %25, align 16, !tbaa !5
  call void @sha256_init(ptr noundef nonnull %9) #5
  call void @sha256_update(ptr noundef nonnull %9, ptr noundef nonnull %6, i32 noundef 64) #5
  %28 = trunc i64 %1 to i32
  call void @sha256_update(ptr noundef nonnull %9, ptr noundef %0, i32 noundef %28) #5
  call void @sha256_finish(ptr noundef nonnull %9, ptr noundef nonnull %8) #5
  call void @sha256_init(ptr noundef nonnull %9) #5
  call void @sha256_update(ptr noundef nonnull %9, ptr noundef nonnull %7, i32 noundef 64) #5
  call void @sha256_update(ptr noundef nonnull %9, ptr noundef nonnull %8, i32 noundef 32) #5
  call void @sha256_finish(ptr noundef nonnull %9, ptr noundef %4) #5
  call void @llvm.lifetime.end.p0(i64 108, ptr nonnull %9) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %6) #5
  ret void
}

; 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

; 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

declare void @sha256_init(ptr noundef) local_unnamed_addr #4

declare void @sha256_update(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

declare void @sha256_finish(ptr noundef, ptr noundef) local_unnamed_addr #4

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

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


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