; LLVM IR from Waqar144/simplecrypto-cxx :: simplecrypto-cxx/sha3.ll (Z11sha3_UpdateP8SHA3_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.SHA3_CTX = type { [25 x i64], [24 x i64], i32, i32 }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z11sha3_UpdateP8SHA3_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
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca ptr, 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) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.SHA3_CTX, ptr %12, i32 0, i32 2
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = zext i32 %14 to i64
  store i64 %15, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.SHA3_CTX, ptr %16, i32 0, i32 3
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %19 = zext i32 %18 to i64
  store i64 %19, ptr %8, align 8, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.SHA3_CTX, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = and i32 %22, -2147483648
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %3
  store i32 1, ptr %9, align 4
  br label %121

26:                                               ; preds = %3
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.SHA3_CTX, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = zext i32 %29 to i64
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = add i64 %30, %31
  %33 = load i64, ptr %8, align 8, !tbaa !9
  %34 = urem i64 %32, %33
  %35 = trunc i64 %34 to i32
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.SHA3_CTX, ptr %36, i32 0, i32 2
  store i32 %35, ptr %37, align 8, !tbaa !11
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = icmp ne i64 %38, 0
  br i1 %39, label %40, label %80

40:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = load i64, ptr %7, align 8, !tbaa !9
  %43 = sub i64 %41, %42
  store i64 %43, ptr %10, align 8, !tbaa !9
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.SHA3_CTX, ptr %44, i32 0, i32 1
  %46 = getelementptr inbounds [24 x i64], ptr %45, i64 0, i64 0
  %47 = load i64, ptr %7, align 8, !tbaa !9
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = load i64, ptr %10, align 8, !tbaa !9
  %52 = icmp ult i64 %50, %51
  br i1 %52, label %53, label %55

53:                                               ; preds = %40
  %54 = load i64, ptr %6, align 8, !tbaa !9
  br label %57

55:                                               ; preds = %40
  %56 = load i64, ptr %10, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %55, %53
  %58 = phi i64 [ %54, %53 ], [ %56, %55 ]
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %48, ptr align 1 %49, i64 %58, i1 false)
  %59 = load i64, ptr %6, align 8, !tbaa !9
  %60 = load i64, ptr %10, align 8, !tbaa !9
  %61 = icmp ult i64 %59, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %57
  store i32 1, ptr %9, align 4
  br label %77

63:                                               ; preds = %57
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.SHA3_CTX, ptr %64, i32 0, i32 0
  %66 = getelementptr inbounds [25 x i64], ptr %65, i64 0, i64 0
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.SHA3_CTX, ptr %67, i32 0, i32 1
  %69 = getelementptr inbounds [24 x i64], ptr %68, i64 0, i64 0
  %70 = load i64, ptr %8, align 8, !tbaa !9
  call void @_ZL18sha3_process_blockPmPKmm(ptr noundef %66, ptr noundef %69, i64 noundef %70)
  %71 = load i64, ptr %10, align 8, !tbaa !9
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %72, i64 %71
  store ptr %73, ptr %5, align 8, !tbaa !5
  %74 = load i64, ptr %10, align 8, !tbaa !9
  %75 = load i64, ptr %6, align 8, !tbaa !9
  %76 = sub i64 %75, %74
  store i64 %76, ptr %6, align 8, !tbaa !9
  store i32 0, ptr %9, align 4
  br label %77

77:                                               ; preds = %63, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %78 = load i32, ptr %9, align 4
  switch i32 %78, label %121 [
    i32 0, label %79
  ]

79:                                               ; preds = %77
  br label %80

80:                                               ; preds = %79, %26
  br label %81

81:                                               ; preds = %99, %80
  %82 = load i64, ptr %6, align 8, !tbaa !9
  %83 = load i64, ptr %8, align 8, !tbaa !9
  %84 = icmp uge i64 %82, %83
  br i1 %84, label %85, label %111

85:                                               ; preds = %81
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = call noundef zeroext i1 @_ZL11isAligned64PKh(ptr noundef %86)
  br i1 %87, label %88, label %90

88:                                               ; preds = %85
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %89, ptr %11, align 8, !tbaa !5
  br label %99

90:                                               ; preds = %85
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.SHA3_CTX, ptr %91, i32 0, i32 1
  %93 = getelementptr inbounds [24 x i64], ptr %92, i64 0, i64 0
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = load i64, ptr %8, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %93, ptr align 1 %94, i64 %95, i1 false)
  %96 = load ptr, ptr %4, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.SHA3_CTX, ptr %96, i32 0, i32 1
  %98 = getelementptr inbounds [24 x i64], ptr %97, i64 0, i64 0
  store ptr %98, ptr %11, align 8, !tbaa !5
  br label %99

99:                                               ; preds = %90, %88
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.SHA3_CTX, ptr %100, i32 0, i32 0
  %102 = getelementptr inbounds [25 x i64], ptr %101, i64 0, i64 0
  %103 = load ptr, ptr %11, align 8, !tbaa !5
  %104 = load i64, ptr %8, align 8, !tbaa !9
  call void @_ZL18sha3_process_blockPmPKmm(ptr noundef %102, ptr noundef %103, i64 noundef %104)
  %105 = load i64, ptr %8, align 8, !tbaa !9
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = getelementptr inbounds i8, ptr %106, i64 %105
  store ptr %107, ptr %5, align 8, !tbaa !5
  %108 = load i64, ptr %8, align 8, !tbaa !9
  %109 = load i64, ptr %6, align 8, !tbaa !9
  %110 = sub i64 %109, %108
  store i64 %110, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %81, !llvm.loop !15

111:                                              ; preds = %81
  %112 = load i64, ptr %6, align 8, !tbaa !9
  %113 = icmp ne i64 %112, 0
  br i1 %113, label %114, label %120

114:                                              ; preds = %111
  %115 = load ptr, ptr %4, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.SHA3_CTX, ptr %115, i32 0, i32 1
  %117 = getelementptr inbounds [24 x i64], ptr %116, i64 0, i64 0
  %118 = load ptr, ptr %5, align 8, !tbaa !5
  %119 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %117, ptr align 1 %118, i64 %119, i1 false)
  br label %120

120:                                              ; preds = %114, %111
  store i32 0, ptr %9, align 4
  br label %121

121:                                              ; preds = %120, %77, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %122 = load i32, ptr %9, align 4
  switch i32 %122, label %124 [
    i32 0, label %123
    i32 1, label %123
  ]

123:                                              ; preds = %121, %121
  ret void

124:                                              ; preds = %121
  unreachable
}

; 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: mustprogress uwtable
declare hidden void @_ZL18sha3_process_blockPmPKmm(ptr noundef, ptr noundef, i64 noundef) #0

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL11isAligned64PKh(ptr noundef) #3

attributes #0 = { mustprogress 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 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 392}
!12 = !{!"_ZTS8SHA3_CTX", !7, i64 0, !7, i64 200, !13, i64 392, !13, i64 396}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 396}
!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 uwtable
define dso_local void @_Z11sha3_UpdateP8SHA3_CTXPKhm(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 392
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = zext i32 %5 to i64
  %7 = getelementptr inbounds i8, ptr %0, i64 396
  %8 = load i32, ptr %7, align 4, !tbaa !10
  %9 = zext i32 %8 to i64
  %.not = icmp sgt i32 %5, -1
  br i1 %.not, label %10, label %.thread

10:                                               ; preds = %3
  %11 = add i64 %6, %2
  %12 = urem i64 %11, %9
  %13 = trunc nuw i64 %12 to i32
  store i32 %13, ptr %4, align 8, !tbaa !5
  %.not55 = icmp eq i32 %5, 0
  br i1 %.not55, label %22, label %14

14:                                               ; preds = %10
  %15 = sub nsw i64 %9, %6
  %16 = getelementptr inbounds i8, ptr %0, i64 200
  %17 = getelementptr inbounds i8, ptr %16, i64 %6
  %.not56 = icmp ugt i64 %15, %2
  %18 = tail call i64 @llvm.umin.i64(i64 %15, i64 %2)
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %17, ptr align 1 %1, i64 %18, i1 false)
  br i1 %.not56, label %.thread, label %19

19:                                               ; preds = %14
  tail call void @_ZL18sha3_process_blockPmPKmm(ptr noundef nonnull %0, ptr noundef nonnull %16, i64 noundef %9)
  %20 = getelementptr inbounds i8, ptr %1, i64 %15
  %21 = sub i64 %2, %15
  br label %22

22:                                               ; preds = %19, %10
  %.148 = phi i64 [ %21, %19 ], [ %2, %10 ]
  %.1 = phi ptr [ %20, %19 ], [ %1, %10 ]
  %.not5761 = icmp ult i64 %.148, %9
  br i1 %.not5761, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %22
  %23 = getelementptr inbounds i8, ptr %0, i64 200
  br label %24

24:                                               ; preds = %.lr.ph, %27
  %.263 = phi ptr [ %.1, %.lr.ph ], [ %28, %27 ]
  %.24962 = phi i64 [ %.148, %.lr.ph ], [ %29, %27 ]
  %25 = tail call noundef zeroext i1 @_ZL11isAligned64PKh(ptr noundef %.263)
  br i1 %25, label %27, label %26

26:                                               ; preds = %24
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %23, ptr align 1 %.263, i64 %9, i1 false)
  br label %27

27:                                               ; preds = %24, %26
  %.0 = phi ptr [ %23, %26 ], [ %.263, %24 ]
  tail call void @_ZL18sha3_process_blockPmPKmm(ptr noundef %0, ptr noundef %.0, i64 noundef %9)
  %28 = getelementptr inbounds i8, ptr %.263, i64 %9
  %29 = sub i64 %.24962, %9
  %.not57 = icmp ult i64 %29, %9
  br i1 %.not57, label %._crit_edge, label %24, !llvm.loop !11

._crit_edge:                                      ; preds = %27, %22
  %.249.lcssa = phi i64 [ %.148, %22 ], [ %29, %27 ]
  %.2.lcssa = phi ptr [ %.1, %22 ], [ %28, %27 ]
  %.not58 = icmp eq i64 %.249.lcssa, 0
  br i1 %.not58, label %.thread, label %30

30:                                               ; preds = %._crit_edge
  %31 = getelementptr inbounds i8, ptr %0, i64 200
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %31, ptr align 1 %.2.lcssa, i64 %.249.lcssa, i1 false)
  br label %.thread

.thread:                                          ; preds = %14, %._crit_edge, %30, %3
  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: mustprogress uwtable
declare hidden void @_ZL18sha3_process_blockPmPKmm(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL11isAligned64PKh(ptr noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #3

attributes #0 = { mustprogress 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 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 392}
!6 = !{!"_ZTS8SHA3_CTX", !7, i64 0, !7, i64 200, !9, i64 392, !9, i64 396}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !9, i64 396}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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