; LLVM IR from intel/intel-ipsec-mb :: test/imb-provider (prov_sw_gcm)

; 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.prov_gcm_ctx_st = type { %struct.gcm_key_data, %struct.gcm_context_data, i32, i32, ptr, i32, ptr, ptr, i32, ptr, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, i32, i64, i64, i64, i64, i64, i64, i8, [16 x i8], ptr, ptr, [48 x i8] }
%struct.gcm_key_data = type { [240 x i8], %union.anon }
%union.anon = type { %struct.anon.1 }
%struct.anon.1 = type { [1024 x i8] }
%struct.gcm_context_data = type { [16 x i8], i64, i64, [16 x i8], [16 x i8], [16 x i8], i64 }

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

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

14:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %72

15:                                               ; preds = %1
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  store i32 0, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %72

19:                                               ; preds = %15
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = call i32 @prov_aes_gcm_ctx_get_nid(ptr noundef %20)
  store i32 %21, ptr %5, align 4, !tbaa !9
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = call i32 @prov_check_gcm_nid(i32 noundef %22)
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %26, label %25

25:                                               ; preds = %19
  store i32 0, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %72

26:                                               ; preds = %19
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.prov_gcm_ctx_st, ptr %27, i32 0, i32 3
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %71

31:                                               ; preds = %26
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.prov_gcm_ctx_st, ptr %32, i32 0, i32 14
  %34 = load i32, ptr %33, align 16, !tbaa !16
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %41, label %36

36:                                               ; preds = %31
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.prov_gcm_ctx_st, ptr %37, i32 0, i32 16
  %39 = load i32, ptr %38, align 8, !tbaa !17
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %71

41:                                               ; preds = %36, %31
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.prov_gcm_ctx_st, ptr %42, i32 0, i32 0
  store ptr %43, ptr %7, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.prov_gcm_ctx_st, ptr %44, i32 0, i32 1
  store ptr %45, ptr %8, align 8, !tbaa !5
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.prov_gcm_ctx_st, ptr %46, i32 0, i32 4
  %48 = load ptr, ptr %47, align 16, !tbaa !18
  store ptr %48, ptr %9, align 8, !tbaa !5
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.prov_gcm_ctx_st, ptr %49, i32 0, i32 11
  %51 = load i32, ptr %50, align 4, !tbaa !19
  store i32 %51, ptr %6, align 4, !tbaa !9
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.prov_gcm_ctx_st, ptr %52, i32 0, i32 11
  %54 = load i32, ptr %53, align 4, !tbaa !19
  %55 = icmp slt i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %41
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %56, %41
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.prov_gcm_ctx_st, ptr %61, i32 0, i32 18
  %63 = load ptr, ptr %62, align 8, !tbaa !20
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.prov_gcm_ctx_st, ptr %64, i32 0, i32 13
  %66 = load i32, ptr %65, align 4, !tbaa !21
  %67 = sext i32 %66 to i64
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  call void @prov_imb_aes_gcm_init_var_iv(i32 noundef %58, ptr noundef %59, ptr noundef %60, ptr noundef %63, i64 noundef %67, ptr noundef %68, i64 noundef %70)
  store i32 1, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %72

71:                                               ; preds = %36, %26
  store i32 0, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %72

72:                                               ; preds = %71, %57, %25, %18, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %73 = load i32, ptr %2, align 4
  ret i32 %73
}

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

declare i32 @prov_aes_gcm_ctx_get_nid(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @prov_check_gcm_nid(i32 noundef) #1

declare void @prov_imb_aes_gcm_init_var_iv(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

attributes #0 = { 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 = { "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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 1356}
!12 = !{!"prov_gcm_ctx_st", !13, i64 0, !14, i64 1264, !10, i64 1352, !10, i64 1356, !6, i64 1360, !10, i64 1368, !6, i64 1376, !6, i64 1384, !10, i64 1392, !6, i64 1400, !10, i64 1408, !10, i64 1412, !10, i64 1416, !10, i64 1420, !10, i64 1424, !10, i64 1428, !10, i64 1432, !6, i64 1440, !6, i64 1448, !10, i64 1456, !15, i64 1464, !15, i64 1472, !15, i64 1480, !15, i64 1488, !15, i64 1496, !15, i64 1504, !10, i64 1512, !10, i64 1512, !10, i64 1512, !7, i64 1513, !6, i64 1536, !6, i64 1544}
!13 = !{!"gcm_key_data", !7, i64 0, !7, i64 240}
!14 = !{!"gcm_context_data", !7, i64 0, !15, i64 16, !15, i64 24, !7, i64 32, !7, i64 48, !7, i64 64, !15, i64 80}
!15 = !{!"long", !7, i64 0}
!16 = !{!12, !10, i64 1424}
!17 = !{!12, !10, i64 1432}
!18 = !{!12, !6, i64 1360}
!19 = !{!12, !10, i64 1412}
!20 = !{!12, !6, i64 1448}
!21 = !{!12, !10, i64 1420}


; 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
define dso_local range(i32 0, 2) i32 @vaesgcm_init_gcm(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %27, label %3

3:                                                ; preds = %1
  %4 = tail call i32 @prov_aes_gcm_ctx_get_nid(ptr noundef nonnull %0) #3
  %5 = tail call i32 @prov_check_gcm_nid(i32 noundef %4)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %27, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 1356
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not21 = icmp eq i32 %8, 0
  br i1 %.not21, label %27, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 1424
  %11 = load i32, ptr %10, align 16, !tbaa !14
  %.not22 = icmp eq i32 %11, 0
  br i1 %.not22, label %12, label %15

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 1432
  %14 = load i32, ptr %13, align 8, !tbaa !15
  %.not23 = icmp eq i32 %14, 0
  br i1 %.not23, label %27, label %15

15:                                               ; preds = %12, %9
  %16 = getelementptr inbounds i8, ptr %0, i64 1264
  %17 = getelementptr inbounds i8, ptr %0, i64 1360
  %18 = load ptr, ptr %17, align 16, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %0, i64 1412
  %20 = load i32, ptr %19, align 4, !tbaa !17
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %20, i32 0)
  %21 = getelementptr inbounds i8, ptr %0, i64 1448
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %23 = getelementptr inbounds i8, ptr %0, i64 1420
  %24 = load i32, ptr %23, align 4, !tbaa !19
  %25 = sext i32 %24 to i64
  %26 = zext nneg i32 %spec.store.select to i64
  tail call void @prov_imb_aes_gcm_init_var_iv(i32 noundef %4, ptr noundef nonnull %0, ptr noundef nonnull %16, ptr noundef %22, i64 noundef %25, ptr noundef %18, i64 noundef %26) #3
  br label %27

27:                                               ; preds = %6, %12, %3, %1, %15
  %.0 = phi i32 [ 1, %15 ], [ 0, %1 ], [ 0, %3 ], [ 0, %12 ], [ 0, %6 ]
  ret i32 %.0
}

declare i32 @prov_aes_gcm_ctx_get_nid(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @prov_check_gcm_nid(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !12, i64 1356}
!6 = !{!"prov_gcm_ctx_st", !7, i64 0, !10, i64 1264, !12, i64 1352, !12, i64 1356, !13, i64 1360, !12, i64 1368, !13, i64 1376, !13, i64 1384, !12, i64 1392, !13, i64 1400, !12, i64 1408, !12, i64 1412, !12, i64 1416, !12, i64 1420, !12, i64 1424, !12, i64 1428, !12, i64 1432, !13, i64 1440, !13, i64 1448, !12, i64 1456, !11, i64 1464, !11, i64 1472, !11, i64 1480, !11, i64 1488, !11, i64 1496, !11, i64 1504, !12, i64 1512, !12, i64 1512, !12, i64 1512, !8, i64 1513, !13, i64 1536, !13, i64 1544}
!7 = !{!"gcm_key_data", !8, i64 0, !8, i64 240}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"gcm_context_data", !8, i64 0, !11, i64 16, !11, i64 24, !8, i64 32, !8, i64 48, !8, i64 64, !11, i64 80}
!11 = !{!"long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!6, !12, i64 1424}
!15 = !{!6, !12, i64 1432}
!16 = !{!6, !13, i64 1360}
!17 = !{!6, !12, i64 1412}
!18 = !{!6, !13, i64 1448}
!19 = !{!6, !12, i64 1420}


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