; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (gost34311)

; 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.ByteArray_st = type { ptr, i64 }
%struct.Gost34311Ctx_st = type { ptr, [32 x i8], i64, [8 x i32], [32 x i8], [8 x i32], [32 x i8] }

@.str = external hidden unnamed_addr constant [19 x i8], align 1

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

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #1

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) #1

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

; 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
define dso_local i32 @gost34311_update(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = 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 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call i64 @ba_get_len(ptr noundef %9)
  store i64 %10, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %11

11:                                               ; preds = %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %16, label %14

14:                                               ; preds = %11
  store i32 2, ptr %8, align 4, !tbaa !11
  %15 = load i32, ptr %8, align 4, !tbaa !11
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 351, i32 noundef %15, ptr noundef null)
  br label %84

16:                                               ; preds = %11
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %24, label %22

22:                                               ; preds = %19
  store i32 2, ptr %8, align 4, !tbaa !11
  %23 = load i32, ptr %8, align 4, !tbaa !11
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 352, i32 noundef %23, ptr noundef null)
  br label %84

24:                                               ; preds = %19
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ByteArray_st, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  store ptr %29, ptr %5, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %80, %26
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Gost34311Ctx_st, ptr %32, i32 0, i32 2
  %34 = load i64, ptr %33, align 8, !tbaa !15
  %35 = sub i64 32, %34
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = icmp ugt i64 %35, %36
  br i1 %37, label %38, label %40

38:                                               ; preds = %31
  %39 = load i64, ptr %6, align 8, !tbaa !9
  br label %45

40:                                               ; preds = %31
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Gost34311Ctx_st, ptr %41, i32 0, i32 2
  %43 = load i64, ptr %42, align 8, !tbaa !15
  %44 = sub i64 32, %43
  br label %45

45:                                               ; preds = %40, %38
  %46 = phi i64 [ %39, %38 ], [ %44, %40 ]
  store i64 %46, ptr %7, align 8, !tbaa !9
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Gost34311Ctx_st, ptr %47, i32 0, i32 1
  %49 = getelementptr inbounds [32 x i8], ptr %48, i64 0, i64 0
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Gost34311Ctx_st, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !15
  %53 = getelementptr inbounds i8, ptr %49, i64 %52
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %53, ptr align 1 %54, i64 %55, i1 false)
  %56 = load i64, ptr %7, align 8, !tbaa !9
  %57 = load i64, ptr %6, align 8, !tbaa !9
  %58 = sub i64 %57, %56
  store i64 %58, ptr %6, align 8, !tbaa !9
  %59 = load i64, ptr %7, align 8, !tbaa !9
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Gost34311Ctx_st, ptr %60, i32 0, i32 2
  %62 = load i64, ptr %61, align 8, !tbaa !15
  %63 = add i64 %62, %59
  store i64 %63, ptr %61, align 8, !tbaa !15
  %64 = load i64, ptr %7, align 8, !tbaa !9
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %65, i64 %64
  store ptr %66, ptr %5, align 8, !tbaa !5
  %67 = load i64, ptr %6, align 8, !tbaa !9
  %68 = icmp eq i64 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %45
  br label %83

70:                                               ; preds = %45
  br label %71

71:                                               ; preds = %70
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = call i32 @update(ptr noundef %72)
  store i32 %73, ptr %8, align 4, !tbaa !11
  %74 = load i32, ptr %8, align 4, !tbaa !11
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %78

76:                                               ; preds = %71
  %77 = load i32, ptr %8, align 4, !tbaa !11
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 367, i32 noundef %77)
  br label %84

78:                                               ; preds = %71
  br label %79

79:                                               ; preds = %78
  br label %80

80:                                               ; preds = %79
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.Gost34311Ctx_st, ptr %81, i32 0, i32 2
  store i64 0, ptr %82, align 8, !tbaa !15
  br label %30

83:                                               ; preds = %69
  br label %84

84:                                               ; preds = %83, %76, %22, %14
  %85 = load i32, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret i32 %85
}

declare i64 @ba_get_len(ptr noundef) #1

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 #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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"ByteArray_st", !6, i64 0, !10, i64 8}
!15 = !{!16, !10, i64 40}
!16 = !{!"Gost34311Ctx_st", !6, i64 0, !7, i64 8, !10, i64 40, !7, i64 48, !7, i64 80, !7, i64 112, !7, i64 144}


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

@.str = external hidden unnamed_addr constant [19 x i8], align 1

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 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: nounwind uwtable
define dso_local i32 @gost34311_update(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = tail call i64 @ba_get_len(ptr noundef %1) #4
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %5

4:                                                ; preds = %2
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 351, i32 noundef 2, ptr noundef null) #4
  br label %.loopexit

5:                                                ; preds = %2
  %.not33 = icmp eq ptr %1, null
  br i1 %.not33, label %6, label %7

6:                                                ; preds = %5
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 352, i32 noundef 2, ptr noundef null) #4
  br label %.loopexit

7:                                                ; preds = %5
  %8 = load ptr, ptr %1, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i64, ptr %9, align 8, !tbaa !11
  %12 = sub i64 32, %11
  %.025.35 = tail call i64 @llvm.umin.i64(i64 %12, i64 %3)
  %13 = getelementptr inbounds i8, ptr %10, i64 %11
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %13, ptr align 1 %8, i64 %.025.35, i1 false)
  %14 = sub i64 %3, %.025.35
  %15 = load i64, ptr %9, align 8, !tbaa !11
  %16 = add i64 %15, %.025.35
  store i64 %16, ptr %9, align 8, !tbaa !11
  %17 = icmp eq i64 %14, 0
  br i1 %17, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %7
  %18 = getelementptr inbounds i8, ptr %8, i64 %.025.35
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %23
  %19 = phi ptr [ %27, %23 ], [ %18, %.lr.ph.preheader ]
  %20 = phi i64 [ %24, %23 ], [ %14, %.lr.ph.preheader ]
  %21 = tail call i32 @update(ptr noundef nonnull %0)
  %.not34 = icmp eq i32 %21, 0
  br i1 %.not34, label %23, label %22

22:                                               ; preds = %.lr.ph
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 367, i32 noundef %21) #4
  br label %.loopexit

23:                                               ; preds = %.lr.ph
  store i64 0, ptr %9, align 8, !tbaa !11
  %.025. = tail call i64 @llvm.umin.i64(i64 %20, i64 32)
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %10, ptr noundef nonnull align 1 dereferenceable(1) %19, i64 %.025., i1 false)
  %24 = sub i64 %20, %.025.
  %25 = load i64, ptr %9, align 8, !tbaa !11
  %26 = add i64 %25, %.025.
  store i64 %26, ptr %9, align 8, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %19, i64 %.025.
  %28 = icmp eq i64 %24, 0
  br i1 %28, label %.loopexit, label %.lr.ph

.loopexit:                                        ; preds = %23, %7, %22, %6, %4
  %.1 = phi i32 [ %21, %22 ], [ 2, %6 ], [ 2, %4 ], [ 0, %7 ], [ 0, %23 ]
  ret i32 %.1
}

declare i64 @ba_get_len(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @update(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 = { "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 = { 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) }
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 = !{!"ByteArray_st", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!12, !10, i64 40}
!12 = !{!"Gost34311Ctx_st", !7, i64 0, !8, i64 8, !10, i64 40, !8, i64 48, !8, i64 80, !8, i64 112, !8, i64 144}


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