; LLVM IR from cornell-zhang/rosetta :: BNN/cpp/minizip/aes (sha1)

; 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.sha1_ctx = type { [2 x i32], [5 x i32], [16 x i32] }

; Function Attrs: nounwind uwtable
declare dso_local void @sha1_compile(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @sha1_hash(ptr noundef %0, i64 noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = 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
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.sha1_ctx, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds [2 x i32], ptr %12, i64 0, i64 0
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = and i32 %14, 63
  store i32 %15, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %16 = load i32, ptr %7, align 4, !tbaa !11
  %17 = sub i32 64, %16
  store i32 %17, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %18, ptr %9, align 8, !tbaa !5
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.sha1_ctx, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds [2 x i32], ptr %21, i64 0, i64 0
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = zext i32 %23 to i64
  %25 = add i64 %24, %19
  %26 = trunc i64 %25 to i32
  store i32 %26, ptr %22, align 4, !tbaa !11
  %27 = zext i32 %26 to i64
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %30, label %36

30:                                               ; preds = %3
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.sha1_ctx, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds [2 x i32], ptr %32, i64 0, i64 1
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %35 = add i32 %34, 1
  store i32 %35, ptr %33, align 4, !tbaa !11
  br label %36

36:                                               ; preds = %30, %3
  br label %37

37:                                               ; preds = %79, %36
  %38 = load i64, ptr %5, align 8, !tbaa !9
  %39 = load i32, ptr %8, align 4, !tbaa !11
  %40 = zext i32 %39 to i64
  %41 = icmp uge i64 %38, %40
  br i1 %41, label %42, label %81

42:                                               ; preds = %37
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.sha1_ctx, ptr %43, i32 0, i32 2
  %45 = getelementptr inbounds [16 x i32], ptr %44, i64 0, i64 0
  %46 = load i32, ptr %7, align 4, !tbaa !11
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %45, i64 %47
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !11
  %51 = zext i32 %50 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %48, ptr align 1 %49, i64 %51, i1 false)
  %52 = load i32, ptr %8, align 4, !tbaa !11
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = zext i32 %52 to i64
  %55 = getelementptr inbounds i8, ptr %53, i64 %54
  store ptr %55, ptr %9, align 8, !tbaa !5
  %56 = load i32, ptr %8, align 4, !tbaa !11
  %57 = zext i32 %56 to i64
  %58 = load i64, ptr %5, align 8, !tbaa !9
  %59 = sub i64 %58, %57
  store i64 %59, ptr %5, align 8, !tbaa !9
  store i32 64, ptr %8, align 4, !tbaa !11
  store i32 0, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 16, ptr %10, align 4, !tbaa !11
  br label %60

60:                                               ; preds = %64, %42
  %61 = load i32, ptr %10, align 4, !tbaa !11
  %62 = add nsw i32 %61, -1
  store i32 %62, ptr %10, align 4, !tbaa !11
  %63 = icmp ne i32 %61, 0
  br i1 %63, label %64, label %79

64:                                               ; preds = %60
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.sha1_ctx, ptr %65, i32 0, i32 2
  %67 = getelementptr inbounds [16 x i32], ptr %66, i64 0, i64 0
  %68 = load i32, ptr %10, align 4, !tbaa !11
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i32, ptr %67, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !11
  %72 = call i32 @__bswap_32(i32 noundef %71)
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.sha1_ctx, ptr %73, i32 0, i32 2
  %75 = getelementptr inbounds [16 x i32], ptr %74, i64 0, i64 0
  %76 = load i32, ptr %10, align 4, !tbaa !11
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i32, ptr %75, i64 %77
  store i32 %72, ptr %78, align 4, !tbaa !11
  br label %60, !llvm.loop !13

79:                                               ; preds = %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  call void @sha1_compile(ptr noundef %80)
  br label %37, !llvm.loop !15

81:                                               ; preds = %37
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.sha1_ctx, ptr %82, i32 0, i32 2
  %84 = getelementptr inbounds [16 x i32], ptr %83, i64 0, i64 0
  %85 = load i32, ptr %7, align 4, !tbaa !11
  %86 = zext i32 %85 to i64
  %87 = getelementptr inbounds i8, ptr %84, i64 %86
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  %89 = load i64, ptr %5, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %87, ptr align 1 %88, i64 %89, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void
}

; 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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__bswap_32(i32 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: readwrite) }
attributes #3 = { inlinehint 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 #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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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
declare dso_local void @sha1_compile(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @sha1_hash(ptr nocapture noundef readonly %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = and i32 %4, 63
  %6 = sub nuw nsw i32 64, %5
  %7 = trunc i64 %1 to i32
  %8 = add i32 %4, %7
  store i32 %8, ptr %2, align 4, !tbaa !5
  %9 = zext i32 %8 to i64
  %10 = icmp ult i64 %9, %1
  br i1 %10, label %11, label %15

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %2, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = add i32 %13, 1
  store i32 %14, ptr %12, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %11, %3
  %16 = zext nneg i32 %6 to i64
  %17 = zext nneg i32 %5 to i64
  %.not33 = icmp ugt i64 %16, %1
  br i1 %.not33, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15
  %18 = getelementptr inbounds i8, ptr %2, i64 28
  %19 = getelementptr inbounds i8, ptr %2, i64 88
  %20 = getelementptr inbounds i8, ptr %18, i64 %17
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %20, ptr noundef nonnull align 1 dereferenceable(1) %0, i64 %16, i1 false)
  %21 = getelementptr inbounds i8, ptr %0, i64 %16
  %22 = load i32, ptr %19, align 4, !tbaa !5
  %23 = tail call i32 @__bswap_32(i32 noundef %22)
  store i32 %23, ptr %19, align 4, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %2, i64 84
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = tail call i32 @__bswap_32(i32 noundef %25)
  store i32 %26, ptr %24, align 4, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %2, i64 80
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = tail call i32 @__bswap_32(i32 noundef %28)
  store i32 %29, ptr %27, align 4, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %2, i64 76
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = tail call i32 @__bswap_32(i32 noundef %31)
  store i32 %32, ptr %30, align 4, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %2, i64 72
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = tail call i32 @__bswap_32(i32 noundef %34)
  store i32 %35, ptr %33, align 4, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %2, i64 68
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = tail call i32 @__bswap_32(i32 noundef %37)
  store i32 %38, ptr %36, align 4, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %2, i64 64
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = tail call i32 @__bswap_32(i32 noundef %40)
  store i32 %41, ptr %39, align 4, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %2, i64 60
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = tail call i32 @__bswap_32(i32 noundef %43)
  store i32 %44, ptr %42, align 4, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %2, i64 56
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = tail call i32 @__bswap_32(i32 noundef %46)
  store i32 %47, ptr %45, align 4, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %2, i64 52
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = tail call i32 @__bswap_32(i32 noundef %49)
  store i32 %50, ptr %48, align 4, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %2, i64 48
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = tail call i32 @__bswap_32(i32 noundef %52)
  store i32 %53, ptr %51, align 4, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %2, i64 44
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = tail call i32 @__bswap_32(i32 noundef %55)
  store i32 %56, ptr %54, align 4, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %2, i64 40
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = tail call i32 @__bswap_32(i32 noundef %58)
  store i32 %59, ptr %57, align 4, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %2, i64 36
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = tail call i32 @__bswap_32(i32 noundef %61)
  store i32 %62, ptr %60, align 4, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %2, i64 32
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = tail call i32 @__bswap_32(i32 noundef %64)
  store i32 %65, ptr %63, align 4, !tbaa !5
  %66 = load i32, ptr %18, align 4, !tbaa !5
  %67 = tail call i32 @__bswap_32(i32 noundef %66)
  store i32 %67, ptr %18, align 4, !tbaa !5
  %68 = sub i64 %1, %16
  tail call void @sha1_compile(ptr noundef nonnull %2)
  %.not.peel = icmp ult i64 %68, 64
  br i1 %.not.peel, label %._crit_edge, label %.peel.next

.peel.next:                                       ; preds = %.lr.ph, %.peel.next
  %.02637 = phi ptr [ %69, %.peel.next ], [ %21, %.lr.ph ]
  %.02934 = phi i64 [ %102, %.peel.next ], [ %68, %.lr.ph ]
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(64) %18, ptr noundef nonnull align 1 dereferenceable(64) %.02637, i64 64, i1 false)
  %69 = getelementptr inbounds i8, ptr %.02637, i64 64
  %70 = load i32, ptr %19, align 4, !tbaa !5
  %71 = tail call i32 @__bswap_32(i32 noundef %70)
  store i32 %71, ptr %19, align 4, !tbaa !5
  %72 = load i32, ptr %24, align 4, !tbaa !5
  %73 = tail call i32 @__bswap_32(i32 noundef %72)
  store i32 %73, ptr %24, align 4, !tbaa !5
  %74 = load i32, ptr %27, align 4, !tbaa !5
  %75 = tail call i32 @__bswap_32(i32 noundef %74)
  store i32 %75, ptr %27, align 4, !tbaa !5
  %76 = load i32, ptr %30, align 4, !tbaa !5
  %77 = tail call i32 @__bswap_32(i32 noundef %76)
  store i32 %77, ptr %30, align 4, !tbaa !5
  %78 = load i32, ptr %33, align 4, !tbaa !5
  %79 = tail call i32 @__bswap_32(i32 noundef %78)
  store i32 %79, ptr %33, align 4, !tbaa !5
  %80 = load i32, ptr %36, align 4, !tbaa !5
  %81 = tail call i32 @__bswap_32(i32 noundef %80)
  store i32 %81, ptr %36, align 4, !tbaa !5
  %82 = load i32, ptr %39, align 4, !tbaa !5
  %83 = tail call i32 @__bswap_32(i32 noundef %82)
  store i32 %83, ptr %39, align 4, !tbaa !5
  %84 = load i32, ptr %42, align 4, !tbaa !5
  %85 = tail call i32 @__bswap_32(i32 noundef %84)
  store i32 %85, ptr %42, align 4, !tbaa !5
  %86 = load i32, ptr %45, align 4, !tbaa !5
  %87 = tail call i32 @__bswap_32(i32 noundef %86)
  store i32 %87, ptr %45, align 4, !tbaa !5
  %88 = load i32, ptr %48, align 4, !tbaa !5
  %89 = tail call i32 @__bswap_32(i32 noundef %88)
  store i32 %89, ptr %48, align 4, !tbaa !5
  %90 = load i32, ptr %51, align 4, !tbaa !5
  %91 = tail call i32 @__bswap_32(i32 noundef %90)
  store i32 %91, ptr %51, align 4, !tbaa !5
  %92 = load i32, ptr %54, align 4, !tbaa !5
  %93 = tail call i32 @__bswap_32(i32 noundef %92)
  store i32 %93, ptr %54, align 4, !tbaa !5
  %94 = load i32, ptr %57, align 4, !tbaa !5
  %95 = tail call i32 @__bswap_32(i32 noundef %94)
  store i32 %95, ptr %57, align 4, !tbaa !5
  %96 = load i32, ptr %60, align 4, !tbaa !5
  %97 = tail call i32 @__bswap_32(i32 noundef %96)
  store i32 %97, ptr %60, align 4, !tbaa !5
  %98 = load i32, ptr %63, align 4, !tbaa !5
  %99 = tail call i32 @__bswap_32(i32 noundef %98)
  store i32 %99, ptr %63, align 4, !tbaa !5
  %100 = load i32, ptr %18, align 4, !tbaa !5
  %101 = tail call i32 @__bswap_32(i32 noundef %100)
  store i32 %101, ptr %18, align 4, !tbaa !5
  %102 = add i64 %.02934, -64
  tail call void @sha1_compile(ptr noundef nonnull %2)
  %.not = icmp ult i64 %102, 64
  br i1 %.not, label %._crit_edge, label %.peel.next, !llvm.loop !9

._crit_edge:                                      ; preds = %.peel.next, %.lr.ph, %15
  %.029.lcssa = phi i64 [ %1, %15 ], [ %68, %.lr.ph ], [ %102, %.peel.next ]
  %.028.lcssa = phi i64 [ %17, %15 ], [ 0, %.lr.ph ], [ 0, %.peel.next ]
  %.026.lcssa = phi ptr [ %0, %15 ], [ %21, %.lr.ph ], [ %69, %.peel.next ]
  %103 = getelementptr inbounds i8, ptr %2, i64 28
  %104 = getelementptr inbounds i8, ptr %103, i64 %.028.lcssa
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %104, ptr align 1 %.026.lcssa, i64 %.029.lcssa, i1 false)
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__bswap_32(i32 noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass