; 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] }

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

declare void @sha1_begin(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @hmac_sha_data(ptr noundef %0, i64 noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = 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 4, ptr %7) #4
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.hmac_ctx, ptr %8, i32 0, i32 2
  %10 = load i64, ptr %9, align 8, !tbaa !11
  %11 = icmp ne i64 %10, 4294967295
  br i1 %11, label %12, label %65

12:                                               ; preds = %3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.hmac_ctx, ptr %13, i32 0, i32 2
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = icmp ugt i64 %15, 64
  br i1 %16, label %17, label %26

17:                                               ; preds = %12
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.hmac_ctx, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds [64 x i8], ptr %19, i64 0, i64 0
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.hmac_ctx, ptr %21, i32 0, i32 1
  %23 = getelementptr inbounds [1 x %struct.sha1_ctx], ptr %22, i64 0, i64 0
  call void @sha1_end(ptr noundef %20, ptr noundef %23)
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.hmac_ctx, ptr %24, i32 0, i32 2
  store i64 20, ptr %25, align 8, !tbaa !11
  br label %26

26:                                               ; preds = %17, %12
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.hmac_ctx, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds [64 x i8], ptr %28, i64 0, i64 0
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.hmac_ctx, ptr %30, i32 0, i32 2
  %32 = load i64, ptr %31, align 8, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %29, i64 %32
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.hmac_ctx, ptr %34, i32 0, i32 2
  %36 = load i64, ptr %35, align 8, !tbaa !11
  %37 = sub i64 64, %36
  call void @llvm.memset.p0.i64(ptr align 1 %33, i8 0, i64 %37, i1 false)
  store i32 0, ptr %7, align 4, !tbaa !13
  br label %38

38:                                               ; preds = %50, %26
  %39 = load i32, ptr %7, align 4, !tbaa !13
  %40 = icmp ult i32 %39, 16
  br i1 %40, label %41, label %53

41:                                               ; preds = %38
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.hmac_ctx, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds [64 x i8], ptr %43, i64 0, i64 0
  %45 = load i32, ptr %7, align 4, !tbaa !13
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %44, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !13
  %49 = xor i32 %48, 909522486
  store i32 %49, ptr %47, align 4, !tbaa !13
  br label %50

50:                                               ; preds = %41
  %51 = load i32, ptr %7, align 4, !tbaa !13
  %52 = add i32 %51, 1
  store i32 %52, ptr %7, align 4, !tbaa !13
  br label %38, !llvm.loop !15

53:                                               ; preds = %38
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.hmac_ctx, ptr %54, i32 0, i32 1
  %56 = getelementptr inbounds [1 x %struct.sha1_ctx], ptr %55, i64 0, i64 0
  call void @sha1_begin(ptr noundef %56)
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.hmac_ctx, ptr %57, i32 0, i32 0
  %59 = getelementptr inbounds [64 x i8], ptr %58, i64 0, i64 0
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.hmac_ctx, ptr %60, i32 0, i32 1
  %62 = getelementptr inbounds [1 x %struct.sha1_ctx], ptr %61, i64 0, i64 0
  call void @sha1_hash(ptr noundef %59, i64 noundef 64, ptr noundef %62)
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.hmac_ctx, ptr %63, i32 0, i32 2
  store i64 4294967295, ptr %64, align 8, !tbaa !11
  br label %65

65:                                               ; preds = %53, %3
  %66 = load i64, ptr %5, align 8, !tbaa !9
  %67 = icmp ne i64 %66, 0
  br i1 %67, label %68, label %74

68:                                               ; preds = %65
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = load i64, ptr %5, align 8, !tbaa !9
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.hmac_ctx, ptr %71, i32 0, i32 1
  %73 = getelementptr inbounds [1 x %struct.sha1_ctx], ptr %72, i64 0, i64 0
  call void @sha1_hash(ptr noundef %69, i64 noundef %70, ptr noundef %73)
  br label %74

74:                                               ; preds = %68, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void
}

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

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

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

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


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

declare void @sha1_begin(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @hmac_sha_data(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = getelementptr inbounds i8, ptr %2, i64 160
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i64 %5, 4294967295
  br i1 %.not, label %26, label %6

6:                                                ; preds = %3
  %7 = icmp ugt i64 %5, 64
  br i1 %7, label %8, label %10

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %2, i64 64
  tail call void @sha1_end(ptr noundef nonnull %2, ptr noundef nonnull %9) #3
  store i64 20, ptr %4, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %8, %6
  %11 = phi i64 [ 20, %8 ], [ %5, %6 ]
  %12 = getelementptr inbounds i8, ptr %2, i64 %11
  %13 = sub nuw nsw i64 64, %11
  tail call void @llvm.memset.p0.i64(ptr align 1 %12, i8 0, i64 %13, i1 false)
  %14 = load <4 x i32>, ptr %2, align 4, !tbaa !10
  %15 = xor <4 x i32> %14, <i32 909522486, i32 909522486, i32 909522486, i32 909522486>
  store <4 x i32> %15, ptr %2, align 4, !tbaa !10
  %16 = getelementptr inbounds i8, ptr %2, i64 16
  %17 = load <4 x i32>, ptr %16, align 4, !tbaa !10
  %18 = xor <4 x i32> %17, <i32 909522486, i32 909522486, i32 909522486, i32 909522486>
  store <4 x i32> %18, ptr %16, align 4, !tbaa !10
  %19 = getelementptr inbounds i8, ptr %2, i64 32
  %20 = load <4 x i32>, ptr %19, align 4, !tbaa !10
  %21 = xor <4 x i32> %20, <i32 909522486, i32 909522486, i32 909522486, i32 909522486>
  store <4 x i32> %21, ptr %19, align 4, !tbaa !10
  %22 = getelementptr inbounds i8, ptr %2, i64 48
  %23 = load <4 x i32>, ptr %22, align 4, !tbaa !10
  %24 = xor <4 x i32> %23, <i32 909522486, i32 909522486, i32 909522486, i32 909522486>
  store <4 x i32> %24, ptr %22, align 4, !tbaa !10
  %25 = getelementptr inbounds i8, ptr %2, i64 64
  tail call void @sha1_begin(ptr noundef nonnull %25) #3
  tail call void @sha1_hash(ptr noundef nonnull %2, i64 noundef 64, ptr noundef nonnull %25) #3
  store i64 4294967295, ptr %4, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %10, %3
  %.not21 = icmp eq i64 %1, 0
  br i1 %.not21, label %29, label %27

27:                                               ; preds = %26
  %28 = getelementptr inbounds i8, ptr %2, i64 64
  tail call void @sha1_hash(ptr noundef %0, i64 noundef %1, ptr noundef nonnull %28) #3
  br label %29

29:                                               ; preds = %27, %26
  ret void
}

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass