; LLVM IR from aws/s2n-tls :: tests/testlib (s2n_test_certs)

; 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_stuffer = type { %struct.s2n_blob, i32, i32, i32, i8 }
%struct.s2n_blob = type { ptr, i32, i32, i8 }

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

declare ptr @s2n_cert_chain_and_key_new() #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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_test_cert_chain_data_from_pem_data(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #3 {
  %5 = alloca %struct.s2n_result, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca %struct.s2n_stuffer, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca %struct.s2n_result, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %10) #4
  call void @llvm.memset.p0.i64(ptr align 8 %10, i8 0, i64 40, i1 false)
  br label %15

15:                                               ; preds = %4
  %16 = call i32 @s2n_stuffer_growable_alloc(ptr noundef %10, i32 noundef 4096)
  %17 = icmp sgt i32 %16, -1
  br i1 %17, label %20, label %18

18:                                               ; preds = %15
  %19 = getelementptr inbounds %struct.s2n_result, ptr %5, i32 0, i32 0
  store i32 -1, ptr %19, align 4, !tbaa !11
  store i32 1, ptr %11, align 4
  br label %83

20:                                               ; preds = %15
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %23 = call ptr @s2n_cert_chain_and_key_new()
  store ptr %23, ptr %12, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %22
  %25 = load ptr, ptr %12, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = call i32 @s2n_cert_chain_and_key_load_public_pem_bytes(ptr noundef %25, ptr noundef %26, i32 noundef %27)
  %29 = icmp sgt i32 %28, -1
  br i1 %29, label %32, label %30

30:                                               ; preds = %24
  %31 = getelementptr inbounds %struct.s2n_result, ptr %5, i32 0, i32 0
  store i32 -1, ptr %31, align 4, !tbaa !11
  store i32 1, ptr %11, align 4
  br label %80

32:                                               ; preds = %24
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  %38 = call i32 @s2n_send_cert_chain(ptr noundef %36, ptr noundef %10, ptr noundef %37)
  %39 = icmp sgt i32 %38, -1
  br i1 %39, label %42, label %40

40:                                               ; preds = %35
  %41 = getelementptr inbounds %struct.s2n_result, ptr %5, i32 0, i32 0
  store i32 -1, ptr %41, align 4, !tbaa !11
  store i32 1, ptr %11, align 4
  br label %80

42:                                               ; preds = %35
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  %46 = call i32 @s2n_stuffer_skip_read(ptr noundef %10, i32 noundef 3)
  %47 = icmp sgt i32 %46, -1
  br i1 %47, label %50, label %48

48:                                               ; preds = %45
  %49 = getelementptr inbounds %struct.s2n_result, ptr %5, i32 0, i32 0
  store i32 -1, ptr %49, align 4, !tbaa !11
  store i32 1, ptr %11, align 4
  br label %80

50:                                               ; preds = %45
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %53 = getelementptr inbounds %struct.s2n_stuffer, ptr %10, i32 0, i32 2
  %54 = load i32, ptr %53, align 4, !tbaa !13
  %55 = getelementptr inbounds %struct.s2n_stuffer, ptr %10, i32 0, i32 1
  %56 = load i32, ptr %55, align 8, !tbaa !16
  %57 = sub i32 %54, %56
  store i32 %57, ptr %13, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %52
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = load i32, ptr %13, align 4, !tbaa !9
  %61 = call i32 @s2n_stuffer_alloc(ptr noundef %59, i32 noundef %60)
  %62 = icmp sgt i32 %61, -1
  br i1 %62, label %65, label %63

63:                                               ; preds = %58
  %64 = getelementptr inbounds %struct.s2n_result, ptr %5, i32 0, i32 0
  store i32 -1, ptr %64, align 4, !tbaa !11
  store i32 1, ptr %11, align 4
  br label %79

65:                                               ; preds = %58
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = load i32, ptr %13, align 4, !tbaa !9
  %71 = call i32 @s2n_stuffer_copy(ptr noundef %10, ptr noundef %69, i32 noundef %70)
  %72 = icmp sgt i32 %71, -1
  br i1 %72, label %75, label %73

73:                                               ; preds = %68
  %74 = getelementptr inbounds %struct.s2n_result, ptr %5, i32 0, i32 0
  store i32 -1, ptr %74, align 4, !tbaa !11
  store i32 1, ptr %11, align 4
  br label %79

75:                                               ; preds = %68
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  %78 = getelementptr inbounds %struct.s2n_result, ptr %5, i32 0, i32 0
  store i32 0, ptr %78, align 4, !tbaa !11
  store i32 1, ptr %11, align 4
  br label %79

79:                                               ; preds = %77, %73, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %80

80:                                               ; preds = %79, %48, %40, %30
  %81 = call i32 @s2n_cert_chain_and_key_ptr_free(ptr noundef %12)
  %82 = getelementptr inbounds %struct.s2n_result, ptr %14, i32 0, i32 0
  store i32 %81, ptr %82, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %83

83:                                               ; preds = %80, %18
  %84 = call i32 @s2n_stuffer_free(ptr noundef %10)
  call void @llvm.lifetime.end.p0(i64 40, ptr %10) #4
  %85 = getelementptr inbounds %struct.s2n_result, ptr %5, i32 0, i32 0
  %86 = load i32, ptr %85, align 4
  ret i32 %86
}

declare i32 @s2n_stuffer_free(ptr noundef) #1

declare i32 @s2n_stuffer_growable_alloc(ptr noundef, i32 noundef) #1

declare i32 @s2n_cert_chain_and_key_ptr_free(ptr noundef) #1

declare i32 @s2n_cert_chain_and_key_load_public_pem_bytes(ptr noundef, ptr noundef, i32 noundef) #1

declare i32 @s2n_send_cert_chain(ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @s2n_stuffer_skip_read(ptr noundef, i32 noundef) #1

declare i32 @s2n_stuffer_alloc(ptr noundef, i32 noundef) #1

declare i32 @s2n_stuffer_copy(ptr noundef, ptr noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0}
!13 = !{!14, !10, i64 28}
!14 = !{!"s2n_stuffer", !15, i64 0, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 36, !10, i64 36}
!15 = !{!"s2n_blob", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!16 = !{!14, !10, i64 24}


; 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.s2n_stuffer = type { %struct.s2n_blob, i32, i32, i32, i8 }
%struct.s2n_blob = type { ptr, i32, i32, i8 }

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

declare ptr @s2n_cert_chain_and_key_new() 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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_test_cert_chain_data_from_pem_data(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #3 {
  %5 = alloca %struct.s2n_stuffer, align 8
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %5) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %5, i8 0, i64 40, i1 false)
  %7 = call i32 @s2n_stuffer_growable_alloc(ptr noundef nonnull %5, i32 noundef 4096) #4
  %8 = icmp sgt i32 %7, -1
  br i1 %8, label %9, label %31

9:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %10 = call ptr @s2n_cert_chain_and_key_new() #4
  store ptr %10, ptr %6, align 8, !tbaa !5
  %11 = call i32 @s2n_cert_chain_and_key_load_public_pem_bytes(ptr noundef %10, ptr noundef %1, i32 noundef %2) #4
  %12 = icmp sgt i32 %11, -1
  br i1 %12, label %13, label %29

13:                                               ; preds = %9
  %14 = call i32 @s2n_send_cert_chain(ptr noundef %0, ptr noundef nonnull %5, ptr noundef %10) #4
  %15 = icmp sgt i32 %14, -1
  br i1 %15, label %16, label %29

16:                                               ; preds = %13
  %17 = call i32 @s2n_stuffer_skip_read(ptr noundef nonnull %5, i32 noundef 3) #4
  %18 = icmp sgt i32 %17, -1
  br i1 %18, label %19, label %29

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %5, i64 28
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %5, i64 24
  %23 = load i32, ptr %22, align 8, !tbaa !13
  %24 = sub i32 %21, %23
  %25 = call i32 @s2n_stuffer_alloc(ptr noundef %3, i32 noundef %24) #4
  %26 = icmp sgt i32 %25, -1
  br i1 %26, label %27, label %29

27:                                               ; preds = %19
  %28 = call i32 @s2n_stuffer_copy(ptr noundef nonnull %5, ptr noundef %3, i32 noundef %24) #4
  %.lobit = ashr i32 %28, 31
  br label %29

29:                                               ; preds = %19, %27, %16, %13, %9
  %.sroa.06.1 = phi i32 [ -1, %9 ], [ -1, %13 ], [ -1, %16 ], [ -1, %19 ], [ %.lobit, %27 ]
  %30 = call i32 @s2n_cert_chain_and_key_ptr_free(ptr noundef nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  br label %31

31:                                               ; preds = %4, %29
  %.sroa.06.2 = phi i32 [ %.sroa.06.1, %29 ], [ -1, %4 ]
  %32 = call i32 @s2n_stuffer_free(ptr noundef nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %5) #4
  ret i32 %.sroa.06.2
}

declare i32 @s2n_stuffer_free(ptr noundef) local_unnamed_addr #1

declare i32 @s2n_stuffer_growable_alloc(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @s2n_cert_chain_and_key_ptr_free(ptr noundef) local_unnamed_addr #1

declare i32 @s2n_cert_chain_and_key_load_public_pem_bytes(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @s2n_send_cert_chain(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @s2n_stuffer_skip_read(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @s2n_stuffer_alloc(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @s2n_stuffer_copy(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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: write) }
attributes #3 = { 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 #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, !12, i64 28}
!10 = !{!"s2n_stuffer", !11, i64 0, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 36, !12, i64 36}
!11 = !{!"s2n_blob", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 24}


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