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

; 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.grain128_state_t = type { [4 x i32], [4 x i32], i64, i64, [16 x i8], i32 }

; 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
define dso_local void @grain128_compute_tag(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.grain128_state_t, ptr %5, i32 0, i32 3
  %7 = load i64, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.grain128_state_t, ptr %8, i32 0, i32 2
  %10 = load i64, ptr %9, align 8, !tbaa !13
  %11 = xor i64 %10, %7
  store i64 %11, ptr %9, align 8, !tbaa !13
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.grain128_state_t, ptr %12, i32 0, i32 2
  %14 = load i64, ptr %13, align 8, !tbaa !13
  store i64 %14, ptr %3, align 8, !tbaa !14
  br label %15

15:                                               ; preds = %1
  %16 = load i64, ptr %3, align 8, !tbaa !14
  %17 = and i64 %16, 6148914691236517205
  %18 = shl i64 %17, 1
  %19 = load i64, ptr %3, align 8, !tbaa !14
  %20 = lshr i64 %19, 1
  %21 = and i64 %20, 6148914691236517205
  %22 = or i64 %18, %21
  store i64 %22, ptr %3, align 8, !tbaa !14
  br label %23

23:                                               ; preds = %15
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  %26 = load i64, ptr %3, align 8, !tbaa !14
  %27 = and i64 %26, 3689348814741910323
  %28 = shl i64 %27, 2
  %29 = load i64, ptr %3, align 8, !tbaa !14
  %30 = lshr i64 %29, 2
  %31 = and i64 %30, 3689348814741910323
  %32 = or i64 %28, %31
  store i64 %32, ptr %3, align 8, !tbaa !14
  br label %33

33:                                               ; preds = %25
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  %36 = load i64, ptr %3, align 8, !tbaa !14
  %37 = and i64 %36, 1085102592571150095
  %38 = shl i64 %37, 4
  %39 = load i64, ptr %3, align 8, !tbaa !14
  %40 = lshr i64 %39, 4
  %41 = and i64 %40, 1085102592571150095
  %42 = or i64 %38, %41
  store i64 %42, ptr %3, align 8, !tbaa !14
  br label %43

43:                                               ; preds = %35
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %46 = load i64, ptr %3, align 8, !tbaa !14
  store i64 %46, ptr %4, align 8, !tbaa !14
  %47 = load i64, ptr %4, align 8, !tbaa !14
  %48 = lshr i64 %47, 56
  %49 = trunc i64 %48 to i8
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.grain128_state_t, ptr %50, i32 0, i32 4
  %52 = getelementptr inbounds [16 x i8], ptr %51, i64 0, i64 0
  store i8 %49, ptr %52, align 8, !tbaa !15
  %53 = load i64, ptr %4, align 8, !tbaa !14
  %54 = lshr i64 %53, 48
  %55 = trunc i64 %54 to i8
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.grain128_state_t, ptr %56, i32 0, i32 4
  %58 = getelementptr inbounds [16 x i8], ptr %57, i64 0, i64 1
  store i8 %55, ptr %58, align 1, !tbaa !15
  %59 = load i64, ptr %4, align 8, !tbaa !14
  %60 = lshr i64 %59, 40
  %61 = trunc i64 %60 to i8
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.grain128_state_t, ptr %62, i32 0, i32 4
  %64 = getelementptr inbounds [16 x i8], ptr %63, i64 0, i64 2
  store i8 %61, ptr %64, align 2, !tbaa !15
  %65 = load i64, ptr %4, align 8, !tbaa !14
  %66 = lshr i64 %65, 32
  %67 = trunc i64 %66 to i8
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.grain128_state_t, ptr %68, i32 0, i32 4
  %70 = getelementptr inbounds [16 x i8], ptr %69, i64 0, i64 3
  store i8 %67, ptr %70, align 1, !tbaa !15
  %71 = load i64, ptr %4, align 8, !tbaa !14
  %72 = lshr i64 %71, 24
  %73 = trunc i64 %72 to i8
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.grain128_state_t, ptr %74, i32 0, i32 4
  %76 = getelementptr inbounds [16 x i8], ptr %75, i64 0, i64 4
  store i8 %73, ptr %76, align 4, !tbaa !15
  %77 = load i64, ptr %4, align 8, !tbaa !14
  %78 = lshr i64 %77, 16
  %79 = trunc i64 %78 to i8
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.grain128_state_t, ptr %80, i32 0, i32 4
  %82 = getelementptr inbounds [16 x i8], ptr %81, i64 0, i64 5
  store i8 %79, ptr %82, align 1, !tbaa !15
  %83 = load i64, ptr %4, align 8, !tbaa !14
  %84 = lshr i64 %83, 8
  %85 = trunc i64 %84 to i8
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.grain128_state_t, ptr %86, i32 0, i32 4
  %88 = getelementptr inbounds [16 x i8], ptr %87, i64 0, i64 6
  store i8 %85, ptr %88, align 2, !tbaa !15
  %89 = load i64, ptr %4, align 8, !tbaa !14
  %90 = trunc i64 %89 to i8
  %91 = load ptr, ptr %2, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.grain128_state_t, ptr %91, i32 0, i32 4
  %93 = getelementptr inbounds [16 x i8], ptr %92, i64 0, i64 7
  store i8 %90, ptr %93, align 1, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %94

94:                                               ; preds = %45
  br label %95

95:                                               ; preds = %94
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #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, !11, i64 40}
!10 = !{!"", !7, i64 0, !7, i64 16, !11, i64 32, !11, i64 40, !7, i64 48, !12, i64 64}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 32}
!14 = !{!11, !11, i64 0}
!15 = !{!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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @grain128_compute_tag(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load i64, ptr %4, align 8, !tbaa !11
  %6 = xor i64 %5, %3
  store i64 %6, ptr %4, align 8, !tbaa !11
  %7 = shl i64 %6, 1
  %8 = and i64 %7, -6148914691236517206
  %9 = lshr i64 %6, 1
  %10 = and i64 %9, 6148914691236517205
  %11 = or disjoint i64 %8, %10
  %12 = shl i64 %11, 2
  %13 = and i64 %12, -3689348814741910324
  %14 = lshr i64 %11, 2
  %15 = and i64 %14, 3689348814741910323
  %16 = or disjoint i64 %13, %15
  %17 = shl i64 %16, 4
  %18 = and i64 %17, -1085102592571150096
  %19 = lshr i64 %16, 4
  %20 = and i64 %19, 1085102592571150095
  %21 = or disjoint i64 %18, %20
  %22 = lshr i64 %21, 56
  %23 = trunc nuw i64 %22 to i8
  %24 = getelementptr inbounds i8, ptr %0, i64 48
  store i8 %23, ptr %24, align 8, !tbaa !12
  %25 = lshr i64 %21, 48
  %26 = trunc i64 %25 to i8
  %27 = getelementptr inbounds i8, ptr %0, i64 49
  store i8 %26, ptr %27, align 1, !tbaa !12
  %28 = lshr i64 %21, 40
  %29 = trunc i64 %28 to i8
  %30 = getelementptr inbounds i8, ptr %0, i64 50
  store i8 %29, ptr %30, align 2, !tbaa !12
  %31 = lshr i64 %21, 32
  %32 = trunc i64 %31 to i8
  %33 = getelementptr inbounds i8, ptr %0, i64 51
  store i8 %32, ptr %33, align 1, !tbaa !12
  %34 = lshr i64 %21, 24
  %35 = trunc i64 %34 to i8
  %36 = getelementptr inbounds i8, ptr %0, i64 52
  store i8 %35, ptr %36, align 4, !tbaa !12
  %37 = lshr i64 %21, 16
  %38 = trunc i64 %37 to i8
  %39 = getelementptr inbounds i8, ptr %0, i64 53
  store i8 %38, ptr %39, align 1, !tbaa !12
  %40 = lshr i64 %21, 8
  %41 = trunc i64 %40 to i8
  %42 = getelementptr inbounds i8, ptr %0, i64 54
  store i8 %41, ptr %42, align 2, !tbaa !12
  %43 = trunc i64 %21 to i8
  %44 = getelementptr inbounds i8, ptr %0, i64 55
  store i8 %43, ptr %44, align 1, !tbaa !12
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !9, i64 40}
!6 = !{!"", !7, i64 0, !7, i64 16, !9, i64 32, !9, i64 40, !7, i64 48, !10, i64 64}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!6, !9, i64 32}
!12 = !{!7, !7, i64 0}


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