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

@.str = external hidden unnamed_addr constant [50 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [48 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 uwtable
declare dso_local i32 @s2n_read_test_pem(ptr noundef, ptr noundef, i64 noundef) #1

declare ptr @s2n_cert_chain_and_key_new() #2

declare i32 @s2n_cert_chain_and_key_load_pem(ptr noundef, ptr noundef, ptr noundef) #2

; 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_test_cert_permutation_load_server_chain(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca [512 x i8], align 16
  %13 = alloca [12000 x i8], align 16
  %14 = alloca [12000 x i8], align 16
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 512, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 12000, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 12000, ptr %14) #4
  %16 = getelementptr inbounds [512 x i8], ptr %12, i64 0, i64 0
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = load ptr, ptr %11, align 8, !tbaa !5
  %21 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %16, ptr noundef @.str, ptr noundef %17, ptr noundef %18, ptr noundef %19, ptr noundef %20) #4
  br label %22

22:                                               ; preds = %5
  %23 = getelementptr inbounds [512 x i8], ptr %12, i64 0, i64 0
  %24 = getelementptr inbounds [12000 x i8], ptr %13, i64 0, i64 0
  %25 = call i32 @s2n_read_test_pem(ptr noundef %23, ptr noundef %24, i64 noundef 12000)
  %26 = icmp sgt i32 %25, -1
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %65

28:                                               ; preds = %22
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  %31 = getelementptr inbounds [512 x i8], ptr %12, i64 0, i64 0
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %31, ptr noundef @.str.1, ptr noundef %32, ptr noundef %33, ptr noundef %34, ptr noundef %35) #4
  br label %37

37:                                               ; preds = %30
  %38 = getelementptr inbounds [512 x i8], ptr %12, i64 0, i64 0
  %39 = getelementptr inbounds [12000 x i8], ptr %14, i64 0, i64 0
  %40 = call i32 @s2n_read_test_pem(ptr noundef %38, ptr noundef %39, i64 noundef 12000)
  %41 = icmp sgt i32 %40, -1
  br i1 %41, label %43, label %42

42:                                               ; preds = %37
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %65

43:                                               ; preds = %37
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45
  %47 = call ptr @s2n_cert_chain_and_key_new()
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %47, ptr %48, align 8, !tbaa !5
  %49 = icmp ne ptr %47, null
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %65

51:                                               ; preds = %46
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = getelementptr inbounds [12000 x i8], ptr %13, i64 0, i64 0
  %58 = getelementptr inbounds [12000 x i8], ptr %14, i64 0, i64 0
  %59 = call i32 @s2n_cert_chain_and_key_load_pem(ptr noundef %56, ptr noundef %57, ptr noundef %58)
  %60 = icmp sgt i32 %59, -1
  br i1 %60, label %62, label %61

61:                                               ; preds = %54
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %65

62:                                               ; preds = %54
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %65

65:                                               ; preds = %64, %61, %50, %42, %27
  call void @llvm.lifetime.end.p0(i64 12000, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 12000, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 512, ptr %12) #4
  %66 = load i32, ptr %6, align 4
  ret i32 %66
}

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #3

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


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

@.str = external hidden unnamed_addr constant [50 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [48 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: nounwind uwtable
declare dso_local i32 @s2n_read_test_pem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare ptr @s2n_cert_chain_and_key_new() local_unnamed_addr #2

declare i32 @s2n_cert_chain_and_key_load_pem(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 range(i32 -1, 1) i32 @s2n_test_cert_permutation_load_server_chain(ptr nocapture noundef writeonly %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = alloca [512 x i8], align 16
  %7 = alloca [12000 x i8], align 16
  %8 = alloca [12000 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 512, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 12000, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 12000, ptr nonnull %8) #4
  %9 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %6, ptr noundef nonnull dereferenceable(1) @.str, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #4
  %10 = call i32 @s2n_read_test_pem(ptr noundef nonnull %6, ptr noundef nonnull %7, i64 noundef 12000)
  %11 = icmp sgt i32 %10, -1
  br i1 %11, label %12, label %20

12:                                               ; preds = %5
  %13 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %6, ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #4
  %14 = call i32 @s2n_read_test_pem(ptr noundef nonnull %6, ptr noundef nonnull %8, i64 noundef 12000)
  %15 = icmp sgt i32 %14, -1
  br i1 %15, label %16, label %20

16:                                               ; preds = %12
  %17 = call ptr @s2n_cert_chain_and_key_new() #4
  store ptr %17, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %17, null
  br i1 %.not, label %20, label %18

18:                                               ; preds = %16
  %19 = call i32 @s2n_cert_chain_and_key_load_pem(ptr noundef nonnull %17, ptr noundef nonnull %7, ptr noundef nonnull %8) #4
  %.lobit = ashr i32 %19, 31
  br label %20

20:                                               ; preds = %18, %16, %12, %5
  %.0 = phi i32 [ -1, %5 ], [ -1, %12 ], [ -1, %16 ], [ %.lobit, %18 ]
  call void @llvm.lifetime.end.p0(i64 12000, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 12000, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 512, ptr nonnull %6) #4
  ret i32 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { 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 #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"}


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