; LLVM IR from rweather/lightweight-crypto :: src/genavr/algorithm_saturnin.ll (Z28get_saturnin_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 }

@_ZL11saturnin_rc = external hidden constant [96 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z28get_saturnin_round_constantsv(ptr dead_on_unwind noalias writable sret(%class.Sbox) align 8 %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca [384 x i8], align 16
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 384, 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 = %53, %1
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = zext i32 %6 to i64
  %8 = icmp ult i64 %7, 96
  br i1 %8, label %10, label %9

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

@_ZL11saturnin_rc = external hidden local_unnamed_addr constant [96 x i32], align 16

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

4:                                                ; preds = %1, %4
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %4 ]
  %5 = getelementptr inbounds [96 x i32], ptr @_ZL11saturnin_rc, 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 [384 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 [384 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 [384 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 [384 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, 96
  br i1 %exitcond.not, label %3, label %4, !llvm.loop !10
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass