; LLVM IR from ARMmbed/mbed-crypto :: library (asn1write)

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

; 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 @mbedtls_asn1_write_named_bitstring(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i8, align 1
  %13 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #2
  %14 = load i64, ptr %8, align 8, !tbaa !9
  %15 = add i64 %14, 7
  %16 = udiv i64 %15, 8
  store i64 %16, ptr %10, align 8, !tbaa !9
  %17 = load i64, ptr %10, align 8, !tbaa !9
  %18 = mul i64 %17, 8
  %19 = load i64, ptr %8, align 8, !tbaa !9
  %20 = sub i64 %18, %19
  store i64 %20, ptr %9, align 8, !tbaa !9
  %21 = load i64, ptr %8, align 8, !tbaa !9
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %64

23:                                               ; preds = %4
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i64, ptr %10, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %24, i64 %25
  %27 = getelementptr inbounds i8, ptr %26, i64 -1
  store ptr %27, ptr %11, align 8, !tbaa !5
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = zext i8 %29 to i32
  %31 = load i64, ptr %9, align 8, !tbaa !9
  %32 = trunc i64 %31 to i32
  %33 = ashr i32 %30, %32
  %34 = trunc i32 %33 to i8
  store i8 %34, ptr %12, align 1, !tbaa !11
  br label %35

35:                                               ; preds = %62, %23
  %36 = load i8, ptr %12, align 1, !tbaa !11
  %37 = zext i8 %36 to i32
  %38 = and i32 %37, 1
  %39 = trunc i32 %38 to i8
  store i8 %39, ptr %13, align 1, !tbaa !11
  %40 = load i8, ptr %12, align 1, !tbaa !11
  %41 = zext i8 %40 to i32
  %42 = ashr i32 %41, 1
  %43 = trunc i32 %42 to i8
  store i8 %43, ptr %12, align 1, !tbaa !11
  %44 = load i8, ptr %13, align 1, !tbaa !11
  %45 = zext i8 %44 to i32
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %35
  br label %63

48:                                               ; preds = %35
  %49 = load i64, ptr %8, align 8, !tbaa !9
  %50 = add i64 %49, -1
  store i64 %50, ptr %8, align 8, !tbaa !9
  %51 = load i64, ptr %8, align 8, !tbaa !9
  %52 = icmp eq i64 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %48
  br label %63

54:                                               ; preds = %48
  %55 = load i64, ptr %8, align 8, !tbaa !9
  %56 = urem i64 %55, 8
  %57 = icmp eq i64 %56, 0
  br i1 %57, label %58, label %62

58:                                               ; preds = %54
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i32 -1
  store ptr %60, ptr %11, align 8, !tbaa !5
  %61 = load i8, ptr %60, align 1, !tbaa !11
  store i8 %61, ptr %12, align 1, !tbaa !11
  br label %62

62:                                               ; preds = %58, %54
  br label %35

63:                                               ; preds = %53, %47
  br label %64

64:                                               ; preds = %63, %4
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = load i64, ptr %8, align 8, !tbaa !9
  %69 = call i32 @mbedtls_asn1_write_bitstring(ptr noundef %65, ptr noundef %66, ptr noundef %67, i64 noundef %68)
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i32 %69
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_asn1_write_bitstring(ptr noundef, ptr noundef, ptr noundef, i64 noundef) #1

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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!7, !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"

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_asn1_write_named_bitstring(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %.loopexit, label %5

5:                                                ; preds = %4
  %6 = add i64 %3, 7
  %7 = and i64 %6, 4294967288
  %8 = sub i64 %7, %3
  %9 = lshr i64 %6, 3
  %10 = getelementptr inbounds i8, ptr %2, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 -1
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = zext i8 %12 to i32
  %14 = trunc i64 %8 to i32
  %15 = lshr i32 %13, %14
  %16 = trunc nuw i32 %15 to i8
  %17 = and i8 %16, 1
  %.not2627 = icmp eq i8 %17, 0
  br i1 %.not2627, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %5, %27
  %.in = phi i8 [ %.119, %27 ], [ %16, %5 ]
  %.029 = phi i64 [ %18, %27 ], [ %3, %5 ]
  %.02028 = phi ptr [ %.121, %27 ], [ %11, %5 ]
  %18 = add i64 %.029, -1
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %.loopexit, label %20

20:                                               ; preds = %.lr.ph
  %21 = lshr i8 %.in, 1
  %22 = and i64 %18, 7
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %24, label %27

24:                                               ; preds = %20
  %25 = getelementptr inbounds i8, ptr %.02028, i64 -1
  %26 = load i8, ptr %25, align 1, !tbaa !5
  br label %27

27:                                               ; preds = %24, %20
  %.121 = phi ptr [ %25, %24 ], [ %.02028, %20 ]
  %.119 = phi i8 [ %26, %24 ], [ %21, %20 ]
  %28 = and i8 %.119, 1
  %.not26 = icmp eq i8 %28, 0
  br i1 %.not26, label %.lr.ph, label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %27, %5, %4
  %.1 = phi i64 [ 0, %4 ], [ %3, %5 ], [ 0, %.lr.ph ], [ %18, %27 ]
  %29 = tail call i32 @mbedtls_asn1_write_bitstring(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %.1)
  ret i32 %29
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_asn1_write_bitstring(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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