; LLVM IR from cornell-zhang/rosetta :: BNN/cpp/minizip/aes (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.hmac_ctx = type { [64 x i8], [1 x %struct.sha1_ctx], i64 }
%struct.sha1_ctx = type { [2 x i32], [5 x i32], [16 x i32] }

declare void @sha1_begin(ptr noundef) #0

declare void @sha1_hash(ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @hmac_sha_data(ptr noundef, i64 noundef, ptr noundef) #1

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

declare void @sha1_end(ptr noundef, ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @hmac_sha_end(ptr noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [20 x i8], align 16
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 20, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.hmac_ctx, ptr %9, i32 0, i32 2
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = icmp ne i64 %11, 4294967295
  br i1 %12, label %13, label %15

13:                                               ; preds = %3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  call void @hmac_sha_data(ptr noundef null, i64 noundef 0, ptr noundef %14)
  br label %15

15:                                               ; preds = %13, %3
  %16 = getelementptr inbounds [20 x i8], ptr %7, i64 0, i64 0
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.hmac_ctx, ptr %17, i32 0, i32 1
  %19 = getelementptr inbounds [1 x %struct.sha1_ctx], ptr %18, i64 0, i64 0
  call void @sha1_end(ptr noundef %16, ptr noundef %19)
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %20

20:                                               ; preds = %32, %15
  %21 = load i32, ptr %8, align 4, !tbaa !13
  %22 = icmp ult i32 %21, 16
  br i1 %22, label %23, label %35

23:                                               ; preds = %20
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.hmac_ctx, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [64 x i8], ptr %25, i64 0, i64 0
  %27 = load i32, ptr %8, align 4, !tbaa !13
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %26, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = xor i32 %30, 1785358954
  store i32 %31, ptr %29, align 4, !tbaa !13
  br label %32

32:                                               ; preds = %23
  %33 = load i32, ptr %8, align 4, !tbaa !13
  %34 = add i32 %33, 1
  store i32 %34, ptr %8, align 4, !tbaa !13
  br label %20, !llvm.loop !15

35:                                               ; preds = %20
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.hmac_ctx, ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds [1 x %struct.sha1_ctx], ptr %37, i64 0, i64 0
  call void @sha1_begin(ptr noundef %38)
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.hmac_ctx, ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds [64 x i8], ptr %40, i64 0, i64 0
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.hmac_ctx, ptr %42, i32 0, i32 1
  %44 = getelementptr inbounds [1 x %struct.sha1_ctx], ptr %43, i64 0, i64 0
  call void @sha1_hash(ptr noundef %41, i64 noundef 64, ptr noundef %44)
  %45 = getelementptr inbounds [20 x i8], ptr %7, i64 0, i64 0
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.hmac_ctx, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds [1 x %struct.sha1_ctx], ptr %47, i64 0, i64 0
  call void @sha1_hash(ptr noundef %45, i64 noundef 20, ptr noundef %48)
  %49 = getelementptr inbounds [20 x i8], ptr %7, i64 0, i64 0
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.hmac_ctx, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds [1 x %struct.sha1_ctx], ptr %51, i64 0, i64 0
  call void @sha1_end(ptr noundef %49, ptr noundef %52)
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %53

53:                                               ; preds = %67, %35
  %54 = load i32, ptr %8, align 4, !tbaa !13
  %55 = zext i32 %54 to i64
  %56 = load i64, ptr %5, align 8, !tbaa !9
  %57 = icmp ult i64 %55, %56
  br i1 %57, label %58, label %70

58:                                               ; preds = %53
  %59 = load i32, ptr %8, align 4, !tbaa !13
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds [20 x i8], ptr %7, i64 0, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !17
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !13
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %63, i64 %65
  store i8 %62, ptr %66, align 1, !tbaa !17
  br label %67

67:                                               ; preds = %58
  %68 = load i32, ptr %8, align 4, !tbaa !13
  %69 = add i32 %68, 1
  store i32 %69, ptr %8, align 4, !tbaa !13
  br label %53, !llvm.loop !18

70:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 20, ptr %7) #3
  ret void
}

attributes #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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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, !10, i64 160}
!12 = !{!"", !7, i64 0, !7, i64 64, !10, i64 160}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !16}


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

declare void @sha1_begin(ptr noundef) local_unnamed_addr #0

declare void @sha1_hash(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @hmac_sha_data(ptr noundef, i64 noundef, ptr noundef) local_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

declare void @sha1_end(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @hmac_sha_end(ptr nocapture noundef writeonly %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca [20 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %4) #3
  %5 = getelementptr inbounds i8, ptr %2, i64 160
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i64 %6, 4294967295
  br i1 %.not, label %8, label %7

7:                                                ; preds = %3
  tail call void @hmac_sha_data(ptr noundef null, i64 noundef 0, ptr noundef nonnull %2)
  br label %8

8:                                                ; preds = %7, %3
  %9 = getelementptr inbounds i8, ptr %2, i64 64
  call void @sha1_end(ptr noundef nonnull %4, ptr noundef nonnull %9) #3
  %10 = load <4 x i32>, ptr %2, align 4, !tbaa !10
  %11 = xor <4 x i32> %10, <i32 1785358954, i32 1785358954, i32 1785358954, i32 1785358954>
  store <4 x i32> %11, ptr %2, align 4, !tbaa !10
  %12 = getelementptr inbounds i8, ptr %2, i64 16
  %13 = load <4 x i32>, ptr %12, align 4, !tbaa !10
  %14 = xor <4 x i32> %13, <i32 1785358954, i32 1785358954, i32 1785358954, i32 1785358954>
  store <4 x i32> %14, ptr %12, align 4, !tbaa !10
  %15 = getelementptr inbounds i8, ptr %2, i64 32
  %16 = load <4 x i32>, ptr %15, align 4, !tbaa !10
  %17 = xor <4 x i32> %16, <i32 1785358954, i32 1785358954, i32 1785358954, i32 1785358954>
  store <4 x i32> %17, ptr %15, align 4, !tbaa !10
  %18 = getelementptr inbounds i8, ptr %2, i64 48
  %19 = load <4 x i32>, ptr %18, align 4, !tbaa !10
  %20 = xor <4 x i32> %19, <i32 1785358954, i32 1785358954, i32 1785358954, i32 1785358954>
  store <4 x i32> %20, ptr %18, align 4, !tbaa !10
  call void @sha1_begin(ptr noundef nonnull %9) #3
  call void @sha1_hash(ptr noundef nonnull %2, i64 noundef 64, ptr noundef nonnull %9) #3
  call void @sha1_hash(ptr noundef nonnull %4, i64 noundef 20, ptr noundef nonnull %9) #3
  call void @sha1_end(ptr noundef nonnull %4, ptr noundef nonnull %9) #3
  %.not20 = icmp eq i64 %1, 0
  br i1 %.not20, label %._crit_edge, label %iter.check

iter.check:                                       ; preds = %8
  %min.iters.check = icmp ult i64 %1, 8
  br i1 %min.iters.check, label %.lr.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %iter.check
  %21 = add i64 %1, -1
  %22 = and i64 %21, 4294967295
  %23 = icmp eq i64 %22, 4294967295
  %24 = icmp ugt i64 %21, 4294967295
  %25 = or i1 %23, %24
  br i1 %25, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %vector.scevcheck
  %min.iters.check22 = icmp ult i64 %1, 32
  br i1 %min.iters.check22, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %1, 8589934560
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %26 = getelementptr inbounds [20 x i8], ptr %4, i64 0, i64 %index
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %wide.load = load <16 x i8>, ptr %26, align 16, !tbaa !12
  %wide.load23 = load <16 x i8>, ptr %27, align 16, !tbaa !12
  %28 = getelementptr inbounds i8, ptr %0, i64 %index
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  store <16 x i8> %wide.load, ptr %28, align 1, !tbaa !12
  store <16 x i8> %wide.load23, ptr %29, align 1, !tbaa !12
  %index.next = add nuw i64 %index, 32
  %30 = icmp eq i64 %index.next, %n.vec
  br i1 %30, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %1
  br i1 %cmp.n, label %._crit_edge, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %ind.end26 = trunc i64 %n.vec to i32
  %n.vec.remaining = and i64 %1, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec25 = and i64 %1, 8589934584
  %ind.end = trunc i64 %n.vec25 to i32
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index28 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next30, %vec.epilog.vector.body ]
  %31 = getelementptr inbounds [20 x i8], ptr %4, i64 0, i64 %index28
  %wide.load29 = load <8 x i8>, ptr %31, align 8, !tbaa !12
  %32 = getelementptr inbounds i8, ptr %0, i64 %index28
  store <8 x i8> %wide.load29, ptr %32, align 1, !tbaa !12
  %index.next30 = add nuw i64 %index28, 8
  %33 = icmp eq i64 %index.next30, %n.vec25
  br i1 %33, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !17

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n31 = icmp eq i64 %n.vec25, %1
  br i1 %cmp.n31, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %vector.scevcheck, %iter.check, %vec.epilog.iter.check
  %.ph = phi i64 [ 0, %iter.check ], [ 0, %vector.scevcheck ], [ %n.vec, %vec.epilog.iter.check ], [ %n.vec25, %vec.epilog.middle.block ]
  %.119.ph = phi i32 [ 0, %iter.check ], [ 0, %vector.scevcheck ], [ %ind.end26, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %34 = phi i64 [ %39, %.lr.ph ], [ %.ph, %.lr.ph.preheader ]
  %.119 = phi i32 [ %38, %.lr.ph ], [ %.119.ph, %.lr.ph.preheader ]
  %35 = getelementptr inbounds [20 x i8], ptr %4, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !12
  %37 = getelementptr inbounds i8, ptr %0, i64 %34
  store i8 %36, ptr %37, align 1, !tbaa !12
  %38 = add i32 %.119, 1
  %39 = zext i32 %38 to i64
  %40 = icmp ult i64 %39, %1
  br i1 %40, label %.lr.ph, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %vec.epilog.middle.block, %8
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %4) #3
  ret void
}

attributes #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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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, !9, i64 160}
!6 = !{!"", !7, i64 0, !7, i64 64, !9, i64 160}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14, !15, !16}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !14, !15, !16}
!18 = distinct !{!18, !14, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass