; 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: nounwind uwtable
define dso_local i32 @hmac_sha_key(ptr noundef %0, i64 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %7, 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 eq i64 %10, 4294967295
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  br label %60

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

20:                                               ; preds = %13
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.hmac_ctx, ptr %21, i32 0, i32 2
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = icmp ule i64 %23, 64
  br i1 %24, label %25, label %38

25:                                               ; preds = %20
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.hmac_ctx, ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds [1 x %struct.sha1_ctx], ptr %27, i64 0, i64 0
  call void @sha1_begin(ptr noundef %28)
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.hmac_ctx, ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds [64 x i8], ptr %30, i64 0, i64 0
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.hmac_ctx, ptr %32, i32 0, i32 2
  %34 = load i64, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.hmac_ctx, ptr %35, i32 0, i32 1
  %37 = getelementptr inbounds [1 x %struct.sha1_ctx], ptr %36, i64 0, i64 0
  call void @sha1_hash(ptr noundef %31, i64 noundef %34, ptr noundef %37)
  br label %38

38:                                               ; preds = %25, %20
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.hmac_ctx, ptr %41, i32 0, i32 1
  %43 = getelementptr inbounds [1 x %struct.sha1_ctx], ptr %42, i64 0, i64 0
  call void @sha1_hash(ptr noundef %39, i64 noundef %40, ptr noundef %43)
  br label %54

44:                                               ; preds = %13
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.hmac_ctx, ptr %45, i32 0, i32 0
  %47 = getelementptr inbounds [64 x i8], ptr %46, i64 0, i64 0
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.hmac_ctx, ptr %48, i32 0, i32 2
  %50 = load i64, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds i8, ptr %47, i64 %50
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %51, ptr align 1 %52, i64 %53, i1 false)
  br label %54

54:                                               ; preds = %44, %38
  %55 = load i64, ptr %6, align 8, !tbaa !9
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.hmac_ctx, ptr %56, i32 0, i32 2
  %58 = load i64, ptr %57, align 8, !tbaa !11
  %59 = add i64 %58, %55
  store i64 %59, ptr %57, align 8, !tbaa !11
  store i32 0, ptr %4, align 4
  br label %60

60:                                               ; preds = %54, %12
  %61 = load i32, ptr %4, align 4
  ret i32 %61
}

declare void @sha1_begin(ptr noundef) #1

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

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

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 = { "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 nounwind willreturn memory(argmem: readwrite) }

!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}


; 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: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @hmac_sha_key(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %2, i64 160
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i64 %5, 4294967295
  br i1 %6, label %22, label %7

7:                                                ; preds = %3
  %8 = add i64 %5, %1
  %9 = icmp ugt i64 %8, 64
  br i1 %9, label %10, label %17

10:                                               ; preds = %7
  %11 = icmp ult i64 %5, 65
  br i1 %11, label %12, label %15

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %2, i64 64
  tail call void @sha1_begin(ptr noundef nonnull %13) #3
  %14 = load i64, ptr %4, align 8, !tbaa !5
  tail call void @sha1_hash(ptr noundef nonnull %2, i64 noundef %14, ptr noundef nonnull %13) #3
  br label %15

15:                                               ; preds = %12, %10
  %16 = getelementptr inbounds i8, ptr %2, i64 64
  tail call void @sha1_hash(ptr noundef %0, i64 noundef %1, ptr noundef nonnull %16) #3
  br label %19

17:                                               ; preds = %7
  %18 = getelementptr inbounds i8, ptr %2, i64 %5
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %18, ptr align 1 %0, i64 %1, i1 false)
  br label %19

19:                                               ; preds = %17, %15
  %20 = load i64, ptr %4, align 8, !tbaa !5
  %21 = add i64 %20, %1
  store i64 %21, ptr %4, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %3, %19
  %.0 = phi i32 [ 0, %19 ], [ -1, %3 ]
  ret i32 %.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: 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) #2

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 = { "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 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}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass