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

; 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.Gost28147Ctx_st = type { i32, i8, ptr, [1024 x i32], [8 x i32], %union.anon }
%union.anon = type { %struct.Gost28147CtrCtx_st }
%struct.Gost28147CtrCtx_st = type { i64, [24 x i8], [6 x i32] }
%struct.Gost28147MacCtx_st = type { i64, [8 x i8] }

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

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

; 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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

declare i32 @uint8_to_uint32(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

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

declare i32 @uint32_to_uint8(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

declare ptr @ba_alloc_from_uint8(ptr noundef, i64 noundef) #2

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

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

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

11:                                               ; preds = %8
  store i32 2, ptr %7, align 4, !tbaa !9
  %12 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 1121, i32 noundef %12, ptr noundef null)
  br label %102

13:                                               ; preds = %8
  br label %14

14:                                               ; preds = %13
  br label %15

15:                                               ; preds = %14
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %21, label %19

19:                                               ; preds = %16
  store i32 2, ptr %7, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 1122, i32 noundef %20, ptr noundef null)
  br label %102

21:                                               ; preds = %16
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Gost28147Ctx_st, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = icmp ne i32 %26, 4
  br i1 %27, label %28, label %33

28:                                               ; preds = %23
  br label %29

29:                                               ; preds = %28
  store i32 14, ptr %7, align 4, !tbaa !9
  %30 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 1125, i32 noundef %30, ptr noundef null)
  br label %102

31:                                               ; No predecessors!
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32, %23
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Gost28147Ctx_st, ptr %34, i32 0, i32 1
  %36 = load i8, ptr %35, align 4, !tbaa !14, !range !15, !noundef !16
  %37 = trunc i8 %36 to i1
  br i1 %37, label %43, label %38

38:                                               ; preds = %33
  br label %39

39:                                               ; preds = %38
  store i32 4, ptr %7, align 4, !tbaa !9
  %40 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 1129, i32 noundef %40, ptr noundef null)
  br label %102

41:                                               ; No predecessors!
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42, %33
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Gost28147Ctx_st, ptr %44, i32 0, i32 5
  store ptr %45, ptr %5, align 8, !tbaa !5
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Gost28147MacCtx_st, ptr %46, i32 0, i32 0
  %48 = load i64, ptr %47, align 8, !tbaa !17
  %49 = icmp ne i64 %48, 0
  br i1 %49, label %50, label %86

50:                                               ; preds = %43
  br label %51

51:                                               ; preds = %50
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Gost28147MacCtx_st, ptr %52, i32 0, i32 1
  %54 = getelementptr inbounds [8 x i8], ptr %53, i64 0, i64 0
  %55 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 0
  %56 = call i32 @uint8_to_uint32(ptr noundef %54, i64 noundef 8, ptr noundef %55, i64 noundef 2)
  store i32 %56, ptr %7, align 4, !tbaa !9
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %61

59:                                               ; preds = %51
  %60 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 1135, i32 noundef %60)
  br label %102

61:                                               ; preds = %51
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62
  %64 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 0
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.Gost28147Ctx_st, ptr %65, i32 0, i32 4
  %67 = getelementptr inbounds [8 x i32], ptr %66, i64 0, i64 0
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Gost28147Ctx_st, ptr %68, i32 0, i32 3
  %70 = getelementptr inbounds [1024 x i32], ptr %69, i64 0, i64 0
  call void @base_cycle8(ptr noundef %64, ptr noundef %67, ptr noundef @MAC_KEY_ORDER, i32 noundef 16, ptr noundef %70)
  br label %71

71:                                               ; preds = %63
  %72 = getelementptr inbounds [2 x i32], ptr %6, i64 0, i64 0
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.Gost28147MacCtx_st, ptr %73, i32 0, i32 1
  %75 = getelementptr inbounds [8 x i8], ptr %74, i64 0, i64 0
  %76 = call i32 @uint32_to_uint8(ptr noundef %72, i64 noundef 2, ptr noundef %75, i64 noundef 8)
  store i32 %76, ptr %7, align 4, !tbaa !9
  %77 = load i32, ptr %7, align 4, !tbaa !9
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %81

79:                                               ; preds = %71
  %80 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 1137, i32 noundef %80)
  br label %102

81:                                               ; preds = %71
  br label %82

82:                                               ; preds = %81
  br label %83

83:                                               ; preds = %82
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.Gost28147MacCtx_st, ptr %84, i32 0, i32 0
  store i64 0, ptr %85, align 8, !tbaa !17
  br label %86

86:                                               ; preds = %83, %43
  br label %87

87:                                               ; preds = %86
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.Gost28147MacCtx_st, ptr %88, i32 0, i32 1
  %90 = getelementptr inbounds [8 x i8], ptr %89, i64 0, i64 0
  %91 = call ptr @ba_alloc_from_uint8(ptr noundef %90, i64 noundef 8)
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %91, ptr %92, align 8, !tbaa !5
  %93 = icmp eq ptr null, %91
  br i1 %93, label %94, label %96

94:                                               ; preds = %87
  store i32 2, ptr %7, align 4, !tbaa !9
  %95 = load i32, ptr %7, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 1141, i32 noundef %95)
  br label %102

96:                                               ; preds = %87
  br label %97

97:                                               ; preds = %96
  br label %98

98:                                               ; preds = %97
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.Gost28147MacCtx_st, ptr %99, i32 0, i32 1
  %101 = getelementptr inbounds [8 x i8], ptr %100, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 8 %101, i8 0, i64 8, i1 false)
  br label %102

102:                                              ; preds = %98, %94, %79, %59, %39, %29, %19, %11
  %103 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret i32 %103
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { "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 = { 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 #4 = { 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 #5 = { 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 = !{!12, !10, i64 0}
!12 = !{!"Gost28147Ctx_st", !10, i64 0, !13, i64 4, !6, i64 8, !7, i64 16, !7, i64 4112, !7, i64 4144}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!12, !13, i64 4}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!18, !19, i64 0}
!18 = !{!"Gost28147MacCtx_st", !19, i64 0, !7, i64 8}
!19 = !{!"long", !7, i64 0}


; 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
@MAC_KEY_ORDER = external hidden constant [16 x i8], align 16

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

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

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

declare i32 @uint8_to_uint32(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

declare i32 @uint32_to_uint8(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare ptr @ba_alloc_from_uint8(ptr noundef, i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gost28147_final_mac8(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #3 {
  %3 = alloca [2 x i32], align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #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 1121, i32 noundef 2, ptr noundef null) #4
  br label %34

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

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

7:                                                ; preds = %5
  %8 = load i32, ptr %0, align 8, !tbaa !5
  %.not29 = icmp eq i32 %8, 4
  br i1 %.not29, label %10, label %9

9:                                                ; preds = %7
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 1125, i32 noundef 14, ptr noundef null) #4
  br label %34

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  %12 = load i8, ptr %11, align 4, !tbaa !12, !range !13, !noundef !14
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 1129, i32 noundef 4, ptr noundef null) #4
  br label %34

15:                                               ; preds = %10
  %16 = getelementptr inbounds i8, ptr %0, i64 4144
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %.not30 = icmp eq i64 %17, 0
  br i1 %.not30, label %28, label %18

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %0, i64 4152
  %20 = call i32 @uint8_to_uint32(ptr noundef nonnull %19, i64 noundef 8, ptr noundef nonnull %3, i64 noundef 2) #4
  %.not31 = icmp eq i32 %20, 0
  br i1 %.not31, label %22, label %21

21:                                               ; preds = %18
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 1135, i32 noundef %20) #4
  br label %34

22:                                               ; preds = %18
  %23 = getelementptr inbounds i8, ptr %0, i64 4112
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  call void @base_cycle8(ptr noundef nonnull %3, ptr noundef nonnull %23, ptr noundef nonnull @MAC_KEY_ORDER, i32 noundef 16, ptr noundef nonnull %24)
  %25 = call i32 @uint32_to_uint8(ptr noundef nonnull %3, i64 noundef 2, ptr noundef nonnull %19, i64 noundef 8) #4
  %.not32 = icmp eq i32 %25, 0
  br i1 %.not32, label %27, label %26

26:                                               ; preds = %22
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 1137, i32 noundef %25) #4
  br label %34

27:                                               ; preds = %22
  store i64 0, ptr %16, align 8, !tbaa !15
  br label %28

28:                                               ; preds = %15, %27
  %29 = getelementptr inbounds i8, ptr %0, i64 4152
  %30 = call ptr @ba_alloc_from_uint8(ptr noundef nonnull %29, i64 noundef 8) #4
  store ptr %30, ptr %1, align 8, !tbaa !18
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %33

32:                                               ; preds = %28
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 1141, i32 noundef 2) #4
  br label %34

33:                                               ; preds = %28
  store i64 0, ptr %29, align 8
  br label %34

34:                                               ; preds = %33, %32, %26, %21, %14, %9, %6, %4
  %.1 = phi i32 [ 14, %9 ], [ %20, %21 ], [ %25, %26 ], [ 2, %32 ], [ 0, %33 ], [ 4, %14 ], [ 2, %6 ], [ 2, %4 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  ret i32 %.1
}

attributes #0 = { mustprogress 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 = { 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 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 = !{!"Gost28147Ctx_st", !7, i64 0, !10, i64 4, !11, i64 8, !8, i64 16, !8, i64 4112, !8, i64 4144}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !10, i64 4}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !17, i64 0}
!16 = !{!"Gost28147MacCtx_st", !17, i64 0, !8, i64 8}
!17 = !{!"long", !8, i64 0}
!18 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass