; LLVM IR from rweather/lightweight-crypto :: src/combined (subterranean)

; 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.subterranean_state_t = type { [9 x i32] }

; Function Attrs: nounwind uwtable
define dso_local i32 @subterranean_hash(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca %struct.subterranean_state_t, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 36, ptr %7) #4
  call void @llvm.memset.p0.i64(ptr align 4 %7, i8 0, i64 36, i1 false)
  br label %8

8:                                                ; preds = %24, %3
  %9 = load i64, ptr %6, align 8, !tbaa !9
  %10 = icmp ugt i64 %9, 0
  br i1 %10, label %11, label %27

11:                                               ; preds = %8
  br label %12

12:                                               ; preds = %11
  call void @subterranean_round(ptr noundef %7)
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i32 1
  store ptr %14, ptr %5, align 8, !tbaa !5
  %15 = load i8, ptr %13, align 1, !tbaa !11
  call void @subterranean_absorb_1(ptr noundef %7, i8 noundef zeroext %15)
  br label %16

16:                                               ; preds = %12
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  call void @subterranean_round(ptr noundef %7)
  %19 = getelementptr inbounds %struct.subterranean_state_t, ptr %7, i32 0, i32 0
  %20 = getelementptr inbounds [9 x i32], ptr %19, i64 0, i64 0
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = xor i32 %21, 2
  store i32 %22, ptr %20, align 4, !tbaa !12
  br label %23

23:                                               ; preds = %18
  br label %24

24:                                               ; preds = %23
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = add i64 %25, -1
  store i64 %26, ptr %6, align 8, !tbaa !9
  br label %8, !llvm.loop !14

27:                                               ; preds = %8
  br label %28

28:                                               ; preds = %27
  call void @subterranean_round(ptr noundef %7)
  %29 = getelementptr inbounds %struct.subterranean_state_t, ptr %7, i32 0, i32 0
  %30 = getelementptr inbounds [9 x i32], ptr %29, i64 0, i64 0
  %31 = load i32, ptr %30, align 4, !tbaa !12
  %32 = xor i32 %31, 2
  store i32 %32, ptr %30, align 4, !tbaa !12
  br label %33

33:                                               ; preds = %28
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  call void @subterranean_round(ptr noundef %7)
  %36 = getelementptr inbounds %struct.subterranean_state_t, ptr %7, i32 0, i32 0
  %37 = getelementptr inbounds [9 x i32], ptr %36, i64 0, i64 0
  %38 = load i32, ptr %37, align 4, !tbaa !12
  %39 = xor i32 %38, 2
  store i32 %39, ptr %37, align 4, !tbaa !12
  br label %40

40:                                               ; preds = %35
  br label %41

41:                                               ; preds = %40
  call void @subterranean_blank(ptr noundef %7)
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  call void @subterranean_squeeze(ptr noundef %7, ptr noundef %42, i32 noundef 32)
  call void @llvm.lifetime.end.p0(i64 36, ptr %7) #4
  ret i32 0
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare void @subterranean_blank(ptr noundef) #3

declare void @subterranean_round(ptr noundef) #3

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

declare void @subterranean_squeeze(ptr noundef, ptr noundef, i32 noundef) #3

declare void @subterranean_absorb_1(ptr noundef, i8 noundef zeroext) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 }

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

%struct.subterranean_state_t = type { [9 x i32] }

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @subterranean_hash(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.subterranean_state_t, align 4
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %4) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %4, i8 0, i64 36, i1 false)
  %.not4 = icmp eq i64 %2, 0
  br i1 %.not4, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.06 = phi i64 [ %9, %.lr.ph ], [ %2, %3 ]
  %.035 = phi ptr [ %5, %.lr.ph ], [ %1, %3 ]
  call void @subterranean_round(ptr noundef nonnull %4) #4
  %5 = getelementptr inbounds i8, ptr %.035, i64 1
  %6 = load i8, ptr %.035, align 1, !tbaa !5
  call void @subterranean_absorb_1(ptr noundef nonnull %4, i8 noundef zeroext %6) #4
  call void @subterranean_round(ptr noundef nonnull %4) #4
  %7 = load i32, ptr %4, align 4, !tbaa !8
  %8 = xor i32 %7, 2
  store i32 %8, ptr %4, align 4, !tbaa !8
  %9 = add i64 %.06, -1
  %.not = icmp eq i64 %9, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph, %3
  call void @subterranean_round(ptr noundef nonnull %4) #4
  %10 = load i32, ptr %4, align 4, !tbaa !8
  %11 = xor i32 %10, 2
  store i32 %11, ptr %4, align 4, !tbaa !8
  call void @subterranean_round(ptr noundef nonnull %4) #4
  %12 = load i32, ptr %4, align 4, !tbaa !8
  %13 = xor i32 %12, 2
  store i32 %13, ptr %4, align 4, !tbaa !8
  call void @subterranean_blank(ptr noundef nonnull %4) #4
  call void @subterranean_squeeze(ptr noundef nonnull %4, ptr noundef %0, i32 noundef 32) #4
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %4) #4
  ret i32 0
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare void @subterranean_blank(ptr noundef) local_unnamed_addr #3

declare void @subterranean_round(ptr noundef) local_unnamed_addr #3

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

declare void @subterranean_squeeze(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare void @subterranean_absorb_1(ptr noundef, i8 noundef zeroext) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 }

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass