; LLVM IR from gost-engine/engine :: gosthash (hash_block)

; 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.gost_hash_ctx = type { i64, ptr, i32, [32 x i8], [32 x i8], [32 x i8] }

; Function Attrs: nounwind uwtable
define dso_local i32 @hash_block(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.gost_hash_ctx, ptr %10, i32 0, i32 2
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %82

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.gost_hash_ctx, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = sub nsw i32 32, %17
  store i32 %18, ptr %8, align 4, !tbaa !15
  %19 = load i32, ptr %8, align 4, !tbaa !15
  %20 = zext i32 %19 to i64
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = icmp ugt i64 %20, %21
  br i1 %22, label %23, label %26

23:                                               ; preds = %14
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = trunc i64 %24 to i32
  store i32 %25, ptr %8, align 4, !tbaa !15
  br label %26

26:                                               ; preds = %23, %14
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.gost_hash_ctx, ptr %27, i32 0, i32 5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.gost_hash_ctx, ptr %29, i32 0, i32 2
  %31 = load i32, ptr %30, align 8, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [32 x i8], ptr %28, i64 0, i64 %32
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i32, ptr %8, align 4, !tbaa !15
  %36 = zext i32 %35 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %33, ptr align 1 %34, i64 %36, i1 false)
  %37 = load i32, ptr %8, align 4, !tbaa !15
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.gost_hash_ctx, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !11
  %41 = add i32 %40, %37
  store i32 %41, ptr %39, align 8, !tbaa !11
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.gost_hash_ctx, ptr %42, i32 0, i32 2
  %44 = load i32, ptr %43, align 8, !tbaa !11
  %45 = icmp slt i32 %44, 32
  br i1 %45, label %46, label %47

46:                                               ; preds = %26
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %79

47:                                               ; preds = %26
  %48 = load i32, ptr %8, align 4, !tbaa !15
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = zext i32 %48 to i64
  %51 = getelementptr inbounds i8, ptr %49, i64 %50
  store ptr %51, ptr %6, align 8, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !15
  %53 = zext i32 %52 to i64
  %54 = load i64, ptr %7, align 8, !tbaa !9
  %55 = sub i64 %54, %53
  store i64 %55, ptr %7, align 8, !tbaa !9
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.gost_hash_ctx, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.gost_hash_ctx, ptr %59, i32 0, i32 3
  %61 = getelementptr inbounds [32 x i8], ptr %60, i64 0, i64 0
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.gost_hash_ctx, ptr %62, i32 0, i32 5
  %64 = getelementptr inbounds [32 x i8], ptr %63, i64 0, i64 0
  %65 = call i32 @hash_step(ptr noundef %58, ptr noundef %61, ptr noundef %64)
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.gost_hash_ctx, ptr %66, i32 0, i32 4
  %68 = getelementptr inbounds [32 x i8], ptr %67, i64 0, i64 0
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.gost_hash_ctx, ptr %69, i32 0, i32 5
  %71 = getelementptr inbounds [32 x i8], ptr %70, i64 0, i64 0
  %72 = call i32 @add_blocks(i32 noundef 32, ptr noundef %68, ptr noundef %71)
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.gost_hash_ctx, ptr %73, i32 0, i32 0
  %75 = load i64, ptr %74, align 8, !tbaa !17
  %76 = add nsw i64 %75, 32
  store i64 %76, ptr %74, align 8, !tbaa !17
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.gost_hash_ctx, ptr %77, i32 0, i32 2
  store i32 0, ptr %78, align 8, !tbaa !11
  store i32 0, ptr %9, align 4
  br label %79

79:                                               ; preds = %47, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %80 = load i32, ptr %9, align 4
  switch i32 %80, label %124 [
    i32 0, label %81
    i32 1, label %122
  ]

81:                                               ; preds = %79
  br label %82

82:                                               ; preds = %81, %3
  br label %83

83:                                               ; preds = %86, %82
  %84 = load i64, ptr %7, align 8, !tbaa !9
  %85 = icmp uge i64 %84, 32
  br i1 %85, label %86, label %108

86:                                               ; preds = %83
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.gost_hash_ctx, ptr %87, i32 0, i32 1
  %89 = load ptr, ptr %88, align 8, !tbaa !16
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.gost_hash_ctx, ptr %90, i32 0, i32 3
  %92 = getelementptr inbounds [32 x i8], ptr %91, i64 0, i64 0
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = call i32 @hash_step(ptr noundef %89, ptr noundef %92, ptr noundef %93)
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.gost_hash_ctx, ptr %95, i32 0, i32 4
  %97 = getelementptr inbounds [32 x i8], ptr %96, i64 0, i64 0
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = call i32 @add_blocks(i32 noundef 32, ptr noundef %97, ptr noundef %98)
  %100 = load ptr, ptr %5, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.gost_hash_ctx, ptr %100, i32 0, i32 0
  %102 = load i64, ptr %101, align 8, !tbaa !17
  %103 = add nsw i64 %102, 32
  store i64 %103, ptr %101, align 8, !tbaa !17
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = getelementptr inbounds i8, ptr %104, i64 32
  store ptr %105, ptr %6, align 8, !tbaa !5
  %106 = load i64, ptr %7, align 8, !tbaa !9
  %107 = sub i64 %106, 32
  store i64 %107, ptr %7, align 8, !tbaa !9
  br label %83, !llvm.loop !18

108:                                              ; preds = %83
  %109 = load i64, ptr %7, align 8, !tbaa !9
  %110 = icmp ne i64 %109, 0
  br i1 %110, label %111, label %121

111:                                              ; preds = %108
  %112 = load ptr, ptr %5, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.gost_hash_ctx, ptr %112, i32 0, i32 5
  %114 = getelementptr inbounds [32 x i8], ptr %113, i64 0, i64 0
  %115 = load ptr, ptr %6, align 8, !tbaa !5
  %116 = load i64, ptr %7, align 8, !tbaa !9
  %117 = trunc i64 %116 to i32
  %118 = load ptr, ptr %5, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.gost_hash_ctx, ptr %118, i32 0, i32 2
  store i32 %117, ptr %119, align 8, !tbaa !11
  %120 = sext i32 %117 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %114, ptr align 1 %115, i64 %120, i1 false)
  br label %121

121:                                              ; preds = %111, %108
  store i32 1, ptr %4, align 4
  br label %122

122:                                              ; preds = %121, %79
  %123 = load i32, ptr %4, align 4
  ret i32 %123

124:                                              ; preds = %79
  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: nounwind uwtable
declare hidden i32 @hash_step(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @add_blocks(i32 noundef, ptr noundef, ptr noundef) #0

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

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 = { 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, !14, i64 16}
!12 = !{!"gost_hash_ctx", !13, i64 0, !6, i64 8, !14, i64 16, !7, i64 20, !7, i64 52, !7, i64 84}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!12, !6, i64 8}
!17 = !{!12, !13, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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: nounwind uwtable
define dso_local noundef i32 @hash_block(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %28, label %6

6:                                                ; preds = %3
  %7 = sub nsw i32 32, %5
  %8 = zext i32 %7 to i64
  %9 = icmp ugt i64 %8, %2
  %10 = trunc nuw i64 %2 to i32
  %spec.select = select i1 %9, i32 %10, i32 %7
  %11 = getelementptr inbounds i8, ptr %0, i64 84
  %12 = sext i32 %5 to i64
  %13 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 %12
  %14 = zext i32 %spec.select to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %13, ptr align 1 %1, i64 %14, i1 false)
  %15 = load i32, ptr %4, align 8, !tbaa !5
  %16 = add i32 %15, %spec.select
  store i32 %16, ptr %4, align 8, !tbaa !5
  %17 = icmp slt i32 %16, 32
  br i1 %17, label %45, label %.thread

.thread:                                          ; preds = %6
  %18 = getelementptr inbounds i8, ptr %1, i64 %14
  %19 = sub i64 %2, %14
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = getelementptr inbounds i8, ptr %0, i64 20
  %23 = tail call i32 @hash_step(ptr noundef %21, ptr noundef nonnull %22, ptr noundef nonnull %11)
  %24 = getelementptr inbounds i8, ptr %0, i64 52
  %25 = tail call i32 @add_blocks(i32 noundef 32, ptr noundef nonnull %24, ptr noundef nonnull %11)
  %26 = load i64, ptr %0, align 8, !tbaa !13
  %27 = add nsw i64 %26, 32
  store i64 %27, ptr %0, align 8, !tbaa !13
  store i32 0, ptr %4, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %.thread, %3
  %.141 = phi ptr [ %1, %3 ], [ %18, %.thread ]
  %.1 = phi i64 [ %2, %3 ], [ %19, %.thread ]
  %29 = icmp ugt i64 %.1, 31
  br i1 %29, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %28
  %30 = getelementptr inbounds i8, ptr %0, i64 8
  %31 = getelementptr inbounds i8, ptr %0, i64 20
  %32 = getelementptr inbounds i8, ptr %0, i64 52
  br label %33

33:                                               ; preds = %.lr.ph, %33
  %.252 = phi i64 [ %.1, %.lr.ph ], [ %40, %33 ]
  %.24251 = phi ptr [ %.141, %.lr.ph ], [ %39, %33 ]
  %34 = load ptr, ptr %30, align 8, !tbaa !12
  %35 = tail call i32 @hash_step(ptr noundef %34, ptr noundef nonnull %31, ptr noundef %.24251)
  %36 = tail call i32 @add_blocks(i32 noundef 32, ptr noundef nonnull %32, ptr noundef %.24251)
  %37 = load i64, ptr %0, align 8, !tbaa !13
  %38 = add nsw i64 %37, 32
  store i64 %38, ptr %0, align 8, !tbaa !13
  %39 = getelementptr inbounds i8, ptr %.24251, i64 32
  %40 = add i64 %.252, -32
  %41 = icmp ugt i64 %40, 31
  br i1 %41, label %33, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %33, %28
  %.242.lcssa = phi ptr [ %.141, %28 ], [ %39, %33 ]
  %.2.lcssa = phi i64 [ %.1, %28 ], [ %40, %33 ]
  %.not47 = icmp eq i64 %.2.lcssa, 0
  br i1 %.not47, label %45, label %42

42:                                               ; preds = %._crit_edge
  %43 = getelementptr inbounds i8, ptr %0, i64 84
  %44 = trunc nuw nsw i64 %.2.lcssa to i32
  store i32 %44, ptr %4, align 8, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %43, ptr align 1 %.242.lcssa, i64 %.2.lcssa, i1 false)
  br label %45

45:                                               ; preds = %6, %._crit_edge, %42
  ret i32 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) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @hash_step(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @add_blocks(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

!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, !11, i64 16}
!6 = !{!"gost_hash_ctx", !7, i64 0, !10, i64 8, !11, i64 16, !8, i64 20, !8, i64 52, !8, i64 84}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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