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

; 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 [4 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: 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 void @to_string_porte(ptr noundef %0, ptr noundef %1) #1 {
  %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 [7 x i8], align 1
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i16, align 2
  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
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i64 @_length(i8 noundef zeroext 105, ptr noundef %13, i8 noundef signext -128)
  store i64 %14, ptr %5, align 8, !tbaa !9
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = mul i64 %15, 6
  %17 = add i64 %16, 1
  %18 = call ptr @llvm.stacksave.p0()
  store ptr %18, ptr %6, align 8
  %19 = alloca i16, i64 %17, align 16
  store i64 %17, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store ptr %19, ptr %8, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %48, %2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load i16, ptr %21, align 2, !tbaa !11
  %23 = sext i16 %22 to i32
  %24 = icmp ne i32 %23, -128
  br i1 %24, label %25, label %51

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

32:                                               ; preds = %44, %25
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = load i8, ptr %33, align 1, !tbaa !13
  %35 = zext i8 %34 to i32
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %38, label %37

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

38:                                               ; preds = %32
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = load i8, ptr %39, align 1, !tbaa !13
  %41 = zext i8 %40 to i16
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds i16, ptr %42, i32 1
  store ptr %43, ptr %8, align 8, !tbaa !5
  store i16 %41, ptr %42, align 2, !tbaa !11
  br label %44

44:                                               ; preds = %38
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i32 1
  store ptr %46, ptr %10, align 8, !tbaa !5
  br label %32, !llvm.loop !14

47:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 7, ptr %9) #5
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds i16, ptr %49, i32 1
  store ptr %50, ptr %4, align 8, !tbaa !5
  br label %20, !llvm.loop !16

51:                                               ; preds = %20
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds i16, ptr %52, i32 -1
  store ptr %53, ptr %8, align 8, !tbaa !5
  store i16 0, ptr %53, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store ptr %19, ptr %11, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %59, %51
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = load i16, ptr %55, align 2, !tbaa !11
  %57 = sext i16 %56 to i32
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %71

59:                                               ; preds = %54
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = load i16, ptr %60, align 2, !tbaa !11
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = ptrtoint ptr %63 to i64
  %65 = ptrtoint ptr %19 to i64
  %66 = sub i64 %64, %65
  %67 = sdiv exact i64 %66, 2
  %68 = getelementptr inbounds i16, ptr %62, i64 %67
  store i16 %61, ptr %68, align 2, !tbaa !11
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = getelementptr inbounds i16, ptr %69, i32 1
  store ptr %70, ptr %11, align 8, !tbaa !5
  br label %54, !llvm.loop !17

71:                                               ; preds = %54
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = ptrtoint ptr %73 to i64
  %75 = ptrtoint ptr %19 to i64
  %76 = sub i64 %74, %75
  %77 = sdiv exact i64 %76, 2
  %78 = getelementptr inbounds i16, ptr %72, i64 %77
  store i16 0, ptr %78, align 2, !tbaa !11
  store i16 0, ptr %12, align 2, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  %79 = load i16, ptr %12, align 2, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %80 = load ptr, ptr %6, align 8
  call void @llvm.stackrestore.p0(ptr %80)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

; 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
declare void @llvm.stackrestore.p0(ptr) #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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


; 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 [4 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: 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 void @to_string_porte(ptr nocapture noundef writeonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca [7 x i8], align 1
  %4 = tail call i64 @_length(i8 noundef zeroext 105, ptr noundef %1, i8 noundef signext -128)
  %5 = mul i64 %4, 6
  %6 = or disjoint i64 %5, 1
  %7 = alloca i16, i64 %6, align 16
  %8 = load i16, ptr %1, align 2, !tbaa !5
  %.not26 = icmp eq i16 %8, -128
  br i1 %.not26, label %._crit_edge31, label %.lr.ph30

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

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph30
  %.1.lcssa = phi ptr [ %.02027, %.lr.ph30 ], [ %17, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 7, ptr nonnull %3) #4
  %13 = getelementptr inbounds i8, ptr %.028, i64 2
  %14 = load i16, ptr %13, align 2, !tbaa !5
  %.not = icmp eq i16 %14, -128
  br i1 %.not, label %._crit_edge31, label %.lr.ph30, !llvm.loop !10

.lr.ph:                                           ; preds = %.lr.ph30, %.lr.ph
  %15 = phi i8 [ %19, %.lr.ph ], [ %12, %.lr.ph30 ]
  %.01925 = phi ptr [ %18, %.lr.ph ], [ %3, %.lr.ph30 ]
  %.124 = phi ptr [ %17, %.lr.ph ], [ %.02027, %.lr.ph30 ]
  %16 = zext i8 %15 to i16
  %17 = getelementptr inbounds i8, ptr %.124, i64 2
  store i16 %16, ptr %.124, align 2, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.01925, i64 1
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %.not22 = icmp eq i8 %19, 0
  br i1 %.not22, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge31:                                    ; preds = %._crit_edge, %2
  %.020.lcssa = phi ptr [ %7, %2 ], [ %.1.lcssa, %._crit_edge ]
  %20 = getelementptr inbounds i8, ptr %.020.lcssa, i64 -2
  store i16 0, ptr %20, align 2, !tbaa !5
  %21 = load i16, ptr %7, align 16, !tbaa !5
  %.not2133 = icmp eq i16 %21, 0
  %.pre = ptrtoint ptr %7 to i64
  br i1 %.not2133, label %._crit_edge37, label %.lr.ph36

.lr.ph36:                                         ; preds = %._crit_edge31, %.lr.ph36
  %22 = phi i16 [ %27, %.lr.ph36 ], [ %21, %._crit_edge31 ]
  %.01834 = phi ptr [ %26, %.lr.ph36 ], [ %7, %._crit_edge31 ]
  %23 = ptrtoint ptr %.01834 to i64
  %24 = sub i64 %23, %.pre
  %25 = getelementptr inbounds i8, ptr %0, i64 %24
  store i16 %22, ptr %25, align 2, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %.01834, i64 2
  %27 = load i16, ptr %26, align 2, !tbaa !5
  %.not21 = icmp eq i16 %27, 0
  br i1 %.not21, label %._crit_edge37.loopexit, label %.lr.ph36, !llvm.loop !13

._crit_edge37.loopexit:                           ; preds = %.lr.ph36
  %.pre40 = ptrtoint ptr %26 to i64
  br label %._crit_edge37

._crit_edge37:                                    ; preds = %._crit_edge31, %._crit_edge37.loopexit
  %.pre-phi41 = phi i64 [ %.pre40, %._crit_edge37.loopexit ], [ %.pre, %._crit_edge31 ]
  %28 = sub i64 %.pre-phi41, %.pre
  %29 = getelementptr inbounds i8, ptr %0, i64 %28
  store i16 0, ptr %29, align 2, !tbaa !5
  ret void
}

; 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

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 = { 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 = { 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 = !{!"short", !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}
!13 = distinct !{!13, !11}


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