; LLVM IR from rweather/lightweight-crypto :: src/combined (internal-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
declare dso_local void @subterranean_round(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @subterranean_absorb_word(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @subterranean_duplex_n(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  call void @subterranean_round(ptr noundef %7)
  %8 = load i32, ptr %6, align 4, !tbaa !9
  switch i32 %8, label %52 [
    i32 0, label %9
    i32 1, label %15
    i32 2, label %20
    i32 3, label %33
  ]

9:                                                ; preds = %3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.subterranean_state_t, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds [9 x i32], ptr %11, i64 0, i64 0
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = xor i32 %13, 2
  store i32 %14, ptr %12, align 4, !tbaa !9
  br label %81

15:                                               ; preds = %3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 0
  %19 = load i8, ptr %18, align 1, !tbaa !11
  call void @subterranean_absorb_1(ptr noundef %16, i8 noundef zeroext %19)
  br label %81

20:                                               ; preds = %3
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 0
  %24 = load i8, ptr %23, align 1, !tbaa !11
  %25 = zext i8 %24 to i32
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 1
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = zext i8 %28 to i32
  %30 = shl i32 %29, 8
  %31 = or i32 %25, %30
  %32 = or i32 %31, 65536
  call void @subterranean_absorb_word(ptr noundef %21, i32 noundef %32)
  br label %81

33:                                               ; preds = %3
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 0
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = zext i8 %37 to i32
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 1
  %41 = load i8, ptr %40, align 1, !tbaa !11
  %42 = zext i8 %41 to i32
  %43 = shl i32 %42, 8
  %44 = or i32 %38, %43
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 2
  %47 = load i8, ptr %46, align 1, !tbaa !11
  %48 = zext i8 %47 to i32
  %49 = shl i32 %48, 16
  %50 = or i32 %44, %49
  %51 = or i32 %50, 16777216
  call void @subterranean_absorb_word(ptr noundef %34, i32 noundef %51)
  br label %81

52:                                               ; preds = %3
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 3
  %56 = load i8, ptr %55, align 1, !tbaa !11
  %57 = zext i8 %56 to i32
  %58 = shl i32 %57, 24
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i64 2
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = zext i8 %61 to i32
  %63 = shl i32 %62, 16
  %64 = or i32 %58, %63
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %65, i64 1
  %67 = load i8, ptr %66, align 1, !tbaa !11
  %68 = zext i8 %67 to i32
  %69 = shl i32 %68, 8
  %70 = or i32 %64, %69
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 0
  %73 = load i8, ptr %72, align 1, !tbaa !11
  %74 = zext i8 %73 to i32
  %75 = or i32 %70, %74
  call void @subterranean_absorb_word(ptr noundef %53, i32 noundef %75)
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.subterranean_state_t, ptr %76, i32 0, i32 0
  %78 = getelementptr inbounds [9 x i32], ptr %77, i64 0, i64 8
  %79 = load i32, ptr %78, align 4, !tbaa !9
  %80 = xor i32 %79, 1
  store i32 %80, ptr %78, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %52, %33, %20, %15, %9
  ret void
}

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

!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}


; 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
declare dso_local void @subterranean_round(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @subterranean_absorb_word(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @subterranean_duplex_n(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  tail call void @subterranean_round(ptr noundef %0)
  switch i32 %2, label %22 [
    i32 0, label %4
    i32 1, label %7
    i32 2, label %9
    i32 3, label %13
  ]

4:                                                ; preds = %3
  %5 = load i32, ptr %0, align 4, !tbaa !5
  %6 = xor i32 %5, 2
  store i32 %6, ptr %0, align 4, !tbaa !5
  br label %27

7:                                                ; preds = %3
  %8 = load i8, ptr %1, align 1, !tbaa !9
  tail call void @subterranean_absorb_1(ptr noundef %0, i8 noundef zeroext %8)
  br label %27

9:                                                ; preds = %3
  %10 = load i16, ptr %1, align 1
  %11 = zext i16 %10 to i32
  %12 = or disjoint i32 %11, 65536
  tail call void @subterranean_absorb_word(ptr noundef %0, i32 noundef %12)
  br label %27

13:                                               ; preds = %3
  %14 = load i16, ptr %1, align 1
  %15 = zext i16 %14 to i32
  %16 = getelementptr inbounds i8, ptr %1, i64 2
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = zext i8 %17 to i32
  %19 = shl nuw nsw i32 %18, 16
  %20 = or disjoint i32 %19, %15
  %21 = or disjoint i32 %20, 16777216
  tail call void @subterranean_absorb_word(ptr noundef %0, i32 noundef %21)
  br label %27

22:                                               ; preds = %3
  %23 = load i32, ptr %1, align 1
  tail call void @subterranean_absorb_word(ptr noundef %0, i32 noundef %23)
  %24 = getelementptr inbounds i8, ptr %0, i64 32
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = xor i32 %25, 1
  store i32 %26, ptr %24, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %22, %13, %9, %7, %4
  ret void
}

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

!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}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass