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

; 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: nounwind uwtable
define dso_local signext i8 @permutation_double(ptr noundef %0, i8 noundef signext %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i8 %1, ptr %8, align 1, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %16 = load i8, ptr %8, align 1, !tbaa !9
  %17 = sext i8 %16 to i32
  %18 = icmp ne i32 %17, 1
  br i1 %18, label %19, label %24

19:                                               ; preds = %5
  %20 = load i8, ptr %8, align 1, !tbaa !9
  %21 = sext i8 %20 to i32
  %22 = icmp ne i32 %21, -1
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  store i8 1, ptr %6, align 1
  br label %101

24:                                               ; preds = %19, %5
  %25 = load i8, ptr %8, align 1, !tbaa !9
  %26 = sext i8 %25 to i32
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %81

28:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  %30 = call i64 @strlen(ptr noundef %29) #4
  store i64 %30, ptr %12, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = call i64 @strlen(ptr noundef %31) #4
  store i64 %32, ptr %13, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = call i64 @strlen(ptr noundef %33) #4
  store i64 %34, ptr %14, align 8, !tbaa !10
  %35 = load i64, ptr %12, align 8, !tbaa !10
  %36 = load i64, ptr %13, align 8, !tbaa !10
  %37 = urem i64 %35, %36
  %38 = icmp ne i64 %37, 0
  br i1 %38, label %39, label %47

39:                                               ; preds = %28
  %40 = load i64, ptr %12, align 8, !tbaa !10
  %41 = load i64, ptr %13, align 8, !tbaa !10
  %42 = add i64 %40, %41
  %43 = load i64, ptr %12, align 8, !tbaa !10
  %44 = load i64, ptr %13, align 8, !tbaa !10
  %45 = urem i64 %43, %44
  %46 = sub i64 %42, %45
  br label %49

47:                                               ; preds = %28
  %48 = load i64, ptr %12, align 8, !tbaa !10
  br label %49

49:                                               ; preds = %47, %39
  %50 = phi i64 [ %46, %39 ], [ %48, %47 ]
  store i64 %50, ptr %12, align 8, !tbaa !10
  %51 = load i64, ptr %12, align 8, !tbaa !10
  %52 = load i64, ptr %14, align 8, !tbaa !10
  %53 = urem i64 %51, %52
  %54 = icmp ne i64 %53, 0
  br i1 %54, label %55, label %63

55:                                               ; preds = %49
  %56 = load i64, ptr %12, align 8, !tbaa !10
  %57 = load i64, ptr %14, align 8, !tbaa !10
  %58 = add i64 %56, %57
  %59 = load i64, ptr %12, align 8, !tbaa !10
  %60 = load i64, ptr %14, align 8, !tbaa !10
  %61 = urem i64 %59, %60
  %62 = sub i64 %58, %61
  br label %65

63:                                               ; preds = %49
  %64 = load i64, ptr %12, align 8, !tbaa !10
  br label %65

65:                                               ; preds = %63, %55
  %66 = phi i64 [ %62, %55 ], [ %64, %63 ]
  store i64 %66, ptr %12, align 8, !tbaa !10
  %67 = load i64, ptr %12, align 8, !tbaa !10
  %68 = load i64, ptr %13, align 8, !tbaa !10
  %69 = urem i64 %67, %68
  %70 = icmp ne i64 %69, 0
  br i1 %70, label %77, label %71

71:                                               ; preds = %65
  %72 = load i64, ptr %12, align 8, !tbaa !10
  %73 = load i64, ptr %14, align 8, !tbaa !10
  %74 = urem i64 %72, %73
  %75 = icmp ne i64 %74, 0
  br i1 %75, label %77, label %76

76:                                               ; preds = %71
  store i8 2, ptr %6, align 1
  store i32 1, ptr %15, align 4
  br label %78

77:                                               ; preds = %71, %65
  store i32 0, ptr %15, align 4
  br label %78

78:                                               ; preds = %77, %76
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %79 = load i32, ptr %15, align 4
  switch i32 %79, label %103 [
    i32 0, label %80
    i32 1, label %101
  ]

80:                                               ; preds = %78
  br label %81

81:                                               ; preds = %80, %24
  %82 = load i8, ptr %8, align 1, !tbaa !9
  %83 = sext i8 %82 to i32
  switch i32 %83, label %100 [
    i32 1, label %84
    i32 -1, label %92
  ]

84:                                               ; preds = %81
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  call void @_encrypt_horizontal(ptr noundef %85, ptr noundef %86, ptr noundef %87)
  %88 = load i8, ptr %8, align 1, !tbaa !9
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = load ptr, ptr %10, align 8, !tbaa !5
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_encrypt_vertical(i8 noundef signext %88, ptr noundef %89, ptr noundef %90, ptr noundef %91)
  br label %100

92:                                               ; preds = %81
  %93 = load i8, ptr %8, align 1, !tbaa !9
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = load ptr, ptr %10, align 8, !tbaa !5
  %96 = load ptr, ptr %11, align 8, !tbaa !5
  call void @_encrypt_vertical(i8 noundef signext %93, ptr noundef %94, ptr noundef %95, ptr noundef %96)
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = load ptr, ptr %9, align 8, !tbaa !5
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_decrypt_horizontal(ptr noundef %97, ptr noundef %98, ptr noundef %99)
  br label %100

100:                                              ; preds = %92, %84, %81
  store i8 0, ptr %6, align 1
  br label %101

101:                                              ; preds = %100, %78, %23
  %102 = load i8, ptr %6, align 1
  ret i8 %102

103:                                              ; preds = %78
  unreachable
}

; 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 uwtable
declare hidden void @_encrypt_horizontal(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @_encrypt_vertical(i8 noundef signext, ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @_decrypt_horizontal(ptr noundef, ptr noundef, ptr noundef) #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" }
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 }
attributes #4 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !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 signext range(i8 0, 3) i8 @permutation_double(ptr noundef %0, i8 noundef signext %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  switch i8 %1, label %23 [
    i8 1, label %6
    i8 -1, label %22
  ]

6:                                                ; preds = %5
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %4) #2
  %8 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #2
  %9 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #2
  %10 = urem i64 %7, %8
  %.not = icmp eq i64 %10, 0
  %11 = add i64 %8, %7
  %12 = sub i64 %11, %10
  %13 = select i1 %.not, i64 %7, i64 %12
  %14 = urem i64 %13, %9
  %.not45 = icmp eq i64 %14, 0
  %15 = sub i64 %9, %14
  %16 = select i1 %.not45, i64 0, i64 %15
  %17 = add i64 %13, %16
  %18 = urem i64 %17, %8
  %.not46 = icmp eq i64 %18, 0
  br i1 %.not46, label %19, label %21

19:                                               ; preds = %6
  %20 = urem i64 %17, %9
  %.not47 = icmp eq i64 %20, 0
  br i1 %.not47, label %23, label %21

21:                                               ; preds = %19, %6
  tail call void @_encrypt_horizontal(ptr noundef %0, ptr noundef %2, ptr noundef %4)
  tail call void @_encrypt_vertical(i8 noundef signext 1, ptr noundef %0, ptr noundef %3, ptr noundef %0)
  br label %23

22:                                               ; preds = %5
  tail call void @_encrypt_vertical(i8 noundef signext -1, ptr noundef %0, ptr noundef %3, ptr noundef %4)
  tail call void @_decrypt_horizontal(ptr noundef %0, ptr noundef %2, ptr noundef %0)
  br label %23

23:                                               ; preds = %19, %21, %22, %5
  %.1 = phi i8 [ 1, %5 ], [ 0, %22 ], [ 0, %21 ], [ 2, %19 ]
  ret i8 %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @_encrypt_horizontal(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @_encrypt_vertical(i8 noundef signext, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @_decrypt_horizontal(ptr noundef, ptr noundef, ptr 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" }
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 = { 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)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass