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

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

@__length_alpha = external hidden global i8, align 1
@__alpha = external hidden global [2 x [127 x i8]], align 16

; Function Attrs: nounwind uwtable
define dso_local signext i8 @set_alpha_couple(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call i64 @strlen(ptr noundef %10) #5
  store i64 %11, ptr %6, align 8, !tbaa !9
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = icmp uge i64 %12, 127
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store i8 1, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %65

15:                                               ; preds = %2
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call i64 @strlen(ptr noundef %17) #5
  %19 = icmp ne i64 %16, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  store i8 2, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %65

21:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %22, ptr %8, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %53, %21
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = zext i8 %25 to i32
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %29, label %28

28:                                               ; preds = %23
  store i32 2, ptr %7, align 4
  br label %56

29:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %30, ptr %9, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %47, %29
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = zext i8 %33 to i32
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %37, label %36

36:                                               ; preds = %31
  store i32 5, ptr %7, align 4
  br label %50

37:                                               ; preds = %31
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = zext i8 %39 to i32
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = zext i8 %42 to i32
  %44 = icmp eq i32 %40, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %37
  store i8 3, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %50

46:                                               ; preds = %37
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i32 1
  store ptr %49, ptr %9, align 8, !tbaa !5
  br label %31, !llvm.loop !12

50:                                               ; preds = %45, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %51 = load i32, ptr %7, align 4
  switch i32 %51, label %56 [
    i32 5, label %52
  ]

52:                                               ; preds = %50
  br label %53

53:                                               ; preds = %52
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i32 1
  store ptr %55, ptr %8, align 8, !tbaa !5
  br label %23, !llvm.loop !14

56:                                               ; preds = %50, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %57 = load i32, ptr %7, align 4
  switch i32 %57, label %65 [
    i32 2, label %58
  ]

58:                                               ; preds = %56
  %59 = load i64, ptr %6, align 8, !tbaa !9
  %60 = trunc i64 %59 to i8
  store i8 %60, ptr @__length_alpha, align 1, !tbaa !11
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = call ptr @strcpy(ptr noundef @__alpha, ptr noundef %61) #4
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = call ptr @strcpy(ptr noundef getelementptr inbounds ([2 x [127 x i8]], ptr @__alpha, i64 0, i64 1), ptr noundef %63) #4
  store i8 0, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %65

65:                                               ; preds = %58, %56, %20, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %66 = load i8, ptr %3, align 1
  ret i8 %66
}

; 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 i64 @strlen(ptr noundef) #2

; 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) #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 = { 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 = { 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 }
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}


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

@__length_alpha = external hidden local_unnamed_addr global i8, align 1
@__alpha = external hidden global [2 x [127 x i8]], align 16

; Function Attrs: nofree nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef signext i8 @set_alpha_couple(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #3
  %4 = icmp ugt i64 %3, 126
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %2
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #3
  %.not = icmp eq i64 %3, %6
  br i1 %.not, label %.preheader28, label %.loopexit

.preheader28:                                     ; preds = %5
  %7 = load i8, ptr %0, align 1, !tbaa !5
  %.not2431 = icmp eq i8 %7, 0
  br i1 %.not2431, label %.critedge27, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %.preheader28
  %8 = load i8, ptr %1, align 1, !tbaa !5
  %.not2529 = icmp eq i8 %8, 0
  br i1 %.not2529, label %.critedge27, label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %..critedge_crit_edge
  %9 = phi i8 [ %17, %..critedge_crit_edge ], [ %7, %.preheader.lr.ph ]
  %.01832 = phi ptr [ %16, %..critedge_crit_edge ], [ %0, %.preheader.lr.ph ]
  br label %13

10:                                               ; preds = %13
  %11 = getelementptr inbounds i8, ptr %.030, i64 1
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %.not25 = icmp eq i8 %12, 0
  br i1 %.not25, label %..critedge_crit_edge, label %13, !llvm.loop !8

13:                                               ; preds = %.preheader, %10
  %14 = phi i8 [ %8, %.preheader ], [ %12, %10 ]
  %.030 = phi ptr [ %1, %.preheader ], [ %11, %10 ]
  %15 = icmp eq i8 %9, %14
  br i1 %15, label %.loopexit, label %10

..critedge_crit_edge:                             ; preds = %10
  %16 = getelementptr inbounds i8, ptr %.01832, i64 1
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %.not24 = icmp eq i8 %17, 0
  br i1 %.not24, label %.critedge27, label %.preheader, !llvm.loop !10

.critedge27:                                      ; preds = %..critedge_crit_edge, %.preheader.lr.ph, %.preheader28
  %18 = trunc nuw nsw i64 %3 to i8
  store i8 %18, ptr @__length_alpha, align 1, !tbaa !5
  %19 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) @__alpha, ptr noundef nonnull dereferenceable(1) %0) #4
  %20 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @__alpha, i64 127), ptr noundef nonnull dereferenceable(1) %1) #4
  br label %.loopexit

.loopexit:                                        ; preds = %13, %5, %2, %.critedge27
  %.3 = phi i8 [ 0, %.critedge27 ], [ 1, %2 ], [ 2, %5 ], [ 3, %13 ]
  ret i8 %.3
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #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 #2

attributes #0 = { nofree nounwind memory(readwrite, inaccessiblemem: none) 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 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 #2 = { 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 #3 = { nounwind willreturn memory(read) }
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 = !{!"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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass