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

; 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.AesCtx_st = type { i64, [16 x i8], [16 x i8], [64 x i32], [64 x i32], [32 x i8], [16 x i8], i64, i64, i64, i32 }

@.str = external hidden unnamed_addr constant [13 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

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

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

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

; 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

; Function Attrs: nounwind uwtable
define dso_local i32 @aes_init_ccm(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  br label %11

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

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

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 %6, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %24, label %22

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

24:                                               ; preds = %19
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %32, label %30

30:                                               ; preds = %27
  store i32 2, ptr %9, align 4, !tbaa !11
  %31 = load i32, ptr %9, align 4, !tbaa !11
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 2137, i32 noundef %31, ptr noundef null)
  br label %93

32:                                               ; preds = %27
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = icmp ult i64 %35, 4
  br i1 %36, label %44, label %37

37:                                               ; preds = %34
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = icmp ugt i64 %38, 16
  br i1 %39, label %44, label %40

40:                                               ; preds = %37
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = and i64 %41, 1
  %43 = icmp ne i64 %42, 0
  br i1 %43, label %44, label %49

44:                                               ; preds = %40, %37, %34
  br label %45

45:                                               ; preds = %44
  store i32 2, ptr %9, align 4, !tbaa !11
  %46 = load i32, ptr %9, align 4, !tbaa !11
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 2140, i32 noundef %46, ptr noundef null)
  br label %93

47:                                               ; No predecessors!
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48, %40
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ByteArray_st, ptr %50, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !13
  store i64 %52, ptr %10, align 8, !tbaa !9
  %53 = load i64, ptr %10, align 8, !tbaa !9
  %54 = icmp ult i64 %53, 7
  br i1 %54, label %58, label %55

55:                                               ; preds = %49
  %56 = load i64, ptr %10, align 8, !tbaa !9
  %57 = icmp ugt i64 %56, 13
  br i1 %57, label %58, label %63

58:                                               ; preds = %55, %49
  br label %59

59:                                               ; preds = %58
  store i32 2, ptr %9, align 4, !tbaa !11
  %60 = load i32, ptr %9, align 4, !tbaa !11
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 2146, i32 noundef %60, ptr noundef null)
  br label %93

61:                                               ; No predecessors!
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62, %55
  br label %64

64:                                               ; preds = %63
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = call i32 @aes_base_init(ptr noundef %65, ptr noundef %66)
  store i32 %67, ptr %9, align 4, !tbaa !11
  %68 = load i32, ptr %9, align 4, !tbaa !11
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %72

70:                                               ; preds = %64
  %71 = load i32, ptr %9, align 4, !tbaa !11
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 2149, i32 noundef %71)
  br label %93

72:                                               ; preds = %64
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.AesCtx_st, ptr %75, i32 0, i32 10
  store i32 6, ptr %76, align 8, !tbaa !15
  %77 = load i64, ptr %8, align 8, !tbaa !9
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.AesCtx_st, ptr %78, i32 0, i32 9
  store i64 %77, ptr %79, align 8, !tbaa !17
  %80 = load i64, ptr %10, align 8, !tbaa !9
  %81 = trunc i64 %80 to i8
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.AesCtx_st, ptr %82, i32 0, i32 6
  %84 = getelementptr inbounds [16 x i8], ptr %83, i64 0, i64 0
  store i8 %81, ptr %84, align 8, !tbaa !18
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.AesCtx_st, ptr %85, i32 0, i32 6
  %87 = getelementptr inbounds [16 x i8], ptr %86, i64 0, i64 0
  %88 = getelementptr inbounds i8, ptr %87, i64 1
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.ByteArray_st, ptr %89, i32 0, i32 0
  %91 = load ptr, ptr %90, align 8, !tbaa !19
  %92 = load i64, ptr %10, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %88, ptr align 1 %91, i64 %92, i1 false)
  br label %93

93:                                               ; preds = %74, %70, %59, %45, %30, %22, %14
  %94 = load i32, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret i32 %94
}

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 = { 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 = !{!"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, !10, i64 8}
!14 = !{!"ByteArray_st", !6, i64 0, !10, i64 8}
!15 = !{!16, !12, i64 624}
!16 = !{!"AesCtx_st", !10, i64 0, !7, i64 8, !7, i64 24, !7, i64 40, !7, i64 296, !7, i64 552, !7, i64 584, !10, i64 600, !10, i64 608, !10, i64 616, !12, i64 624}
!17 = !{!16, !10, i64 616}
!18 = !{!7, !7, i64 0}
!19 = !{!14, !6, 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 [13 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: nounwind uwtable
declare hidden i32 @aes_base_init(ptr noundef, ptr noundef) local_unnamed_addr #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
define dso_local i32 @aes_init_ccm(ptr noundef %0, ptr noundef %1, ptr noundef readonly %2, i64 noundef %3) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %6

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

6:                                                ; preds = %4
  %.not35 = icmp eq ptr %1, null
  br i1 %.not35, label %7, label %8

7:                                                ; preds = %6
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 2136, i32 noundef 2, ptr noundef null) #3
  br label %29

8:                                                ; preds = %6
  %.not36 = icmp eq ptr %2, null
  br i1 %.not36, label %9, label %10

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

10:                                               ; preds = %8
  %11 = add i64 %3, -4
  %or.cond = icmp ult i64 %11, 13
  %12 = and i64 %3, 1
  %.not37 = icmp eq i64 %12, 0
  %or.cond39 = and i1 %or.cond, %.not37
  br i1 %or.cond39, label %14, label %13

13:                                               ; preds = %10
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 2140, i32 noundef 2, ptr noundef null) #3
  br label %29

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %2, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = add i64 %16, -14
  %or.cond3 = icmp ult i64 %17, -7
  br i1 %or.cond3, label %18, label %19

18:                                               ; preds = %14
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 2146, i32 noundef 2, ptr noundef null) #3
  br label %29

19:                                               ; preds = %14
  %20 = tail call i32 @aes_base_init(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %.not38 = icmp eq i32 %20, 0
  br i1 %.not38, label %22, label %21

21:                                               ; preds = %19
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 2149, i32 noundef %20) #3
  br label %29

22:                                               ; preds = %19
  %23 = getelementptr inbounds i8, ptr %0, i64 624
  store i32 6, ptr %23, align 8, !tbaa !11
  %24 = getelementptr inbounds i8, ptr %0, i64 616
  store i64 %3, ptr %24, align 8, !tbaa !14
  %25 = trunc nuw nsw i64 %16 to i8
  %26 = getelementptr inbounds i8, ptr %0, i64 584
  store i8 %25, ptr %26, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %0, i64 585
  %28 = load ptr, ptr %2, align 8, !tbaa !16
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %27, ptr align 1 %28, i64 %16, i1 false)
  br label %29

29:                                               ; preds = %22, %21, %18, %13, %9, %7, %5
  %.0 = phi i32 [ 2, %13 ], [ 2, %18 ], [ %20, %21 ], [ 0, %22 ], [ 2, %9 ], [ 2, %7 ], [ 2, %5 ]
  ret i32 %.0
}

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 8}
!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, !13, i64 624}
!12 = !{!"AesCtx_st", !10, i64 0, !8, i64 8, !8, i64 24, !8, i64 40, !8, i64 296, !8, i64 552, !8, i64 584, !10, i64 600, !10, i64 608, !10, i64 616, !13, i64 624}
!13 = !{!"int", !8, i64 0}
!14 = !{!12, !10, i64 616}
!15 = !{!8, !8, i64 0}
!16 = !{!6, !7, i64 0}


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