; LLVM IR from kala13x/libxutils :: src/crypt (hmac)

; 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.XSHA256 = type { %union.xsha256_digest_t, %union.xsha256_block_t, i64, i64 }
%union.xsha256_digest_t = type { [8 x i32] }
%union.xsha256_block_t = type { [16 x i32] }

; Function Attrs: nounwind uwtable
define dso_local i32 @XHMAC_SHA256(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i8, align 1
  %15 = alloca [32 x i8], align 16
  %16 = alloca [64 x i8], align 16
  %17 = alloca [64 x i8], align 16
  %18 = alloca %struct.XSHA256, align 8
  %19 = alloca [32 x i8], align 16
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i64 %3, ptr %11, align 8, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !5
  store i64 %5, ptr %13, align 8, !tbaa !9
  %20 = load i64, ptr %9, align 8, !tbaa !9
  %21 = icmp uge i64 %20, 32
  br i1 %21, label %22, label %37

22:                                               ; preds = %6
  %23 = load i64, ptr %11, align 8, !tbaa !9
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %37

25:                                               ; preds = %22
  %26 = load i64, ptr %13, align 8, !tbaa !9
  %27 = icmp ne i64 %26, 0
  br i1 %27, label %28, label %37

28:                                               ; preds = %25
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %37

31:                                               ; preds = %28
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %37

34:                                               ; preds = %31
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %38, label %37

37:                                               ; preds = %34, %31, %28, %25, %22, %6
  store i32 -2, ptr %7, align 4
  br label %88

38:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 64, ptr %16) #5
  call void @llvm.memset.p0.i64(ptr align 16 %16, i8 0, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 64, ptr %17) #5
  call void @llvm.memset.p0.i64(ptr align 16 %17, i8 0, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 112, ptr %18) #5
  %39 = load i64, ptr %13, align 8, !tbaa !9
  %40 = icmp ugt i64 %39, 64
  br i1 %40, label %41, label %50

41:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 32, ptr %19) #5
  call void @llvm.memset.p0.i64(ptr align 16 %19, i8 0, i64 32, i1 false)
  %42 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 0
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = load i64, ptr %13, align 8, !tbaa !9
  %45 = call i32 @XSHA256_Compute(ptr noundef %42, i64 noundef 32, ptr noundef %43, i64 noundef %44)
  %46 = getelementptr inbounds [64 x i8], ptr %16, i64 0, i64 0
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %46, ptr align 1 %47, i64 32, i1 false)
  %48 = getelementptr inbounds [64 x i8], ptr %17, i64 0, i64 0
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %48, ptr align 1 %49, i64 32, i1 false)
  call void @llvm.lifetime.end.p0(i64 32, ptr %19) #5
  br label %57

50:                                               ; preds = %38
  %51 = getelementptr inbounds [64 x i8], ptr %16, i64 0, i64 0
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  %53 = load i64, ptr %13, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %51, ptr align 1 %52, i64 %53, i1 false)
  %54 = getelementptr inbounds [64 x i8], ptr %17, i64 0, i64 0
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = load i64, ptr %13, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %54, ptr align 1 %55, i64 %56, i1 false)
  br label %57

57:                                               ; preds = %50, %41
  store i8 0, ptr %14, align 1, !tbaa !11
  br label %58

58:                                               ; preds = %77, %57
  %59 = load i8, ptr %14, align 1, !tbaa !11
  %60 = zext i8 %59 to i32
  %61 = icmp slt i32 %60, 64
  br i1 %61, label %62, label %80

62:                                               ; preds = %58
  %63 = load i8, ptr %14, align 1, !tbaa !11
  %64 = zext i8 %63 to i64
  %65 = getelementptr inbounds [64 x i8], ptr %16, i64 0, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !11
  %67 = zext i8 %66 to i32
  %68 = xor i32 %67, 54
  %69 = trunc i32 %68 to i8
  store i8 %69, ptr %65, align 1, !tbaa !11
  %70 = load i8, ptr %14, align 1, !tbaa !11
  %71 = zext i8 %70 to i64
  %72 = getelementptr inbounds [64 x i8], ptr %17, i64 0, i64 %71
  %73 = load i8, ptr %72, align 1, !tbaa !11
  %74 = zext i8 %73 to i32
  %75 = xor i32 %74, 92
  %76 = trunc i32 %75 to i8
  store i8 %76, ptr %72, align 1, !tbaa !11
  br label %77

77:                                               ; preds = %62
  %78 = load i8, ptr %14, align 1, !tbaa !11
  %79 = add i8 %78, 1
  store i8 %79, ptr %14, align 1, !tbaa !11
  br label %58, !llvm.loop !12

80:                                               ; preds = %58
  call void @XSHA256_Init(ptr noundef %18)
  %81 = getelementptr inbounds [64 x i8], ptr %16, i64 0, i64 0
  call void @XSHA256_Update(ptr noundef %18, ptr noundef %81, i64 noundef 64)
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = load i64, ptr %11, align 8, !tbaa !9
  call void @XSHA256_Update(ptr noundef %18, ptr noundef %82, i64 noundef %83)
  %84 = getelementptr inbounds [32 x i8], ptr %15, i64 0, i64 0
  call void @XSHA256_Final(ptr noundef %18, ptr noundef %84)
  call void @XSHA256_Init(ptr noundef %18)
  %85 = getelementptr inbounds [64 x i8], ptr %17, i64 0, i64 0
  call void @XSHA256_Update(ptr noundef %18, ptr noundef %85, i64 noundef 64)
  %86 = getelementptr inbounds [32 x i8], ptr %15, i64 0, i64 0
  call void @XSHA256_Update(ptr noundef %18, ptr noundef %86, i64 noundef 32)
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  call void @XSHA256_Final(ptr noundef %18, ptr noundef %87)
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 112, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #5
  br label %88

88:                                               ; preds = %80, %37
  %89 = load i32, ptr %7, align 4
  ret i32 %89
}

; 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 i32 @XSHA256_Compute(ptr noundef, i64 noundef, ptr noundef, i64 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare void @XSHA256_Init(ptr noundef) #3

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

declare void @XSHA256_Final(ptr noundef, ptr noundef) #3

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 = { "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 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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.XSHA256 = type { %union.xsha256_digest_t, %union.xsha256_block_t, i64, i64 }
%union.xsha256_digest_t = type { [8 x i32] }
%union.xsha256_block_t = type { [16 x i32] }

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2, 2) i32 @XHMAC_SHA256(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5) local_unnamed_addr #0 {
  %7 = alloca [32 x i8], align 16
  %8 = alloca [64 x i8], align 16
  %9 = alloca [64 x i8], align 16
  %10 = alloca %struct.XSHA256, align 8
  %11 = alloca [32 x i8], align 16
  %12 = icmp ugt i64 %1, 31
  %13 = icmp ne i64 %3, 0
  %or.cond = and i1 %12, %13
  %14 = icmp ne i64 %5, 0
  %or.cond3 = and i1 %or.cond, %14
  %15 = icmp ne ptr %0, null
  %or.cond5 = and i1 %15, %or.cond3
  %16 = icmp ne ptr %2, null
  %or.cond7 = and i1 %16, %or.cond5
  %17 = icmp ne ptr %4, null
  %or.cond9 = and i1 %17, %or.cond7
  br i1 %or.cond9, label %18, label %37

18:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %7) #5
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %8) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %8, i8 0, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %9) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %9, i8 0, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %10) #5
  %19 = icmp ugt i64 %5, 64
  br i1 %19, label %20, label %22

20:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %11) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %11, i8 0, i64 32, i1 false)
  %21 = call i32 @XSHA256_Compute(ptr noundef nonnull %11, i64 noundef 32, ptr noundef nonnull %4, i64 noundef %5) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %8, ptr noundef nonnull align 1 dereferenceable(32) %4, i64 32, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %9, ptr noundef nonnull align 1 dereferenceable(32) %4, i64 32, i1 false)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %11) #5
  br label %vector.body

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

vector.body:                                      ; preds = %22, %20
  %23 = getelementptr inbounds i8, ptr %8, i64 16
  %wide.load = load <16 x i8>, ptr %8, align 16, !tbaa !5
  %wide.load36 = load <16 x i8>, ptr %23, align 16, !tbaa !5
  %24 = 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>
  %25 = xor <16 x i8> %wide.load36, <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> %24, ptr %8, align 16, !tbaa !5
  store <16 x i8> %25, ptr %23, align 16, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %9, i64 16
  %wide.load37 = load <16 x i8>, ptr %9, align 16, !tbaa !5
  %wide.load38 = load <16 x i8>, ptr %26, align 16, !tbaa !5
  %27 = xor <16 x i8> %wide.load37, <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>
  %28 = xor <16 x i8> %wide.load38, <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> %27, ptr %9, align 16, !tbaa !5
  store <16 x i8> %28, ptr %26, align 16, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %8, i64 32
  %30 = getelementptr inbounds i8, ptr %8, i64 48
  %wide.load.1 = load <16 x i8>, ptr %29, align 16, !tbaa !5
  %wide.load36.1 = load <16 x i8>, ptr %30, align 16, !tbaa !5
  %31 = 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>
  %32 = xor <16 x i8> %wide.load36.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> %31, ptr %29, align 16, !tbaa !5
  store <16 x i8> %32, ptr %30, align 16, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %9, i64 32
  %34 = getelementptr inbounds i8, ptr %9, i64 48
  %wide.load37.1 = load <16 x i8>, ptr %33, align 16, !tbaa !5
  %wide.load38.1 = load <16 x i8>, ptr %34, align 16, !tbaa !5
  %35 = xor <16 x i8> %wide.load37.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>
  %36 = xor <16 x i8> %wide.load38.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> %35, ptr %33, align 16, !tbaa !5
  store <16 x i8> %36, ptr %34, align 16, !tbaa !5
  call void @XSHA256_Init(ptr noundef nonnull %10) #5
  call void @XSHA256_Update(ptr noundef nonnull %10, ptr noundef nonnull %8, i64 noundef 64) #5
  call void @XSHA256_Update(ptr noundef nonnull %10, ptr noundef nonnull %2, i64 noundef %3) #5
  call void @XSHA256_Final(ptr noundef nonnull %10, ptr noundef nonnull %7) #5
  call void @XSHA256_Init(ptr noundef nonnull %10) #5
  call void @XSHA256_Update(ptr noundef nonnull %10, ptr noundef nonnull %9, i64 noundef 64) #5
  call void @XSHA256_Update(ptr noundef nonnull %10, ptr noundef nonnull %7, i64 noundef 32) #5
  call void @XSHA256_Final(ptr noundef nonnull %10, ptr noundef nonnull %0) #5
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %10) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %9) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #5
  br label %37

37:                                               ; preds = %6, %vector.body
  %.031 = phi i32 [ 1, %vector.body ], [ -2, %6 ]
  ret i32 %.031
}

; 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 i32 @XSHA256_Compute(ptr noundef, i64 noundef, ptr noundef, i64 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare void @XSHA256_Init(ptr noundef) local_unnamed_addr #3

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

declare void @XSHA256_Final(ptr noundef, ptr noundef) local_unnamed_addr #3

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 = { "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 = { 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,ReassociatePass,SROAPass,SimplifyCFGPass