; LLVM IR from rweather/lightweight-crypto :: src/genavr/algorithm_gift128_fixsliced.ll (Z30get_gift128_fs_round_constantsv)

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

%class.Sbox = type { %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@_ZL20GIFT128_RC_fixsliced = external hidden constant [40 x i32], align 16

; 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: mustprogress uwtable
define dso_local void @_Z30get_gift128_fs_round_constantsv(ptr dead_on_unwind noalias writable sret(%class.Sbox) align 8 %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca [160 x i8], align 16
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 160, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %52, %1
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 40
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %55

9:                                                ; preds = %5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [40 x i32], ptr @_ZL20GIFT128_RC_fixsliced, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = trunc i32 %13 to i8
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = mul nsw i32 %15, 4
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [160 x i8], ptr %3, i64 0, i64 %17
  store i8 %14, ptr %18, align 1, !tbaa !9
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [40 x i32], ptr @_ZL20GIFT128_RC_fixsliced, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = lshr i32 %22, 8
  %24 = trunc i32 %23 to i8
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = mul nsw i32 %25, 4
  %27 = add nsw i32 %26, 1
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [160 x i8], ptr %3, i64 0, i64 %28
  store i8 %24, ptr %29, align 1, !tbaa !9
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [40 x i32], ptr @_ZL20GIFT128_RC_fixsliced, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = lshr i32 %33, 16
  %35 = trunc i32 %34 to i8
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = mul nsw i32 %36, 4
  %38 = add nsw i32 %37, 2
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [160 x i8], ptr %3, i64 0, i64 %39
  store i8 %35, ptr %40, align 1, !tbaa !9
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [40 x i32], ptr @_ZL20GIFT128_RC_fixsliced, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = lshr i32 %44, 24
  %46 = trunc i32 %45 to i8
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = mul nsw i32 %47, 4
  %49 = add nsw i32 %48, 3
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [160 x i8], ptr %3, i64 0, i64 %50
  store i8 %46, ptr %51, align 1, !tbaa !9
  br label %52

52:                                               ; preds = %9
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %4, align 4, !tbaa !5
  br label %5, !llvm.loop !10

55:                                               ; preds = %8
  %56 = getelementptr inbounds [160 x i8], ptr %3, i64 0, i64 0
  call void @_ZN4SboxC1EPKhj(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %56, i32 noundef 160)
  call void @llvm.lifetime.end.p0(i64 160, ptr %3) #3
  ret void
}

declare void @_ZN4SboxC1EPKhj(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef, i32 noundef) unnamed_addr #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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 }

!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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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

%class.Sbox = type { %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned char, std::allocator<unsigned char>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@_ZL20GIFT128_RC_fixsliced = external hidden local_unnamed_addr constant [40 x i32], align 16

; 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: mustprogress uwtable
define dso_local void @_Z30get_gift128_fs_round_constantsv(ptr dead_on_unwind noalias writable sret(%class.Sbox) align 8 %0) local_unnamed_addr #1 {
  %2 = alloca [160 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 160, ptr nonnull %2) #3
  br label %4

3:                                                ; preds = %4
  call void @_ZN4SboxC1EPKhj(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull %2, i32 noundef 160)
  call void @llvm.lifetime.end.p0(i64 160, ptr nonnull %2) #3
  ret void

4:                                                ; preds = %1, %4
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %4 ]
  %5 = getelementptr inbounds [40 x i32], ptr @_ZL20GIFT128_RC_fixsliced, i64 0, i64 %indvars.iv
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = trunc i32 %6 to i8
  %8 = shl nuw nsw i64 %indvars.iv, 2
  %9 = getelementptr inbounds [160 x i8], ptr %2, i64 0, i64 %8
  store i8 %7, ptr %9, align 4, !tbaa !9
  %10 = lshr i32 %6, 8
  %11 = trunc i32 %10 to i8
  %12 = or disjoint i64 %8, 1
  %13 = getelementptr inbounds [160 x i8], ptr %2, i64 0, i64 %12
  store i8 %11, ptr %13, align 1, !tbaa !9
  %14 = lshr i32 %6, 16
  %15 = trunc i32 %14 to i8
  %16 = or disjoint i64 %8, 2
  %17 = getelementptr inbounds [160 x i8], ptr %2, i64 0, i64 %16
  store i8 %15, ptr %17, align 2, !tbaa !9
  %18 = lshr i32 %6, 24
  %19 = trunc nuw i32 %18 to i8
  %20 = or disjoint i64 %8, 3
  %21 = getelementptr inbounds [160 x i8], ptr %2, i64 0, i64 %20
  store i8 %19, ptr %21, align 1, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 40
  br i1 %exitcond.not, label %3, label %4, !llvm.loop !10
}

declare void @_ZN4SboxC1EPKhj(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef, i32 noundef) unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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 }

!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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass