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

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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: nounwind uwtable
declare hidden i32 @hash_step(ptr noundef, ptr noundef, ptr noundef) #3

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

; 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 i32 @finish_hash(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [32 x i8], align 16
  %6 = alloca [32 x i8], align 16
  %7 = alloca [32 x i8], align 16
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.gost_hash_ctx, ptr %10, i32 0, i32 0
  %12 = load i64, ptr %11, align 8, !tbaa !9
  store i64 %12, ptr %8, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %13 = getelementptr inbounds [32 x i8], ptr %6, i64 0, i64 0
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.gost_hash_ctx, ptr %14, i32 0, i32 3
  %16 = getelementptr inbounds [32 x i8], ptr %15, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %13, ptr align 4 %16, i64 32, i1 false)
  %17 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.gost_hash_ctx, ptr %18, i32 0, i32 4
  %20 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %17, ptr align 4 %20, i64 32, i1 false)
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.gost_hash_ctx, ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !14
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %50

25:                                               ; preds = %2
  %26 = getelementptr inbounds [32 x i8], ptr %5, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %26, i8 0, i64 32, i1 false)
  %27 = getelementptr inbounds [32 x i8], ptr %5, i64 0, i64 0
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.gost_hash_ctx, ptr %28, i32 0, i32 5
  %30 = getelementptr inbounds [32 x i8], ptr %29, i64 0, i64 0
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.gost_hash_ctx, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 8, !tbaa !14
  %34 = sext i32 %33 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %27, ptr align 4 %30, i64 %34, i1 false)
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.gost_hash_ctx, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = getelementptr inbounds [32 x i8], ptr %6, i64 0, i64 0
  %39 = getelementptr inbounds [32 x i8], ptr %5, i64 0, i64 0
  %40 = call i32 @hash_step(ptr noundef %37, ptr noundef %38, ptr noundef %39)
  %41 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  %42 = getelementptr inbounds [32 x i8], ptr %5, i64 0, i64 0
  %43 = call i32 @add_blocks(i32 noundef 32, ptr noundef %41, ptr noundef %42)
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.gost_hash_ctx, ptr %44, i32 0, i32 2
  %46 = load i32, ptr %45, align 8, !tbaa !14
  %47 = sext i32 %46 to i64
  %48 = load i64, ptr %8, align 8, !tbaa !13
  %49 = add nsw i64 %48, %47
  store i64 %49, ptr %8, align 8, !tbaa !13
  br label %50

50:                                               ; preds = %25, %2
  %51 = getelementptr inbounds [32 x i8], ptr %5, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %51, i8 0, i64 32, i1 false)
  %52 = load i64, ptr %8, align 8, !tbaa !13
  %53 = icmp eq i64 %52, 0
  br i1 %53, label %54, label %61

54:                                               ; preds = %50
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.gost_hash_ctx, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !15
  %58 = getelementptr inbounds [32 x i8], ptr %6, i64 0, i64 0
  %59 = getelementptr inbounds [32 x i8], ptr %5, i64 0, i64 0
  %60 = call i32 @hash_step(ptr noundef %57, ptr noundef %58, ptr noundef %59)
  br label %61

61:                                               ; preds = %54, %50
  %62 = getelementptr inbounds [32 x i8], ptr %5, i64 0, i64 0
  store ptr %62, ptr %9, align 8, !tbaa !5
  %63 = load i64, ptr %8, align 8, !tbaa !13
  %64 = shl i64 %63, 3
  store i64 %64, ptr %8, align 8, !tbaa !13
  br label %65

65:                                               ; preds = %68, %61
  %66 = load i64, ptr %8, align 8, !tbaa !13
  %67 = icmp sgt i64 %66, 0
  br i1 %67, label %68, label %76

68:                                               ; preds = %65
  %69 = load i64, ptr %8, align 8, !tbaa !13
  %70 = and i64 %69, 255
  %71 = trunc i64 %70 to i8
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %72, i32 1
  store ptr %73, ptr %9, align 8, !tbaa !5
  store i8 %71, ptr %72, align 1, !tbaa !16
  %74 = load i64, ptr %8, align 8, !tbaa !13
  %75 = ashr i64 %74, 8
  store i64 %75, ptr %8, align 8, !tbaa !13
  br label %65, !llvm.loop !17

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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, !11, i64 0}
!10 = !{!"gost_hash_ctx", !11, i64 0, !6, i64 8, !12, i64 16, !7, i64 20, !7, i64 52, !7, i64 84}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !12, i64 16}
!15 = !{!10, !6, i64 8}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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 nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

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

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

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

; Function Attrs: mustprogress 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 noundef i32 @finish_hash(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #3 {
  %3 = alloca [32 x i8], align 16
  %4 = alloca [32 x i8], align 16
  %5 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  %6 = load i64, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 20
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %4, ptr noundef nonnull align 4 dereferenceable(32) %7, i64 32, i1 false)
  %8 = getelementptr inbounds i8, ptr %0, i64 52
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %5, ptr noundef nonnull align 4 dereferenceable(32) %8, i64 32, i1 false)
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load i32, ptr %9, align 8, !tbaa !12
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %25, label %11

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 84
  %13 = sext i32 %10 to i64
  %14 = icmp ugt i32 %10, 31
  %15 = sub nsw i64 32, %13
  %16 = select i1 %14, i64 0, i64 %15
  %17 = getelementptr i8, ptr %3, i64 %13
  call void @llvm.memset.p0.i64(ptr align 1 %17, i8 0, i64 %16, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %3, ptr nonnull align 4 %12, i64 %13, i1 false)
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = call i32 @hash_step(ptr noundef %19, ptr noundef nonnull %4, ptr noundef nonnull %3)
  %21 = call i32 @add_blocks(i32 noundef 32, ptr noundef nonnull %5, ptr noundef nonnull %3)
  %22 = load i32, ptr %9, align 8, !tbaa !12
  %23 = sext i32 %22 to i64
  %24 = add nsw i64 %6, %23
  br label %25

25:                                               ; preds = %11, %2
  %.018 = phi i64 [ %24, %11 ], [ %6, %2 ]
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %3, i8 0, i64 32, i1 false)
  %26 = icmp eq i64 %.018, 0
  br i1 %26, label %.thread, label %30

.thread:                                          ; preds = %25
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = call i32 @hash_step(ptr noundef %28, ptr noundef nonnull %4, ptr noundef nonnull %3)
  br label %._crit_edge

30:                                               ; preds = %25
  %31 = shl i64 %.018, 3
  %32 = icmp sgt i64 %31, 0
  br i1 %32, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %30, %.lr.ph
  %.020 = phi ptr [ %34, %.lr.ph ], [ %3, %30 ]
  %.119 = phi i64 [ %35, %.lr.ph ], [ %31, %30 ]
  %33 = trunc i64 %.119 to i8
  %34 = getelementptr inbounds i8, ptr %.020, i64 1
  store i8 %33, ptr %.020, align 1, !tbaa !14
  %35 = lshr i64 %.119, 8
  %.not21 = icmp ult i64 %.119, 256
  br i1 %.not21, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %.thread, %30
  %36 = getelementptr inbounds i8, ptr %0, i64 8
  %37 = load ptr, ptr %36, align 8, !tbaa !13
  %38 = call i32 @hash_step(ptr noundef %37, ptr noundef nonnull %4, ptr noundef nonnull %3)
  %39 = load ptr, ptr %36, align 8, !tbaa !13
  %40 = call i32 @hash_step(ptr noundef %39, ptr noundef nonnull %4, ptr noundef nonnull %5)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %1, ptr noundef nonnull align 16 dereferenceable(32) %4, i64 32, i1 false)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  ret i32 1
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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, !7, i64 0}
!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, !11, i64 16}
!13 = !{!6, !10, i64 8}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass