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

; 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.SM3_HMAC_CTX = type { %struct.SM3_CTX, [64 x i8] }
%struct.SM3_CTX = type { [8 x i32], i64, [64 x i8], i64 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [58 x i8], align 1
@__FUNCTION__.sm3_hkdf_expand = external hidden unnamed_addr constant [16 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: nounwind
declare i32 @fprintf(ptr 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

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

declare void @sm3_hmac_init(ptr noundef, ptr noundef, i64 noundef) #3

declare void @sm3_hmac_update(ptr noundef, ptr noundef, i64 noundef) #3

declare void @sm3_hmac_finish(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @sm3_hkdf_expand(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) #4 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %struct.SM3_HMAC_CTX, align 8
  %13 = alloca [32 x i8], align 16
  %14 = alloca i8, align 1
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 176, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #5
  store i8 1, ptr %14, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %17 = load i64, ptr %10, align 8, !tbaa !9
  %18 = icmp ugt i64 %17, 0
  br i1 %18, label %19, label %41

19:                                               ; preds = %5
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  call void @sm3_hmac_init(ptr noundef %12, ptr noundef %20, i64 noundef 32)
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = load i64, ptr %9, align 8, !tbaa !9
  call void @sm3_hmac_update(ptr noundef %12, ptr noundef %21, i64 noundef %22)
  call void @sm3_hmac_update(ptr noundef %12, ptr noundef %14, i64 noundef 1)
  %23 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  call void @sm3_hmac_finish(ptr noundef %12, ptr noundef %23)
  %24 = load i8, ptr %14, align 1, !tbaa !11
  %25 = add i8 %24, 1
  store i8 %25, ptr %14, align 1, !tbaa !11
  store i64 32, ptr %15, align 8, !tbaa !9
  %26 = load i64, ptr %15, align 8, !tbaa !9
  %27 = load i64, ptr %10, align 8, !tbaa !9
  %28 = icmp ugt i64 %26, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %19
  %30 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %30, ptr %15, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %29, %19
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  %34 = load i64, ptr %15, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %32, ptr align 16 %33, i64 %34, i1 false)
  %35 = load i64, ptr %15, align 8, !tbaa !9
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 %35
  store ptr %37, ptr %11, align 8, !tbaa !5
  %38 = load i64, ptr %15, align 8, !tbaa !9
  %39 = load i64, ptr %10, align 8, !tbaa !9
  %40 = sub i64 %39, %38
  store i64 %40, ptr %10, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %31, %5
  br label %42

42:                                               ; preds = %69, %41
  %43 = load i64, ptr %10, align 8, !tbaa !9
  %44 = icmp ugt i64 %43, 0
  br i1 %44, label %45, label %79

45:                                               ; preds = %42
  %46 = load i8, ptr %14, align 1, !tbaa !11
  %47 = zext i8 %46 to i32
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %55

49:                                               ; preds = %45
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr @stderr, align 8, !tbaa !5
  %52 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 170, ptr noundef @__FUNCTION__.sm3_hkdf_expand) #5
  br label %53

53:                                               ; preds = %50
  br label %54

54:                                               ; preds = %53
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %80

55:                                               ; preds = %45
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  call void @sm3_hmac_init(ptr noundef %12, ptr noundef %56, i64 noundef 32)
  %57 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  %58 = load i64, ptr %15, align 8, !tbaa !9
  call void @sm3_hmac_update(ptr noundef %12, ptr noundef %57, i64 noundef %58)
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load i64, ptr %9, align 8, !tbaa !9
  call void @sm3_hmac_update(ptr noundef %12, ptr noundef %59, i64 noundef %60)
  call void @sm3_hmac_update(ptr noundef %12, ptr noundef %14, i64 noundef 1)
  %61 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  call void @sm3_hmac_finish(ptr noundef %12, ptr noundef %61)
  %62 = load i8, ptr %14, align 1, !tbaa !11
  %63 = add i8 %62, 1
  store i8 %63, ptr %14, align 1, !tbaa !11
  store i64 32, ptr %15, align 8, !tbaa !9
  %64 = load i64, ptr %15, align 8, !tbaa !9
  %65 = load i64, ptr %10, align 8, !tbaa !9
  %66 = icmp ugt i64 %64, %65
  br i1 %66, label %67, label %69

67:                                               ; preds = %55
  %68 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %68, ptr %15, align 8, !tbaa !9
  br label %69

69:                                               ; preds = %67, %55
  %70 = load ptr, ptr %11, align 8, !tbaa !5
  %71 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  %72 = load i64, ptr %15, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %70, ptr align 16 %71, i64 %72, i1 false)
  %73 = load i64, ptr %15, align 8, !tbaa !9
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %74, i64 %73
  store ptr %75, ptr %11, align 8, !tbaa !5
  %76 = load i64, ptr %15, align 8, !tbaa !9
  %77 = load i64, ptr %10, align 8, !tbaa !9
  %78 = sub i64 %77, %76
  store i64 %78, ptr %10, align 8, !tbaa !9
  br label %42, !llvm.loop !12

79:                                               ; preds = %42
  store i32 1, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %80

80:                                               ; preds = %79, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 176, ptr %12) #5
  %81 = load i32, ptr %6, align 4
  ret i32 %81
}

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


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

%struct.SM3_HMAC_CTX = type { %struct.SM3_CTX, [64 x i8] }
%struct.SM3_CTX = type { [8 x i32], i64, [64 x i8], i64 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [58 x i8], align 1
@__FUNCTION__.sm3_hkdf_expand = external hidden unnamed_addr constant [16 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: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #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: 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

declare void @sm3_hmac_init(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

declare void @sm3_hmac_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

declare void @sm3_hmac_finish(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @sm3_hkdf_expand(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #4 {
  %6 = alloca %struct.SM3_HMAC_CTX, align 8
  %7 = alloca [32 x i8], align 16
  %8 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 176, ptr nonnull %6) #6
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %7) #6
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %8) #6
  store i8 1, ptr %8, align 1, !tbaa !5
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %.loopexit, label %9

9:                                                ; preds = %5
  call void @sm3_hmac_init(ptr noundef nonnull %6, ptr noundef %0, i64 noundef 32) #6
  call void @sm3_hmac_update(ptr noundef nonnull %6, ptr noundef %1, i64 noundef %2) #6
  call void @sm3_hmac_update(ptr noundef nonnull %6, ptr noundef nonnull %8, i64 noundef 1) #6
  call void @sm3_hmac_finish(ptr noundef nonnull %6, ptr noundef nonnull %7) #6
  %10 = load i8, ptr %8, align 1, !tbaa !5
  %11 = add i8 %10, 1
  store i8 %11, ptr %8, align 1, !tbaa !5
  %spec.select = call i64 @llvm.umin.i64(i64 %3, i64 32)
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %4, ptr nonnull align 16 %7, i64 %spec.select, i1 false)
  %12 = sub i64 %3, %spec.select
  %.not3436 = icmp eq i64 %12, 0
  br i1 %.not3436, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %9
  %13 = getelementptr inbounds i8, ptr %4, i64 %spec.select
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %19
  %14 = phi i8 [ %21, %19 ], [ %11, %.lr.ph.preheader ]
  %.239 = phi i64 [ %spec.select35, %19 ], [ %spec.select, %.lr.ph.preheader ]
  %.12838 = phi ptr [ %22, %19 ], [ %13, %.lr.ph.preheader ]
  %.13037 = phi i64 [ %23, %19 ], [ %12, %.lr.ph.preheader ]
  %15 = icmp eq i8 %14, 0
  br i1 %15, label %16, label %19

16:                                               ; preds = %.lr.ph
  %17 = load ptr, ptr @stderr, align 8, !tbaa !8
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 170, ptr noundef nonnull @__FUNCTION__.sm3_hkdf_expand) #7
  br label %.loopexit

19:                                               ; preds = %.lr.ph
  call void @sm3_hmac_init(ptr noundef nonnull %6, ptr noundef %0, i64 noundef 32) #6
  call void @sm3_hmac_update(ptr noundef nonnull %6, ptr noundef nonnull %7, i64 noundef %.239) #6
  call void @sm3_hmac_update(ptr noundef nonnull %6, ptr noundef %1, i64 noundef %2) #6
  call void @sm3_hmac_update(ptr noundef nonnull %6, ptr noundef nonnull %8, i64 noundef 1) #6
  call void @sm3_hmac_finish(ptr noundef nonnull %6, ptr noundef nonnull %7) #6
  %20 = load i8, ptr %8, align 1, !tbaa !5
  %21 = add i8 %20, 1
  store i8 %21, ptr %8, align 1, !tbaa !5
  %spec.select35 = call i64 @llvm.umin.i64(i64 %.13037, i64 32)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %.12838, ptr noundef nonnull align 16 dereferenceable(1) %7, i64 %spec.select35, i1 false)
  %22 = getelementptr inbounds i8, ptr %.12838, i64 %spec.select35
  %23 = sub i64 %.13037, %spec.select35
  %.not34 = icmp eq i64 %23, 0
  br i1 %.not34, label %.loopexit, label %.lr.ph, !llvm.loop !10

.loopexit:                                        ; preds = %19, %5, %9, %16
  %.031 = phi i32 [ -1, %16 ], [ 1, %9 ], [ 1, %5 ], [ 1, %19 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %8) #6
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #6
  call void @llvm.lifetime.end.p0(i64 176, ptr nonnull %6) #6
  ret i32 %.031
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #5

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass