; LLVM IR from ARMmbed/mbed-crypto :: programs/util (pem2der)

; 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 [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @convert_pem_to_der(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %16, i64 %17
  store ptr %18, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 0, ptr %14, align 8, !tbaa !9
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = call ptr @strstr(ptr noundef %19, ptr noundef @.str) #5
  store ptr %20, ptr %11, align 8, !tbaa !5
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %24

23:                                               ; preds = %4
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %121

24:                                               ; preds = %4
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = call ptr @strstr(ptr noundef %25, ptr noundef @.str.1) #5
  store ptr %26, ptr %12, align 8, !tbaa !5
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %121

30:                                               ; preds = %24
  %31 = load ptr, ptr %11, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 10
  store ptr %32, ptr %11, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %44, %30
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = load ptr, ptr %13, align 8, !tbaa !5
  %36 = icmp ult ptr %34, %35
  br i1 %36, label %37, label %42

37:                                               ; preds = %33
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = zext i8 %39 to i32
  %41 = icmp ne i32 %40, 45
  br label %42

42:                                               ; preds = %37, %33
  %43 = phi i1 [ false, %33 ], [ %41, %37 ]
  br i1 %43, label %44, label %47

44:                                               ; preds = %42
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i32 1
  store ptr %46, ptr %11, align 8, !tbaa !5
  br label %33, !llvm.loop !12

47:                                               ; preds = %42
  br label %48

48:                                               ; preds = %59, %47
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = load ptr, ptr %13, align 8, !tbaa !5
  %51 = icmp ult ptr %49, %50
  br i1 %51, label %52, label %57

52:                                               ; preds = %48
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = zext i8 %54 to i32
  %56 = icmp eq i32 %55, 45
  br label %57

57:                                               ; preds = %52, %48
  %58 = phi i1 [ false, %48 ], [ %56, %52 ]
  br i1 %58, label %59, label %62

59:                                               ; preds = %57
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i32 1
  store ptr %61, ptr %11, align 8, !tbaa !5
  br label %48, !llvm.loop !14

62:                                               ; preds = %57
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = load i8, ptr %63, align 1, !tbaa !11
  %65 = zext i8 %64 to i32
  %66 = icmp eq i32 %65, 13
  br i1 %66, label %67, label %70

67:                                               ; preds = %62
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i32 1
  store ptr %69, ptr %11, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %67, %62
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = load i8, ptr %71, align 1, !tbaa !11
  %73 = zext i8 %72 to i32
  %74 = icmp eq i32 %73, 10
  br i1 %74, label %75, label %78

75:                                               ; preds = %70
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %76, i32 1
  store ptr %77, ptr %11, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %75, %70
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = icmp ule ptr %79, %80
  br i1 %81, label %86, label %82

82:                                               ; preds = %78
  %83 = load ptr, ptr %12, align 8, !tbaa !5
  %84 = load ptr, ptr %13, align 8, !tbaa !5
  %85 = icmp ugt ptr %83, %84
  br i1 %85, label %86, label %87

86:                                               ; preds = %82, %78
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %121

87:                                               ; preds = %82
  %88 = load ptr, ptr %11, align 8, !tbaa !5
  %89 = load ptr, ptr %12, align 8, !tbaa !5
  %90 = load ptr, ptr %11, align 8, !tbaa !5
  %91 = ptrtoint ptr %89 to i64
  %92 = ptrtoint ptr %90 to i64
  %93 = sub i64 %91, %92
  %94 = call i32 @mbedtls_base64_decode(ptr noundef null, i64 noundef 0, ptr noundef %14, ptr noundef %88, i64 noundef %93)
  store i32 %94, ptr %10, align 4, !tbaa !15
  %95 = load i32, ptr %10, align 4, !tbaa !15
  %96 = icmp eq i32 %95, -44
  br i1 %96, label %97, label %99

97:                                               ; preds = %87
  %98 = load i32, ptr %10, align 4, !tbaa !15
  store i32 %98, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %121

99:                                               ; preds = %87
  %100 = load i64, ptr %14, align 8, !tbaa !9
  %101 = load ptr, ptr %9, align 8, !tbaa !5
  %102 = load i64, ptr %101, align 8, !tbaa !9
  %103 = icmp ugt i64 %100, %102
  br i1 %103, label %104, label %105

104:                                              ; preds = %99
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %121

105:                                              ; preds = %99
  %106 = load ptr, ptr %8, align 8, !tbaa !5
  %107 = load i64, ptr %14, align 8, !tbaa !9
  %108 = load ptr, ptr %11, align 8, !tbaa !5
  %109 = load ptr, ptr %12, align 8, !tbaa !5
  %110 = load ptr, ptr %11, align 8, !tbaa !5
  %111 = ptrtoint ptr %109 to i64
  %112 = ptrtoint ptr %110 to i64
  %113 = sub i64 %111, %112
  %114 = call i32 @mbedtls_base64_decode(ptr noundef %106, i64 noundef %107, ptr noundef %14, ptr noundef %108, i64 noundef %113)
  store i32 %114, ptr %10, align 4, !tbaa !15
  %115 = icmp ne i32 %114, 0
  br i1 %115, label %116, label %118

116:                                              ; preds = %105
  %117 = load i32, ptr %10, align 4, !tbaa !15
  store i32 %117, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %121

118:                                              ; preds = %105
  %119 = load i64, ptr %14, align 8, !tbaa !9
  %120 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %119, ptr %120, align 8, !tbaa !9
  store i32 0, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %121

121:                                              ; preds = %118, %116, %104, %97, %86, %29, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %122 = load i32, ptr %5, align 4
  ret i32 %122
}

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

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strstr(ptr noundef, ptr noundef) #2

declare i32 @mbedtls_base64_decode(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i64 noundef) #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 = { nounwind willreturn memory(read) "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 = { "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}


; 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 [11 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @convert_pem_to_der(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = alloca i64, align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store i64 0, ptr %5, align 8, !tbaa !5
  %7 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) @.str) #5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %44, label %9

9:                                                ; preds = %4
  %10 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) @.str.1) #5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %44, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %7, i64 10
  %14 = icmp ult ptr %13, %6
  br i1 %14, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %12, %16
  %.03745 = phi ptr [ %17, %16 ], [ %13, %12 ]
  %15 = load i8, ptr %.03745, align 1, !tbaa !9
  %.not = icmp eq i8 %15, 45
  br i1 %.not, label %.critedge, label %16

16:                                               ; preds = %.lr.ph
  %17 = getelementptr inbounds i8, ptr %.03745, i64 1
  %18 = icmp ult ptr %17, %6
  br i1 %18, label %.lr.ph, label %.critedge, !llvm.loop !10

.critedge:                                        ; preds = %.lr.ph, %16, %12
  %.037.lcssa = phi ptr [ %13, %12 ], [ %17, %16 ], [ %.03745, %.lr.ph ]
  %19 = icmp ult ptr %.037.lcssa, %6
  br i1 %19, label %.lr.ph49, label %.critedge2

.lr.ph49:                                         ; preds = %.critedge, %22
  %.148 = phi ptr [ %23, %22 ], [ %.037.lcssa, %.critedge ]
  %20 = load i8, ptr %.148, align 1, !tbaa !9
  %21 = icmp eq i8 %20, 45
  br i1 %21, label %22, label %.critedge2

22:                                               ; preds = %.lr.ph49
  %23 = getelementptr inbounds i8, ptr %.148, i64 1
  %24 = icmp ult ptr %23, %6
  br i1 %24, label %.lr.ph49, label %.critedge2, !llvm.loop !12

.critedge2:                                       ; preds = %.lr.ph49, %22, %.critedge
  %.1.lcssa = phi ptr [ %.037.lcssa, %.critedge ], [ %23, %22 ], [ %.148, %.lr.ph49 ]
  %25 = load i8, ptr %.1.lcssa, align 1, !tbaa !9
  %26 = icmp eq i8 %25, 13
  %spec.select.idx = zext i1 %26 to i64
  %spec.select = getelementptr inbounds i8, ptr %.1.lcssa, i64 %spec.select.idx
  %27 = load i8, ptr %spec.select, align 1, !tbaa !9
  %28 = icmp eq i8 %27, 10
  %.3.idx = zext i1 %28 to i64
  %.3 = getelementptr inbounds i8, ptr %spec.select, i64 %.3.idx
  %.not43 = icmp ule ptr %10, %.3
  %29 = icmp ugt ptr %10, %6
  %or.cond = select i1 %.not43, i1 true, i1 %29
  br i1 %or.cond, label %44, label %30

30:                                               ; preds = %.critedge2
  %31 = ptrtoint ptr %10 to i64
  %32 = ptrtoint ptr %.3 to i64
  %33 = sub i64 %31, %32
  %34 = call i32 @mbedtls_base64_decode(ptr noundef null, i64 noundef 0, ptr noundef nonnull %5, ptr noundef nonnull %.3, i64 noundef %33) #4
  %35 = icmp eq i32 %34, -44
  br i1 %35, label %44, label %36

36:                                               ; preds = %30
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = icmp ugt i64 %37, %38
  br i1 %39, label %44, label %40

40:                                               ; preds = %36
  %41 = call i32 @mbedtls_base64_decode(ptr noundef %2, i64 noundef %37, ptr noundef nonnull %5, ptr noundef nonnull %.3, i64 noundef %33) #4
  %.not44 = icmp eq i32 %41, 0
  br i1 %.not44, label %42, label %44

42:                                               ; preds = %40
  %43 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %43, ptr %3, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %40, %36, %30, %.critedge2, %9, %4, %42
  %.0 = phi i32 [ 0, %42 ], [ -1, %4 ], [ -1, %9 ], [ -1, %.critedge2 ], [ -44, %30 ], [ -1, %36 ], [ %41, %40 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  ret i32 %.0
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strstr(ptr noundef, ptr nocapture noundef) local_unnamed_addr #2

declare i32 @mbedtls_base64_decode(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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