; LLVM IR from openssl/openssl :: providers/implementations/rands (drbg_hmac)

; 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.drbg_hmac_st = type { ptr, %struct.PROV_DIGEST, i64, [64 x i8], [64 x i8] }
%struct.PROV_DIGEST = type { ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
declare hidden i32 @drbg_hmac_update(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_drbg_hmac_generate(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = 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 ptr %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.drbg_hmac_st, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  store ptr %17, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.drbg_hmac_st, ptr %18, i32 0, i32 4
  %20 = getelementptr inbounds [64 x i8], ptr %19, i64 0, i64 0
  store ptr %20, ptr %13, align 8, !tbaa !5
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %33

23:                                               ; preds = %5
  %24 = load i64, ptr %11, align 8, !tbaa !9
  %25 = icmp ugt i64 %24, 0
  br i1 %25, label %26, label %33

26:                                               ; preds = %23
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = load i64, ptr %11, align 8, !tbaa !9
  %30 = call i32 @drbg_hmac_update(ptr noundef %27, ptr noundef %28, i64 noundef %29, ptr noundef null, i64 noundef 0, ptr noundef null, i64 noundef 0)
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %26
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %101

33:                                               ; preds = %26, %23, %5
  br label %34

34:                                               ; preds = %82, %33
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.drbg_hmac_st, ptr %36, i32 0, i32 3
  %38 = getelementptr inbounds [64 x i8], ptr %37, i64 0, i64 0
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.drbg_hmac_st, ptr %39, i32 0, i32 2
  %41 = load i64, ptr %40, align 8, !tbaa !14
  %42 = call i32 @EVP_MAC_init(ptr noundef %35, ptr noundef %38, i64 noundef %41, ptr noundef null)
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %52

44:                                               ; preds = %34
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = load ptr, ptr %13, align 8, !tbaa !5
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.drbg_hmac_st, ptr %47, i32 0, i32 2
  %49 = load i64, ptr %48, align 8, !tbaa !14
  %50 = call i32 @EVP_MAC_update(ptr noundef %45, ptr noundef %46, i64 noundef %49)
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %53, label %52

52:                                               ; preds = %44, %34
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %101

53:                                               ; preds = %44
  %54 = load i64, ptr %9, align 8, !tbaa !9
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.drbg_hmac_st, ptr %55, i32 0, i32 2
  %57 = load i64, ptr %56, align 8, !tbaa !14
  %58 = icmp ugt i64 %54, %57
  br i1 %58, label %59, label %68

59:                                               ; preds = %53
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load i64, ptr %9, align 8, !tbaa !9
  %63 = call i32 @EVP_MAC_final(ptr noundef %60, ptr noundef %61, ptr noundef null, i64 noundef %62)
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %66, label %65

65:                                               ; preds = %59
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %101

66:                                               ; preds = %59
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %67, ptr %13, align 8, !tbaa !5
  br label %82

68:                                               ; preds = %53
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.drbg_hmac_st, ptr %70, i32 0, i32 4
  %72 = getelementptr inbounds [64 x i8], ptr %71, i64 0, i64 0
  %73 = call i32 @EVP_MAC_final(ptr noundef %69, ptr noundef %72, ptr noundef null, i64 noundef 64)
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %76, label %75

75:                                               ; preds = %68
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %101

76:                                               ; preds = %68
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.drbg_hmac_st, ptr %78, i32 0, i32 4
  %80 = getelementptr inbounds [64 x i8], ptr %79, i64 0, i64 0
  %81 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %77, ptr align 8 %80, i64 %81, i1 false)
  br label %93

82:                                               ; preds = %66
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.drbg_hmac_st, ptr %83, i32 0, i32 2
  %85 = load i64, ptr %84, align 8, !tbaa !14
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = getelementptr inbounds i8, ptr %86, i64 %85
  store ptr %87, ptr %8, align 8, !tbaa !5
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.drbg_hmac_st, ptr %88, i32 0, i32 2
  %90 = load i64, ptr %89, align 8, !tbaa !14
  %91 = load i64, ptr %9, align 8, !tbaa !9
  %92 = sub i64 %91, %90
  store i64 %92, ptr %9, align 8, !tbaa !9
  br label %34

93:                                               ; preds = %76
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = load ptr, ptr %10, align 8, !tbaa !5
  %96 = load i64, ptr %11, align 8, !tbaa !9
  %97 = call i32 @drbg_hmac_update(ptr noundef %94, ptr noundef %95, i64 noundef %96, ptr noundef null, i64 noundef 0, ptr noundef null, i64 noundef 0)
  %98 = icmp ne i32 %97, 0
  br i1 %98, label %100, label %99

99:                                               ; preds = %93
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %101

100:                                              ; preds = %93
  store i32 1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %101

101:                                              ; preds = %100, %99, %75, %65, %52, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %102 = load i32, ptr %6, align 4
  ret i32 %102
}

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

declare i32 @EVP_MAC_init(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #2

declare i32 @EVP_MAC_update(ptr noundef, ptr noundef, i64 noundef) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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, !6, i64 0}
!12 = !{!"drbg_hmac_st", !6, i64 0, !13, i64 8, !10, i64 32, !7, i64 40, !7, i64 104}
!13 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!12, !10, i64 32}


; 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: nounwind uwtable
declare hidden i32 @drbg_hmac_update(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_drbg_hmac_generate(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 104
  %8 = icmp ne ptr %3, null
  %9 = icmp ne i64 %4, 0
  %or.cond = and i1 %8, %9
  br i1 %or.cond, label %10, label %12

10:                                               ; preds = %5
  %11 = tail call i32 @drbg_hmac_update(ptr noundef nonnull %0, ptr noundef nonnull %3, i64 noundef %4, ptr noundef null, i64 noundef 0, ptr noundef null, i64 noundef 0)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %.loopexit, label %12

12:                                               ; preds = %10, %5
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %15 = load i64, ptr %14, align 8, !tbaa !12
  %16 = tail call i32 @EVP_MAC_init(ptr noundef %6, ptr noundef nonnull %13, i64 noundef %15, ptr noundef null) #3
  %.not3744 = icmp eq i32 %16, 0
  br i1 %.not3744, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %12, %24
  %.047 = phi ptr [ %.03346, %24 ], [ %7, %12 ]
  %.03346 = phi ptr [ %26, %24 ], [ %1, %12 ]
  %.03445 = phi i64 [ %27, %24 ], [ %2, %12 ]
  %17 = load i64, ptr %14, align 8, !tbaa !12
  %18 = tail call i32 @EVP_MAC_update(ptr noundef %6, ptr noundef %.047, i64 noundef %17) #3
  %.not38 = icmp eq i32 %18, 0
  br i1 %.not38, label %.loopexit, label %19

19:                                               ; preds = %.lr.ph
  %20 = load i64, ptr %14, align 8, !tbaa !12
  %21 = icmp ugt i64 %.03445, %20
  br i1 %21, label %22, label %29

22:                                               ; preds = %19
  %23 = tail call i32 @EVP_MAC_final(ptr noundef %6, ptr noundef %.03346, ptr noundef null, i64 noundef %.03445) #3
  %.not41 = icmp eq i32 %23, 0
  br i1 %.not41, label %.loopexit, label %24

24:                                               ; preds = %22
  %25 = load i64, ptr %14, align 8, !tbaa !12
  %26 = getelementptr inbounds i8, ptr %.03346, i64 %25
  %27 = sub i64 %.03445, %25
  %28 = tail call i32 @EVP_MAC_init(ptr noundef %6, ptr noundef nonnull %13, i64 noundef %25, ptr noundef null) #3
  %.not37 = icmp eq i32 %28, 0
  br i1 %.not37, label %.loopexit, label %.lr.ph

29:                                               ; preds = %19
  %30 = tail call i32 @EVP_MAC_final(ptr noundef %6, ptr noundef nonnull %7, ptr noundef null, i64 noundef 64) #3
  %.not39 = icmp eq i32 %30, 0
  br i1 %.not39, label %.loopexit, label %31

31:                                               ; preds = %29
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %.03346, ptr nonnull align 8 %7, i64 %.03445, i1 false)
  %32 = tail call i32 @drbg_hmac_update(ptr noundef nonnull %0, ptr noundef %3, i64 noundef %4, ptr noundef null, i64 noundef 0, ptr noundef null, i64 noundef 0)
  %.not40 = icmp ne i32 %32, 0
  %. = zext i1 %.not40 to i32
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %24, %22, %12, %31, %29, %10
  %.032 = phi i32 [ 0, %10 ], [ 0, %29 ], [ %., %31 ], [ 0, %12 ], [ 0, %22 ], [ 0, %24 ], [ 0, %.lr.ph ]
  ret i32 %.032
}

declare i32 @EVP_MAC_init(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @EVP_MAC_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare i32 @EVP_MAC_final(ptr noundef, ptr noundef, ptr noundef, i64 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

attributes #0 = { 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 #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 = { 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, !7, i64 0}
!6 = !{!"drbg_hmac_st", !7, i64 0, !10, i64 8, !11, i64 32, !8, i64 40, !8, i64 104}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !11, i64 32}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass