; LLVM IR from gost-engine/engine :: gost_grasshopper_core (grasshopper_set_encrypt_key)

; 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"

%union.grasshopper_w128_t = type { [2 x i64] }
%struct.grasshopper_key_t = type { %union.grasshopper_w256_t }
%union.grasshopper_w256_t = type { [4 x i64] }
%struct.grasshopper_round_keys_t = type { [10 x %union.grasshopper_w128_t] }

@grasshopper_pi = external constant [256 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local void @grasshopper_set_encrypt_key(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %union.grasshopper_w128_t, align 8
  %6 = alloca %union.grasshopper_w128_t, align 8
  %7 = alloca %union.grasshopper_w128_t, align 8
  %8 = alloca %union.grasshopper_w128_t, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  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 16, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %34, %2
  %12 = load i32, ptr %9, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 16
  br i1 %13, label %14, label %37

14:                                               ; preds = %11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.grasshopper_key_t, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [32 x i8], ptr %16, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 %22
  store i8 %20, ptr %23, align 1, !tbaa !11
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.grasshopper_key_t, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = add nsw i32 %26, 16
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [32 x i8], ptr %25, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 %32
  store i8 %30, ptr %33, align 1, !tbaa !11
  br label %34

34:                                               ; preds = %14
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %9, align 4, !tbaa !9
  br label %11, !llvm.loop !12

37:                                               ; preds = %11
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.grasshopper_round_keys_t, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds [10 x %union.grasshopper_w128_t], ptr %39, i64 0, i64 0
  call void @grasshopper_copy128(ptr noundef %40, ptr noundef %6)
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.grasshopper_round_keys_t, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds [10 x %union.grasshopper_w128_t], ptr %42, i64 0, i64 1
  call void @grasshopper_copy128(ptr noundef %43, ptr noundef %7)
  store i32 1, ptr %9, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %69, %37
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = icmp sle i32 %45, 32
  br i1 %46, label %47, label %72

47:                                               ; preds = %44
  call void @grasshopper_zero128(ptr noundef %5)
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = trunc i32 %48 to i8
  %50 = getelementptr inbounds [16 x i8], ptr %5, i64 0, i64 15
  store i8 %49, ptr %50, align 1, !tbaa !11
  call void @grasshopper_l(ptr noundef %5)
  call void @grasshopper_plus128(ptr noundef %8, ptr noundef %6, ptr noundef %5)
  call void @grasshopper_convert128(ptr noundef %8, ptr noundef @grasshopper_pi)
  call void @grasshopper_l(ptr noundef %8)
  call void @grasshopper_append128(ptr noundef %8, ptr noundef %7)
  call void @grasshopper_copy128(ptr noundef %7, ptr noundef %6)
  call void @grasshopper_copy128(ptr noundef %6, ptr noundef %8)
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = and i32 %51, 7
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %68

54:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = ashr i32 %55, 2
  store i32 %56, ptr %10, align 4, !tbaa !9
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.grasshopper_round_keys_t, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [10 x %union.grasshopper_w128_t], ptr %58, i64 0, i64 %60
  call void @grasshopper_copy128(ptr noundef %61, ptr noundef %6)
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.grasshopper_round_keys_t, ptr %62, i32 0, i32 0
  %64 = load i32, ptr %10, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [10 x %union.grasshopper_w128_t], ptr %63, i64 0, i64 %66
  call void @grasshopper_copy128(ptr noundef %67, ptr noundef %7)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %68

68:                                               ; preds = %54, %47
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %9, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %9, align 4, !tbaa !9
  br label %44, !llvm.loop !14

72:                                               ; preds = %44
  call void @grasshopper_zero128(ptr noundef %5)
  call void @grasshopper_zero128(ptr noundef %6)
  call void @grasshopper_zero128(ptr noundef %7)
  call void @grasshopper_zero128(ptr noundef %8)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #3
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @grasshopper_copy128(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @grasshopper_zero128(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @grasshopper_l(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @grasshopper_plus128(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @grasshopper_convert128(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @grasshopper_append128(ptr noundef, ptr noundef) #2

; 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 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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"

%union.grasshopper_w128_t = type { [2 x i64] }

@grasshopper_pi = external constant [256 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local void @grasshopper_set_encrypt_key(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca %union.grasshopper_w128_t, align 8
  %4 = alloca %union.grasshopper_w128_t, align 8
  %5 = alloca %union.grasshopper_w128_t, align 8
  %6 = alloca %union.grasshopper_w128_t, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 1 dereferenceable(16) %1, i64 16, i1 false), !tbaa !5
  %scevgep = getelementptr i8, ptr %1, i64 16
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 1 dereferenceable(16) %scevgep, i64 16, i1 false), !tbaa !5
  call void @grasshopper_copy128(ptr noundef %0, ptr noundef nonnull %4)
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  call void @grasshopper_copy128(ptr noundef nonnull %7, ptr noundef nonnull %5)
  %8 = getelementptr inbounds i8, ptr %3, i64 15
  br label %9

9:                                                ; preds = %2, %20
  %.119 = phi i32 [ 1, %2 ], [ %21, %20 ]
  call void @grasshopper_zero128(ptr noundef nonnull %3)
  %10 = trunc nuw i32 %.119 to i8
  store i8 %10, ptr %8, align 1, !tbaa !5
  call void @grasshopper_l(ptr noundef nonnull %3)
  call void @grasshopper_plus128(ptr noundef nonnull %6, ptr noundef nonnull %4, ptr noundef nonnull %3)
  call void @grasshopper_convert128(ptr noundef nonnull %6, ptr noundef nonnull @grasshopper_pi)
  call void @grasshopper_l(ptr noundef nonnull %6)
  call void @grasshopper_append128(ptr noundef nonnull %6, ptr noundef nonnull %5)
  call void @grasshopper_copy128(ptr noundef nonnull %5, ptr noundef nonnull %4)
  call void @grasshopper_copy128(ptr noundef nonnull %4, ptr noundef nonnull %6)
  %11 = and i32 %.119, 7
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %20

13:                                               ; preds = %9
  %14 = lshr exact i32 %.119, 2
  %15 = zext nneg i32 %14 to i64
  %16 = getelementptr inbounds [10 x %union.grasshopper_w128_t], ptr %0, i64 0, i64 %15
  call void @grasshopper_copy128(ptr noundef nonnull %16, ptr noundef nonnull %4)
  %17 = or disjoint i32 %14, 1
  %18 = zext nneg i32 %17 to i64
  %19 = getelementptr inbounds [10 x %union.grasshopper_w128_t], ptr %0, i64 0, i64 %18
  call void @grasshopper_copy128(ptr noundef nonnull %19, ptr noundef nonnull %5)
  br label %20

20:                                               ; preds = %9, %13
  %21 = add nuw nsw i32 %.119, 1
  %exitcond.not = icmp eq i32 %21, 33
  br i1 %exitcond.not, label %22, label %9, !llvm.loop !8

22:                                               ; preds = %20
  call void @grasshopper_zero128(ptr noundef nonnull %3)
  call void @grasshopper_zero128(ptr noundef nonnull %4)
  call void @grasshopper_zero128(ptr noundef nonnull %5)
  call void @grasshopper_zero128(ptr noundef nonnull %6)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @grasshopper_copy128(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @grasshopper_zero128(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @grasshopper_l(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @grasshopper_plus128(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @grasshopper_convert128(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @grasshopper_append128(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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) #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 = { mustprogress nocallback nofree nosync 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" }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass