; LLVM IR from MidnightBlueLabs/TETRA_crypto :: hurdle (HURDLE_dec_cts)

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

%struct.HURDLE_CTX = type { [256 x i8] }

; 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
declare dso_local void @HURDLE_set_key(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @HURDLE_encrypt(ptr noundef, ptr noundef, ptr noundef, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local void @HURDLE_dec_cts(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [16 x i8], align 16
  %8 = alloca %struct.HURDLE_CTX, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 256, ptr %8) #2
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  call void @HURDLE_set_key(ptr noundef %9, ptr noundef %8)
  %10 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 8
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 7
  call void @HURDLE_encrypt(ptr noundef %10, ptr noundef %12, ptr noundef %8, i8 noundef zeroext 1)
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 0
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 0
  store i32 %15, ptr %16, align 16, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 4
  store i32 %19, ptr %20, align 4, !tbaa !9
  %21 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 15
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 7
  store i8 %22, ptr %23, align 1, !tbaa !11
  %24 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 0
  %25 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 0
  call void @HURDLE_encrypt(ptr noundef %24, ptr noundef %25, ptr noundef %8, i8 noundef zeroext 1)
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 0
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 8
  %30 = load i32, ptr %29, align 8, !tbaa !9
  %31 = xor i32 %30, %28
  store i32 %31, ptr %29, align 8, !tbaa !9
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 4
  %34 = load i16, ptr %33, align 2, !tbaa !12
  %35 = zext i16 %34 to i32
  %36 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 12
  %37 = load i16, ptr %36, align 4, !tbaa !12
  %38 = zext i16 %37 to i32
  %39 = xor i32 %38, %35
  %40 = trunc i32 %39 to i16
  store i16 %40, ptr %36, align 4, !tbaa !12
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 6
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = zext i8 %43 to i32
  %45 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 14
  %46 = load i8, ptr %45, align 2, !tbaa !11
  %47 = zext i8 %46 to i32
  %48 = xor i32 %47, %44
  %49 = trunc i32 %48 to i8
  store i8 %49, ptr %45, align 2, !tbaa !11
  %50 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 0
  %51 = load i32, ptr %50, align 16, !tbaa !9
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 0
  store i32 %51, ptr %53, align 4, !tbaa !9
  %54 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 4
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i64 4
  store i32 %55, ptr %57, align 4, !tbaa !9
  %58 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 8
  %59 = load i32, ptr %58, align 8, !tbaa !9
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 8
  store i32 %59, ptr %61, align 4, !tbaa !9
  %62 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 12
  %63 = load i16, ptr %62, align 4, !tbaa !12
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 12
  store i16 %63, ptr %65, align 2, !tbaa !12
  %66 = getelementptr inbounds [16 x i8], ptr %7, i64 0, i64 14
  %67 = load i8, ptr %66, align 2, !tbaa !11
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i64 14
  store i8 %67, ptr %69, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 256, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #2
  ret void
}

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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !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"

%struct.HURDLE_CTX = type { [256 x i8] }

; 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
declare dso_local void @HURDLE_set_key(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @HURDLE_encrypt(ptr noundef, ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @HURDLE_dec_cts(ptr nocapture noundef writeonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca [16 x i8], align 16
  %5 = alloca %struct.HURDLE_CTX, align 1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %5) #2
  call void @HURDLE_set_key(ptr noundef %2, ptr noundef nonnull %5)
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  %7 = getelementptr inbounds i8, ptr %1, i64 7
  call void @HURDLE_encrypt(ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef nonnull %5, i8 noundef zeroext 1)
  %8 = getelementptr inbounds i8, ptr %1, i64 4
  %9 = load <2 x i32>, ptr %1, align 4, !tbaa !5
  store <2 x i32> %9, ptr %4, align 16, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %4, i64 15
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %4, i64 7
  store i8 %11, ptr %12, align 1, !tbaa !9
  call void @HURDLE_encrypt(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef nonnull %5, i8 noundef zeroext 1)
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = load i32, ptr %6, align 8, !tbaa !5
  %15 = xor i32 %14, %13
  %16 = load i16, ptr %8, align 2, !tbaa !10
  %17 = getelementptr inbounds i8, ptr %4, i64 12
  %18 = load i16, ptr %17, align 4, !tbaa !10
  %19 = xor i16 %18, %16
  %20 = getelementptr inbounds i8, ptr %1, i64 6
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %4, i64 14
  %23 = load i8, ptr %22, align 2, !tbaa !9
  %24 = xor i8 %23, %21
  %25 = load <2 x i32>, ptr %4, align 16, !tbaa !5
  store <2 x i32> %25, ptr %0, align 4, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %15, ptr %26, align 4, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %0, i64 12
  store i16 %19, ptr %27, align 2, !tbaa !10
  %28 = getelementptr inbounds i8, ptr %0, i64 14
  store i8 %24, ptr %28, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #2
  ret void
}

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass