; LLVM IR from guanzhi/GmSSL :: 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.AES_KEY = type { [60 x i32], i64 }

; 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

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

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

9:                                                ; preds = %37, %3
  %10 = load i64, ptr %8, align 8, !tbaa !9
  %11 = icmp ult i64 %10, 4
  br i1 %11, label %12, label %40

12:                                               ; preds = %9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i32 1
  store ptr %14, ptr %5, align 8, !tbaa !5
  %15 = load i8, ptr %13, align 1, !tbaa !11
  %16 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 0
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = getelementptr inbounds [4 x i8], ptr %16, i64 0, i64 %17
  store i8 %15, ptr %18, align 1, !tbaa !11
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i32 1
  store ptr %20, ptr %5, align 8, !tbaa !5
  %21 = load i8, ptr %19, align 1, !tbaa !11
  %22 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 1
  %23 = load i64, ptr %8, align 8, !tbaa !9
  %24 = getelementptr inbounds [4 x i8], ptr %22, i64 0, i64 %23
  store i8 %21, ptr %24, align 1, !tbaa !11
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i32 1
  store ptr %26, ptr %5, align 8, !tbaa !5
  %27 = load i8, ptr %25, align 1, !tbaa !11
  %28 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 2
  %29 = load i64, ptr %8, align 8, !tbaa !9
  %30 = getelementptr inbounds [4 x i8], ptr %28, i64 0, i64 %29
  store i8 %27, ptr %30, align 1, !tbaa !11
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i32 1
  store ptr %32, ptr %5, align 8, !tbaa !5
  %33 = load i8, ptr %31, align 1, !tbaa !11
  %34 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 3
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = getelementptr inbounds [4 x i8], ptr %34, i64 0, i64 %35
  store i8 %33, ptr %36, align 1, !tbaa !11
  br label %37

37:                                               ; preds = %12
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = add i64 %38, 1
  store i64 %39, ptr %8, align 8, !tbaa !9
  br label %9, !llvm.loop !12

40:                                               ; preds = %9
  %41 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 0
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.AES_KEY, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds [60 x i32], ptr %43, i64 0, i64 0
  call void @add_round_key(ptr noundef %41, ptr noundef %44)
  store i64 1, ptr %8, align 8, !tbaa !9
  br label %45

45:                                               ; preds = %62, %40
  %46 = load i64, ptr %8, align 8, !tbaa !9
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.AES_KEY, ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !14
  %50 = icmp ult i64 %46, %49
  br i1 %50, label %51, label %65

51:                                               ; preds = %45
  %52 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 0
  call void @inv_shift_rows(ptr noundef %52)
  %53 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 0
  call void @inv_sub_bytes(ptr noundef %53)
  %54 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 0
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.AES_KEY, ptr %55, i32 0, i32 0
  %57 = getelementptr inbounds [60 x i32], ptr %56, i64 0, i64 0
  %58 = load i64, ptr %8, align 8, !tbaa !9
  %59 = mul i64 4, %58
  %60 = getelementptr inbounds i32, ptr %57, i64 %59
  call void @add_round_key(ptr noundef %54, ptr noundef %60)
  %61 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 0
  call void @inv_mix_columns(ptr noundef %61)
  br label %62

62:                                               ; preds = %51
  %63 = load i64, ptr %8, align 8, !tbaa !9
  %64 = add i64 %63, 1
  store i64 %64, ptr %8, align 8, !tbaa !9
  br label %45, !llvm.loop !16

65:                                               ; preds = %45
  %66 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 0
  call void @inv_shift_rows(ptr noundef %66)
  %67 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 0
  call void @inv_sub_bytes(ptr noundef %67)
  %68 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 0
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.AES_KEY, ptr %69, i32 0, i32 0
  %71 = getelementptr inbounds [60 x i32], ptr %70, i64 0, i64 0
  %72 = load i64, ptr %8, align 8, !tbaa !9
  %73 = mul i64 4, %72
  %74 = getelementptr inbounds i32, ptr %71, i64 %73
  call void @add_round_key(ptr noundef %68, ptr noundef %74)
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %75

75:                                               ; preds = %103, %65
  %76 = load i64, ptr %8, align 8, !tbaa !9
  %77 = icmp ult i64 %76, 4
  br i1 %77, label %78, label %106

78:                                               ; preds = %75
  %79 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 0
  %80 = load i64, ptr %8, align 8, !tbaa !9
  %81 = getelementptr inbounds [4 x i8], ptr %79, i64 0, i64 %80
  %82 = load i8, ptr %81, align 1, !tbaa !11
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds i8, ptr %83, i32 1
  store ptr %84, ptr %6, align 8, !tbaa !5
  store i8 %82, ptr %83, align 1, !tbaa !11
  %85 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 1
  %86 = load i64, ptr %8, align 8, !tbaa !9
  %87 = getelementptr inbounds [4 x i8], ptr %85, i64 0, i64 %86
  %88 = load i8, ptr %87, align 1, !tbaa !11
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds i8, ptr %89, i32 1
  store ptr %90, ptr %6, align 8, !tbaa !5
  store i8 %88, ptr %89, align 1, !tbaa !11
  %91 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 2
  %92 = load i64, ptr %8, align 8, !tbaa !9
  %93 = getelementptr inbounds [4 x i8], ptr %91, i64 0, i64 %92
  %94 = load i8, ptr %93, align 1, !tbaa !11
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = getelementptr inbounds i8, ptr %95, i32 1
  store ptr %96, ptr %6, align 8, !tbaa !5
  store i8 %94, ptr %95, align 1, !tbaa !11
  %97 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 3
  %98 = load i64, ptr %8, align 8, !tbaa !9
  %99 = getelementptr inbounds [4 x i8], ptr %97, i64 0, i64 %98
  %100 = load i8, ptr %99, align 1, !tbaa !11
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  %102 = getelementptr inbounds i8, ptr %101, i32 1
  store ptr %102, ptr %6, align 8, !tbaa !5
  store i8 %100, ptr %101, align 1, !tbaa !11
  br label %103

103:                                              ; preds = %78
  %104 = load i64, ptr %8, align 8, !tbaa !9
  %105 = add i64 %104, 1
  store i64 %105, ptr %8, align 8, !tbaa !9
  br label %75, !llvm.loop !17

106:                                              ; preds = %75
  %107 = getelementptr inbounds [4 x [4 x i8]], ptr %7, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %107, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  ret void
}

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !10, i64 240}
!15 = !{!"", !7, i64 0, !10, i64 240}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !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"

; 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

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

; Function Attrs: nounwind uwtable
define dso_local void @aes_decrypt(ptr noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = alloca [4 x [4 x i8]], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #2
  %5 = load <16 x i8>, ptr %1, align 1, !tbaa !5
  %6 = shufflevector <16 x i8> %5, <16 x i8> poison, <16 x i32> <i32 0, i32 4, i32 8, i32 12, i32 1, i32 5, i32 9, i32 13, i32 2, i32 6, i32 10, i32 14, i32 3, i32 7, i32 11, i32 15>
  store <16 x i8> %6, ptr %4, align 16, !tbaa !5
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef %0)
  %7 = getelementptr inbounds i8, ptr %0, i64 240
  %8 = load i64, ptr %7, align 8, !tbaa !8
  %9 = icmp ugt i64 %8, 1
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.132 = phi i64 [ %11, %.lr.ph ], [ 1, %3 ]
  call void @inv_shift_rows(ptr noundef nonnull %4)
  call void @inv_sub_bytes(ptr noundef nonnull %4)
  %.idx29 = shl i64 %.132, 4
  %10 = getelementptr inbounds i8, ptr %0, i64 %.idx29
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef %10)
  call void @inv_mix_columns(ptr noundef nonnull %4)
  %11 = add nuw i64 %.132, 1
  %12 = load i64, ptr %7, align 8, !tbaa !8
  %13 = icmp ult i64 %11, %12
  br i1 %13, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %14 = shl i64 %11, 4
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %3
  %.1.lcssa = phi i64 [ 16, %3 ], [ %14, %._crit_edge.loopexit ]
  call void @inv_shift_rows(ptr noundef nonnull %4)
  call void @inv_sub_bytes(ptr noundef nonnull %4)
  %15 = getelementptr inbounds i8, ptr %0, i64 %.1.lcssa
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef %15)
  %16 = load <16 x i8>, ptr %4, align 16, !tbaa !5
  %17 = shufflevector <16 x i8> %16, <16 x i8> poison, <16 x i32> <i32 0, i32 4, i32 8, i32 12, i32 1, i32 5, i32 9, i32 13, i32 2, i32 6, i32 10, i32 14, i32 3, i32 7, i32 11, i32 15>
  store <16 x i8> %17, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @inv_shift_rows(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @inv_sub_bytes(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @inv_mix_columns(ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 240}
!9 = !{!"", !6, i64 0, !10, i64 240}
!10 = !{!"long", !6, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass