; LLVM IR from aws/s2n-tls :: tls (s2n_cipher_suites)

; 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.s2n_result = type { i32 }
%struct.s2n_cipher_suite = type { i8, ptr, ptr, [2 x i8], ptr, i32, ptr, [2 x ptr], i8, ptr, ptr, i32, i8 }

@s2n_all_cipher_suites = external hidden global [36 x ptr], align 16
@should_init_crypto = external hidden global 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 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 @s2n_cipher_suites_cleanup() #1 {
  %1 = alloca %struct.s2n_result, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 36, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %43, %0
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 36
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  store i32 2, ptr %4, align 4
  br label %46

10:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [36 x ptr], ptr @s2n_all_cipher_suites, i64 0, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %5, align 8, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = load i8, ptr %15, align 8
  %17 = and i8 %16, -2
  %18 = or i8 %17, 0
  store i8 %18, ptr %15, align 8
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.s2n_cipher_suite, ptr %19, i32 0, i32 6
  store ptr null, ptr %20, align 8, !tbaa !11
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.s2n_cipher_suite, ptr %21, i32 0, i32 10
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = load ptr, ptr %5, align 8, !tbaa !9
  %25 = icmp ne ptr %23, %24
  br i1 %25, label %26, label %37

26:                                               ; preds = %10
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %5, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.s2n_cipher_suite, ptr %28, i32 0, i32 10
  %30 = call i32 @s2n_free_object(ptr noundef %29, i32 noundef 104)
  %31 = icmp sgt i32 %30, -1
  br i1 %31, label %34, label %32

32:                                               ; preds = %27
  %33 = getelementptr inbounds %struct.s2n_result, ptr %1, i32 0, i32 0
  store i32 -1, ptr %33, align 4, !tbaa !14
  store i32 1, ptr %4, align 4
  br label %40

34:                                               ; preds = %27
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36, %10
  %38 = load ptr, ptr %5, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.s2n_cipher_suite, ptr %38, i32 0, i32 10
  store ptr null, ptr %39, align 8, !tbaa !13
  store i32 0, ptr %4, align 4
  br label %40

40:                                               ; preds = %37, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %41 = load i32, ptr %4, align 4
  switch i32 %41, label %46 [
    i32 0, label %42
  ]

42:                                               ; preds = %40
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %3, align 4, !tbaa !5
  br label %6, !llvm.loop !16

46:                                               ; preds = %40, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %47 = load i32, ptr %4, align 4
  switch i32 %47, label %54 [
    i32 2, label %48
  ]

48:                                               ; preds = %46
  %49 = load i8, ptr @should_init_crypto, align 1, !tbaa !18, !range !20, !noundef !21
  %50 = trunc i8 %49 to i1
  br i1 %50, label %51, label %52

51:                                               ; preds = %48
  br label %52

52:                                               ; preds = %51, %48
  %53 = getelementptr inbounds %struct.s2n_result, ptr %1, i32 0, i32 0
  store i32 0, ptr %53, align 4, !tbaa !14
  store i32 1, ptr %4, align 4
  br label %54

54:                                               ; preds = %52, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %55 = getelementptr inbounds %struct.s2n_result, ptr %1, i32 0, i32 0
  %56 = load i32, ptr %55, align 4
  ret i32 %56
}

declare i32 @s2n_free_object(ptr noundef, i32 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 48}
!12 = !{!"s2n_cipher_suite", !6, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !10, i64 32, !6, i64 40, !10, i64 48, !7, i64 56, !7, i64 72, !10, i64 80, !10, i64 88, !6, i64 96, !7, i64 100}
!13 = !{!12, !10, i64 88}
!14 = !{!15, !6, i64 0}
!15 = !{!"", !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !19, i64 0}
!19 = !{!"_Bool", !7, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}


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

@s2n_all_cipher_suites = external hidden local_unnamed_addr global [36 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_cipher_suites_cleanup() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %0, %.critedge
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %.critedge ]
  %2 = phi i1 [ true, %0 ], [ %13, %.critedge ]
  %3 = getelementptr inbounds [36 x ptr], ptr @s2n_all_cipher_suites, i64 0, i64 %indvars.iv
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load i8, ptr %4, align 8
  %6 = and i8 %5, -2
  store i8 %6, ptr %4, align 8
  %7 = getelementptr inbounds i8, ptr %4, i64 48
  store ptr null, ptr %7, align 8, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %4, i64 88
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %.not = icmp eq ptr %9, %4
  br i1 %.not, label %.critedge, label %10

10:                                               ; preds = %1
  %11 = tail call i32 @s2n_free_object(ptr noundef nonnull %8, i32 noundef 104) #2
  %12 = icmp sgt i32 %11, -1
  br i1 %12, label %.critedge, label %14

.critedge:                                        ; preds = %10, %1
  store ptr null, ptr %8, align 8, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = icmp ult i64 %indvars.iv, 35
  %exitcond.not = icmp eq i64 %indvars.iv.next, 36
  br i1 %exitcond.not, label %14, label %1, !llvm.loop !13

14:                                               ; preds = %10, %.critedge
  %.lcssa = phi i1 [ %2, %10 ], [ %13, %.critedge ]
  %spec.select = sext i1 %.lcssa to i32
  ret i32 %spec.select
}

declare i32 @s2n_free_object(ptr noundef, i32 noundef) local_unnamed_addr #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 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 48}
!10 = !{!"s2n_cipher_suite", !11, i64 0, !6, i64 8, !6, i64 16, !7, i64 24, !6, i64 32, !11, i64 40, !6, i64 48, !7, i64 56, !7, i64 72, !6, i64 80, !6, i64 88, !11, i64 96, !7, i64 100}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 88}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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