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

@.str = external hidden unnamed_addr constant [19 x i8], align 1
@GOST28147_SBOX_1 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_2 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_3 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_4 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_5 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_6 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_7 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_8 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_9 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_10 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_11 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_12 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_13 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_14 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_15 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_16 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_17 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_18 = external hidden constant [128 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

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: nounwind uwtable
define dso_local ptr @gost28147_alloc(i32 noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store ptr null, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !9
  %6 = load i32, ptr %2, align 4, !tbaa !5
  switch i32 %6, label %25 [
    i32 0, label %7
    i32 1, label %7
    i32 2, label %8
    i32 3, label %9
    i32 4, label %10
    i32 5, label %11
    i32 6, label %12
    i32 7, label %13
    i32 8, label %14
    i32 9, label %15
    i32 10, label %16
    i32 11, label %17
    i32 12, label %18
    i32 13, label %19
    i32 14, label %20
    i32 15, label %21
    i32 16, label %22
    i32 17, label %23
    i32 18, label %24
  ]

7:                                                ; preds = %1, %1
  store ptr @GOST28147_SBOX_1, ptr %5, align 8, !tbaa !9
  br label %30

8:                                                ; preds = %1
  store ptr @GOST28147_SBOX_2, ptr %5, align 8, !tbaa !9
  br label %30

9:                                                ; preds = %1
  store ptr @GOST28147_SBOX_3, ptr %5, align 8, !tbaa !9
  br label %30

10:                                               ; preds = %1
  store ptr @GOST28147_SBOX_4, ptr %5, align 8, !tbaa !9
  br label %30

11:                                               ; preds = %1
  store ptr @GOST28147_SBOX_5, ptr %5, align 8, !tbaa !9
  br label %30

12:                                               ; preds = %1
  store ptr @GOST28147_SBOX_6, ptr %5, align 8, !tbaa !9
  br label %30

13:                                               ; preds = %1
  store ptr @GOST28147_SBOX_7, ptr %5, align 8, !tbaa !9
  br label %30

14:                                               ; preds = %1
  store ptr @GOST28147_SBOX_8, ptr %5, align 8, !tbaa !9
  br label %30

15:                                               ; preds = %1
  store ptr @GOST28147_SBOX_9, ptr %5, align 8, !tbaa !9
  br label %30

16:                                               ; preds = %1
  store ptr @GOST28147_SBOX_10, ptr %5, align 8, !tbaa !9
  br label %30

17:                                               ; preds = %1
  store ptr @GOST28147_SBOX_11, ptr %5, align 8, !tbaa !9
  br label %30

18:                                               ; preds = %1
  store ptr @GOST28147_SBOX_12, ptr %5, align 8, !tbaa !9
  br label %30

19:                                               ; preds = %1
  store ptr @GOST28147_SBOX_13, ptr %5, align 8, !tbaa !9
  br label %30

20:                                               ; preds = %1
  store ptr @GOST28147_SBOX_14, ptr %5, align 8, !tbaa !9
  br label %30

21:                                               ; preds = %1
  store ptr @GOST28147_SBOX_15, ptr %5, align 8, !tbaa !9
  br label %30

22:                                               ; preds = %1
  store ptr @GOST28147_SBOX_16, ptr %5, align 8, !tbaa !9
  br label %30

23:                                               ; preds = %1
  store ptr @GOST28147_SBOX_17, ptr %5, align 8, !tbaa !9
  br label %30

24:                                               ; preds = %1
  store ptr @GOST28147_SBOX_18, ptr %5, align 8, !tbaa !9
  br label %30

25:                                               ; preds = %1
  br label %26

26:                                               ; preds = %25
  store i32 2, ptr %4, align 4, !tbaa !5
  %27 = load i32, ptr %4, align 4, !tbaa !5
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 747, i32 noundef %27, ptr noundef null)
  br label %40

28:                                               ; No predecessors!
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29, %24, %23, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = call ptr @gost28147_alloc_user_sbox_core(ptr noundef %32, i64 noundef 128)
  store ptr %33, ptr %3, align 8, !tbaa !9
  %34 = icmp eq ptr null, %33
  br i1 %34, label %35, label %37

35:                                               ; preds = %31
  store i32 2, ptr %4, align 4, !tbaa !5
  %36 = load i32, ptr %4, align 4, !tbaa !5
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 750, i32 noundef %36)
  br label %40

37:                                               ; preds = %31
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39, %35, %26
  %41 = load ptr, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %41
}

; Function Attrs: nounwind uwtable
declare hidden ptr @gost28147_alloc_user_sbox_core(ptr noundef, i64 noundef) #2

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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
@GOST28147_SBOX_1 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_2 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_3 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_4 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_5 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_6 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_7 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_8 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_9 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_10 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_11 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_12 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_13 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_14 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_15 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_16 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_17 = external hidden constant [128 x i8], align 16
@GOST28147_SBOX_18 = external hidden constant [128 x i8], align 16
@switch.table.gost28147_alloc = private unnamed_addr constant [19 x ptr] [ptr @GOST28147_SBOX_1, ptr @GOST28147_SBOX_1, ptr @GOST28147_SBOX_2, ptr @GOST28147_SBOX_3, ptr @GOST28147_SBOX_4, ptr @GOST28147_SBOX_5, ptr @GOST28147_SBOX_6, ptr @GOST28147_SBOX_7, ptr @GOST28147_SBOX_8, ptr @GOST28147_SBOX_9, ptr @GOST28147_SBOX_10, ptr @GOST28147_SBOX_11, ptr @GOST28147_SBOX_12, ptr @GOST28147_SBOX_13, ptr @GOST28147_SBOX_14, ptr @GOST28147_SBOX_15, ptr @GOST28147_SBOX_16, ptr @GOST28147_SBOX_17, ptr @GOST28147_SBOX_18], align 8

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: nounwind uwtable
define dso_local ptr @gost28147_alloc(i32 noundef %0) local_unnamed_addr #1 {
  %2 = icmp ult i32 %0, 19
  br i1 %2, label %switch.lookup, label %3

3:                                                ; preds = %1
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 747, i32 noundef 2, ptr noundef null) #2
  br label %8

switch.lookup:                                    ; preds = %1
  %4 = zext nneg i32 %0 to i64
  %switch.gep = getelementptr inbounds [19 x ptr], ptr @switch.table.gost28147_alloc, i64 0, i64 %4
  %switch.load = load ptr, ptr %switch.gep, align 8
  %5 = tail call ptr @gost28147_alloc_user_sbox_core(ptr noundef nonnull %switch.load, i64 noundef 128)
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %8

7:                                                ; preds = %switch.lookup
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 750, i32 noundef 2) #2
  br label %8

8:                                                ; preds = %switch.lookup, %7, %3
  %.04 = phi ptr [ null, %3 ], [ null, %7 ], [ %5, %switch.lookup ]
  ret ptr %.04
}

; Function Attrs: nounwind uwtable
declare hidden ptr @gost28147_alloc_user_sbox_core(ptr noundef, i64 noundef) local_unnamed_addr #1

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 = { 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 #2 = { 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)"}


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