; LLVM IR from intuitive-robots/mdt_policy :: pyhash-0.9.3/src/smhasher/sha1.ll (Z11SHA1_UpdateP8SHA1_CTXPKhm)

; 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 { [5 x i32], [2 x i32], [64 x i8] }

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z11SHA1_UpdateP8SHA1_CTXPKhm(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.SHA1_CTX, ptr %9, i32 0, i32 1
  %11 = getelementptr inbounds [2 x i32], ptr %10, i64 0, i64 0
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = zext i32 %12 to i64
  store i64 %13, ptr %8, align 8, !tbaa !9
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = shl i64 %14, 3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.SHA1_CTX, ptr %16, i32 0, i32 1
  %18 = getelementptr inbounds [2 x i32], ptr %17, i64 0, i64 0
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = zext i32 %19 to i64
  %21 = add i64 %20, %15
  %22 = trunc i64 %21 to i32
  store i32 %22, ptr %18, align 4, !tbaa !11
  %23 = zext i32 %22 to i64
  %24 = load i64, ptr %8, align 8, !tbaa !9
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %26, label %32

26:                                               ; preds = %3
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.SHA1_CTX, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds [2 x i32], ptr %28, i64 0, i64 1
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = add i32 %30, 1
  store i32 %31, ptr %29, align 4, !tbaa !11
  br label %32

32:                                               ; preds = %26, %3
  %33 = load i64, ptr %6, align 8, !tbaa !9
  %34 = lshr i64 %33, 29
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.SHA1_CTX, ptr %35, i32 0, i32 1
  %37 = getelementptr inbounds [2 x i32], ptr %36, i64 0, i64 1
  %38 = load i32, ptr %37, align 4, !tbaa !11
  %39 = zext i32 %38 to i64
  %40 = add i64 %39, %34
  %41 = trunc i64 %40 to i32
  store i32 %41, ptr %37, align 4, !tbaa !11
  %42 = load i64, ptr %8, align 8, !tbaa !9
  %43 = lshr i64 %42, 3
  %44 = and i64 %43, 63
  store i64 %44, ptr %8, align 8, !tbaa !9
  %45 = load i64, ptr %8, align 8, !tbaa !9
  %46 = load i64, ptr %6, align 8, !tbaa !9
  %47 = add i64 %45, %46
  %48 = icmp ugt i64 %47, 63
  br i1 %48, label %49, label %79

49:                                               ; preds = %32
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.SHA1_CTX, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %8, align 8, !tbaa !9
  %53 = getelementptr inbounds [64 x i8], ptr %51, i64 0, i64 %52
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i64, ptr %8, align 8, !tbaa !9
  %56 = sub i64 64, %55
  store i64 %56, ptr %7, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %53, ptr align 1 %54, i64 %56, i1 false)
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.SHA1_CTX, ptr %57, i32 0, i32 0
  %59 = getelementptr inbounds [5 x i32], ptr %58, i64 0, i64 0
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.SHA1_CTX, ptr %60, i32 0, i32 2
  %62 = getelementptr inbounds [64 x i8], ptr %61, i64 0, i64 0
  call void @_Z14SHA1_TransformPjPKh(ptr noundef %59, ptr noundef %62)
  br label %63

63:                                               ; preds = %75, %49
  %64 = load i64, ptr %7, align 8, !tbaa !9
  %65 = add i64 %64, 63
  %66 = load i64, ptr %6, align 8, !tbaa !9
  %67 = icmp ult i64 %65, %66
  br i1 %67, label %68, label %78

68:                                               ; preds = %63
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.SHA1_CTX, ptr %69, i32 0, i32 0
  %71 = getelementptr inbounds [5 x i32], ptr %70, i64 0, i64 0
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = load i64, ptr %7, align 8, !tbaa !9
  %74 = getelementptr inbounds i8, ptr %72, i64 %73
  call void @_Z14SHA1_TransformPjPKh(ptr noundef %71, ptr noundef %74)
  br label %75

75:                                               ; preds = %68
  %76 = load i64, ptr %7, align 8, !tbaa !9
  %77 = add i64 %76, 64
  store i64 %77, ptr %7, align 8, !tbaa !9
  br label %63, !llvm.loop !13

78:                                               ; preds = %63
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %80

79:                                               ; preds = %32
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %80

80:                                               ; preds = %79, %78
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.SHA1_CTX, ptr %81, i32 0, i32 2
  %83 = load i64, ptr %8, align 8, !tbaa !9
  %84 = getelementptr inbounds [64 x i8], ptr %82, i64 0, i64 %83
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = load i64, ptr %7, align 8, !tbaa !9
  %87 = getelementptr inbounds i8, ptr %85, i64 %86
  %88 = load i64, ptr %6, align 8, !tbaa !9
  %89 = load i64, ptr %7, align 8, !tbaa !9
  %90 = sub i64 %88, %89
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %84, ptr align 1 %87, i64 %90, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

attributes #0 = { mustprogress 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 = { 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++ 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"}


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

; 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: mustprogress nounwind uwtable
define dso_local void @_Z11SHA1_UpdateP8SHA1_CTXPKhm(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
._crit_edge:
  %3 = getelementptr inbounds i8, ptr %0, i64 20
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.tr = trunc i64 %2 to i32
  %5 = shl i32 %.tr, 3
  %6 = add i32 %4, %5
  store i32 %6, ptr %3, align 4, !tbaa !5
  %7 = icmp ult i32 %6, %4
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = zext i1 %7 to i32
  %11 = add i32 %9, %10
  %12 = lshr i64 %2, 29
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = trunc i64 %12 to i32
  %15 = add i32 %11, %14
  store i32 %15, ptr %13, align 4, !tbaa !5
  %16 = lshr i32 %4, 3
  %17 = and i32 %16, 63
  %18 = zext nneg i32 %17 to i64
  %19 = add i64 %18, %2
  %20 = icmp ugt i64 %19, 63
  br i1 %20, label %21, label %.loopexit

21:                                               ; preds = %._crit_edge
  %22 = getelementptr inbounds i8, ptr %0, i64 28
  %23 = getelementptr inbounds [64 x i8], ptr %22, i64 0, i64 %18
  %24 = sub nuw nsw i64 64, %18
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %23, ptr noundef nonnull align 1 dereferenceable(1) %1, i64 %24, i1 false)
  tail call void @_Z14SHA1_TransformPjPKh(ptr noundef nonnull %0, ptr noundef nonnull %22)
  %25 = xor i64 %18, 127
  %26 = icmp ult i64 %25, %2
  br i1 %26, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %21, %.lr.ph
  %.02728 = phi i64 [ %28, %.lr.ph ], [ %24, %21 ]
  %27 = getelementptr inbounds i8, ptr %1, i64 %.02728
  tail call void @_Z14SHA1_TransformPjPKh(ptr noundef %0, ptr noundef %27)
  %28 = add i64 %.02728, 64
  %29 = add i64 %.02728, 127
  %30 = icmp ult i64 %29, %2
  br i1 %30, label %.lr.ph, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph, %21, %._crit_edge
  %.1 = phi i64 [ 0, %._crit_edge ], [ %24, %21 ], [ %28, %.lr.ph ]
  %.0 = phi i64 [ %18, %._crit_edge ], [ 0, %21 ], [ 0, %.lr.ph ]
  %31 = getelementptr inbounds i8, ptr %0, i64 28
  %32 = getelementptr inbounds [64 x i8], ptr %31, i64 0, i64 %.0
  %33 = getelementptr inbounds i8, ptr %1, i64 %.1
  %34 = sub i64 %2, %.1
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %32, ptr align 1 %33, i64 %34, i1 false)
  ret void
}

attributes #0 = { mustprogress 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) }

!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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass