; LLVM IR from number571/c-crypto-lib :: crypto/cipher (a1z26)

; 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 [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @to_string_a1z26(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca [5 x i8], align 1
  %10 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call i64 @_length(i8 noundef zeroext 99, ptr noundef %11, i8 noundef signext -128)
  store i64 %12, ptr %5, align 8, !tbaa !9
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = mul i64 %13, 4
  %15 = add i64 %14, 1
  %16 = call ptr @llvm.stacksave.p0()
  store ptr %16, ptr %6, align 8
  %17 = alloca i8, i64 %15, align 16
  store i64 %15, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store ptr %17, ptr %8, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %47, %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = sext i8 %20 to i32
  %22 = icmp ne i32 %21, -128
  br i1 %22, label %23, label %50

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 5, ptr %9) #5
  %24 = getelementptr inbounds [5 x i8], ptr %9, i64 0, i64 0
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %24, ptr noundef @.str, i32 noundef %27) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %29 = getelementptr inbounds [5 x i8], ptr %9, i64 0, i64 0
  store ptr %29, ptr %10, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %41, %23
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = zext i8 %32 to i32
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %36, label %35

35:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %44

36:                                               ; preds = %30
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = load i8, ptr %37, align 1, !tbaa !11
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i32 1
  store ptr %40, ptr %8, align 8, !tbaa !5
  store i8 %38, ptr %39, align 1, !tbaa !11
  br label %41

41:                                               ; preds = %36
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i32 1
  store ptr %43, ptr %10, align 8, !tbaa !5
  br label %30, !llvm.loop !12

44:                                               ; preds = %35
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i32 1
  store ptr %46, ptr %8, align 8, !tbaa !5
  store i8 32, ptr %45, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 5, ptr %9) #5
  br label %47

47:                                               ; preds = %44
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i32 1
  store ptr %49, ptr %4, align 8, !tbaa !5
  br label %18, !llvm.loop !14

50:                                               ; preds = %18
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i32 -1
  store ptr %52, ptr %8, align 8, !tbaa !5
  store i8 0, ptr %52, align 1, !tbaa !11
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = call ptr @strcpy(ptr noundef %53, ptr noundef %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %55 = load ptr, ptr %6, align 8
  call void @llvm.stackrestore.p0(ptr %55)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @_length(i8 noundef zeroext, ptr noundef, i8 noundef signext) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

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

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

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

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 = { inlinehint 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 #3 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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 #5 = { 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}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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 [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @to_string_a1z26(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca [5 x i8], align 1
  %4 = tail call i64 @_length(i8 noundef zeroext 99, ptr noundef %1, i8 noundef signext -128)
  %5 = shl i64 %4, 2
  %6 = or disjoint i64 %5, 1
  %7 = alloca i8, i64 %6, align 16
  %8 = load i8, ptr %1, align 1, !tbaa !5
  %.not18 = icmp eq i8 %8, -128
  br i1 %.not18, label %._crit_edge23, label %.lr.ph22

.lr.ph22:                                         ; preds = %2, %._crit_edge
  %9 = phi i8 [ %15, %._crit_edge ], [ %8, %2 ]
  %.01220 = phi ptr [ %13, %._crit_edge ], [ %7, %2 ]
  %.01319 = phi ptr [ %14, %._crit_edge ], [ %1, %2 ]
  call void @llvm.lifetime.start.p0(i64 5, ptr nonnull %3) #5
  %10 = sext i8 %9 to i32
  %11 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %10) #5
  %12 = load i8, ptr %3, align 1, !tbaa !5
  %.not1415 = icmp eq i8 %12, 0
  br i1 %.not1415, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph22
  %.1.lcssa = phi ptr [ %.01220, %.lr.ph22 ], [ %17, %.lr.ph ]
  %13 = getelementptr inbounds i8, ptr %.1.lcssa, i64 1
  store i8 32, ptr %.1.lcssa, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 5, ptr nonnull %3) #5
  %14 = getelementptr inbounds i8, ptr %.01319, i64 1
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %.not = icmp eq i8 %15, -128
  br i1 %.not, label %._crit_edge23, label %.lr.ph22, !llvm.loop !8

.lr.ph:                                           ; preds = %.lr.ph22, %.lr.ph
  %16 = phi i8 [ %19, %.lr.ph ], [ %12, %.lr.ph22 ]
  %.017 = phi ptr [ %18, %.lr.ph ], [ %3, %.lr.ph22 ]
  %.116 = phi ptr [ %17, %.lr.ph ], [ %.01220, %.lr.ph22 ]
  %17 = getelementptr inbounds i8, ptr %.116, i64 1
  store i8 %16, ptr %.116, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.017, i64 1
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %.not14 = icmp eq i8 %19, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge23:                                    ; preds = %._crit_edge, %2
  %.012.lcssa = phi ptr [ %7, %2 ], [ %13, %._crit_edge ]
  %20 = getelementptr inbounds i8, ptr %.012.lcssa, i64 -1
  store i8 0, ptr %20, align 1, !tbaa !5
  %21 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) %7) #5
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @_length(i8 noundef zeroext, ptr noundef, i8 noundef signext) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) 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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #4

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 = { inlinehint 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 #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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 #5 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass