; LLVM IR from guanzhi/GmSSL :: src (sm4_cbc)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@__FUNCTION__.sm4_cbc_padding_decrypt = external hidden unnamed_addr constant [24 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.4 = 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

; 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) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sm4_cbc_padding_decrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca [16 x i8], align 16
  %15 = alloca [16 x i8], align 16
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i64 %3, ptr %11, align 8, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  store i64 16, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  %19 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %19, ptr align 1 %20, i64 16, i1 false)
  %21 = load i64, ptr %11, align 8, !tbaa !9
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %29

23:                                               ; preds = %6
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 53, ptr noundef @__FUNCTION__.sm4_cbc_padding_decrypt, ptr noundef @.str.2) #5
  br label %27

27:                                               ; preds = %24
  br label %28

28:                                               ; preds = %27
  store i32 0, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %91

29:                                               ; preds = %6
  %30 = load i64, ptr %11, align 8, !tbaa !9
  %31 = urem i64 %30, 16
  %32 = icmp ne i64 %31, 0
  br i1 %32, label %36, label %33

33:                                               ; preds = %29
  %34 = load i64, ptr %11, align 8, !tbaa !9
  %35 = icmp ult i64 %34, 16
  br i1 %35, label %36, label %42

36:                                               ; preds = %33, %29
  br label %37

37:                                               ; preds = %36
  %38 = load ptr, ptr @stderr, align 8, !tbaa !5
  %39 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 57, ptr noundef @__FUNCTION__.sm4_cbc_padding_decrypt, ptr noundef @.str.3) #5
  br label %40

40:                                               ; preds = %37
  br label %41

41:                                               ; preds = %40
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %91

42:                                               ; preds = %33
  %43 = load i64, ptr %11, align 8, !tbaa !9
  %44 = icmp ugt i64 %43, 16
  br i1 %44, label %45, label %53

45:                                               ; preds = %42
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = load i64, ptr %11, align 8, !tbaa !9
  %50 = udiv i64 %49, 16
  %51 = sub i64 %50, 1
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  call void @sm4_cbc_decrypt_blocks(ptr noundef %46, ptr noundef %47, ptr noundef %48, i64 noundef %51, ptr noundef %52)
  br label %53

53:                                               ; preds = %45, %42
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = load i64, ptr %11, align 8, !tbaa !9
  %58 = getelementptr inbounds i8, ptr %56, i64 %57
  %59 = getelementptr inbounds i8, ptr %58, i64 -16
  %60 = getelementptr inbounds [16 x i8], ptr %15, i64 0, i64 0
  call void @sm4_cbc_decrypt_blocks(ptr noundef %54, ptr noundef %55, ptr noundef %59, i64 noundef 1, ptr noundef %60)
  %61 = getelementptr inbounds [16 x i8], ptr %15, i64 0, i64 15
  %62 = load i8, ptr %61, align 1, !tbaa !11
  %63 = zext i8 %62 to i32
  store i32 %63, ptr %17, align 4, !tbaa !12
  %64 = load i32, ptr %17, align 4, !tbaa !12
  %65 = icmp slt i32 %64, 1
  br i1 %65, label %69, label %66

66:                                               ; preds = %53
  %67 = load i32, ptr %17, align 4, !tbaa !12
  %68 = icmp sgt i32 %67, 16
  br i1 %68, label %69, label %75

69:                                               ; preds = %66, %53
  br label %70

70:                                               ; preds = %69
  %71 = load ptr, ptr @stderr, align 8, !tbaa !5
  %72 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %71, ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 68, ptr noundef @__FUNCTION__.sm4_cbc_padding_decrypt) #5
  br label %73

73:                                               ; preds = %70
  br label %74

74:                                               ; preds = %73
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %91

75:                                               ; preds = %66
  %76 = load i32, ptr %17, align 4, !tbaa !12
  %77 = sext i32 %76 to i64
  %78 = load i64, ptr %16, align 8, !tbaa !9
  %79 = sub i64 %78, %77
  store i64 %79, ptr %16, align 8, !tbaa !9
  %80 = load ptr, ptr %12, align 8, !tbaa !5
  %81 = load i64, ptr %11, align 8, !tbaa !9
  %82 = getelementptr inbounds i8, ptr %80, i64 %81
  %83 = getelementptr inbounds i8, ptr %82, i64 -16
  %84 = getelementptr inbounds [16 x i8], ptr %15, i64 0, i64 0
  %85 = load i64, ptr %16, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %83, ptr align 16 %84, i64 %85, i1 false)
  %86 = load i64, ptr %11, align 8, !tbaa !9
  %87 = load i32, ptr %17, align 4, !tbaa !12
  %88 = sext i32 %87 to i64
  %89 = sub i64 %86, %88
  %90 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 %89, ptr %90, align 8, !tbaa !9
  store i32 1, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %91

91:                                               ; preds = %75, %74, %41, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #5
  %92 = load i32, ptr %7, align 4
  ret i32 %92
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

declare void @sm4_cbc_decrypt_blocks(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nounwind "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 = { "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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@__FUNCTION__.sm4_cbc_padding_decrypt = external hidden unnamed_addr constant [24 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [13 x i8], align 1

; 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 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @sm4_cbc_padding_decrypt(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #2 {
  %7 = alloca [16 x i8], align 16
  %8 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %7, ptr noundef nonnull align 1 dereferenceable(16) %1, i64 16, i1 false)
  %9 = icmp eq i64 %3, 0
  br i1 %9, label %10, label %13

10:                                               ; preds = %6
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 53, ptr noundef nonnull @__FUNCTION__.sm4_cbc_padding_decrypt, ptr noundef nonnull @.str.2) #6
  br label %40

13:                                               ; preds = %6
  %14 = and i64 %3, 15
  %15 = icmp ne i64 %14, 0
  %16 = icmp ult i64 %3, 16
  %or.cond = or i1 %16, %15
  br i1 %or.cond, label %17, label %20

17:                                               ; preds = %13
  %18 = load ptr, ptr @stderr, align 8, !tbaa !5
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 57, ptr noundef nonnull @__FUNCTION__.sm4_cbc_padding_decrypt, ptr noundef nonnull @.str.3) #6
  br label %40

20:                                               ; preds = %13
  %21 = icmp ugt i64 %3, 16
  br i1 %21, label %22, label %25

22:                                               ; preds = %20
  %23 = lshr exact i64 %3, 4
  %24 = add nsw i64 %23, -1
  call void @sm4_cbc_decrypt_blocks(ptr noundef %0, ptr noundef nonnull %7, ptr noundef %2, i64 noundef %24, ptr noundef %4) #5
  br label %25

25:                                               ; preds = %22, %20
  %26 = getelementptr inbounds i8, ptr %2, i64 %3
  %27 = getelementptr inbounds i8, ptr %26, i64 -16
  call void @sm4_cbc_decrypt_blocks(ptr noundef %0, ptr noundef nonnull %7, ptr noundef nonnull %27, i64 noundef 1, ptr noundef nonnull %8) #5
  %28 = getelementptr inbounds i8, ptr %8, i64 15
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %30 = add i8 %29, -17
  %or.cond3 = icmp ult i8 %30, -16
  br i1 %or.cond3, label %31, label %34

31:                                               ; preds = %25
  %32 = load ptr, ptr @stderr, align 8, !tbaa !5
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 68, ptr noundef nonnull @__FUNCTION__.sm4_cbc_padding_decrypt) #6
  br label %40

34:                                               ; preds = %25
  %35 = zext nneg i8 %29 to i64
  %36 = sub nuw nsw i64 16, %35
  %37 = getelementptr inbounds i8, ptr %4, i64 %3
  %38 = getelementptr inbounds i8, ptr %37, i64 -16
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %38, ptr nonnull align 16 %8, i64 %36, i1 false)
  %39 = sub nuw i64 %3, %35
  store i64 %39, ptr %5, align 8, !tbaa !10
  br label %40

40:                                               ; preds = %34, %31, %17, %10
  %.0 = phi i32 [ 0, %10 ], [ -1, %17 ], [ -1, %31 ], [ 1, %34 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #5
  ret i32 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

declare void @sm4_cbc_decrypt_blocks(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nofree nounwind "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 = { "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 }
attributes #6 = { cold 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}


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