; LLVM IR from stamparm/cryptospecs :: symmetrical/sources (3-way)

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

; 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 @rndcon_gen(i64 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %6

6:                                                ; preds = %24, %2
  %7 = load i32, ptr %5, align 4, !tbaa !11
  %8 = icmp sle i32 %7, 11
  br i1 %8, label %9, label %27

9:                                                ; preds = %6
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !9
  %12 = load i32, ptr %5, align 4, !tbaa !11
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i64, ptr %11, i64 %13
  store i64 %10, ptr %14, align 8, !tbaa !5
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = shl i64 %15, 1
  store i64 %16, ptr %3, align 8, !tbaa !5
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = and i64 %17, 65536
  %19 = icmp ne i64 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %9
  %21 = load i64, ptr %3, align 8, !tbaa !5
  %22 = xor i64 %21, 69649
  store i64 %22, ptr %3, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %20, %9
  br label %24

24:                                               ; preds = %23
  %25 = load i32, ptr %5, align 4, !tbaa !11
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %5, align 4, !tbaa !11
  br label %6, !llvm.loop !13

27:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @rndcon_gen(i64 noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  store i64 %0, ptr %1, align 8, !tbaa !5
  %3 = shl i64 %0, 1
  %4 = and i64 %0, 32768
  %.not = icmp eq i64 %4, 0
  %5 = xor i64 %3, 69649
  %spec.select = select i1 %.not, i64 %3, i64 %5
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  store i64 %spec.select, ptr %6, align 8, !tbaa !5
  %7 = shl i64 %spec.select, 1
  %8 = and i64 %spec.select, 32768
  %.not.1 = icmp eq i64 %8, 0
  %9 = xor i64 %7, 69649
  %spec.select.1 = select i1 %.not.1, i64 %7, i64 %9
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  store i64 %spec.select.1, ptr %10, align 8, !tbaa !5
  %11 = shl i64 %spec.select.1, 1
  %12 = and i64 %spec.select.1, 32768
  %.not.2 = icmp eq i64 %12, 0
  %13 = xor i64 %11, 69649
  %spec.select.2 = select i1 %.not.2, i64 %11, i64 %13
  %14 = getelementptr inbounds i8, ptr %1, i64 24
  store i64 %spec.select.2, ptr %14, align 8, !tbaa !5
  %15 = shl i64 %spec.select.2, 1
  %16 = and i64 %spec.select.2, 32768
  %.not.3 = icmp eq i64 %16, 0
  %17 = xor i64 %15, 69649
  %spec.select.3 = select i1 %.not.3, i64 %15, i64 %17
  %18 = getelementptr inbounds i8, ptr %1, i64 32
  store i64 %spec.select.3, ptr %18, align 8, !tbaa !5
  %19 = shl i64 %spec.select.3, 1
  %20 = and i64 %spec.select.3, 32768
  %.not.4 = icmp eq i64 %20, 0
  %21 = xor i64 %19, 69649
  %spec.select.4 = select i1 %.not.4, i64 %19, i64 %21
  %22 = getelementptr inbounds i8, ptr %1, i64 40
  store i64 %spec.select.4, ptr %22, align 8, !tbaa !5
  %23 = shl i64 %spec.select.4, 1
  %24 = and i64 %spec.select.4, 32768
  %.not.5 = icmp eq i64 %24, 0
  %25 = xor i64 %23, 69649
  %spec.select.5 = select i1 %.not.5, i64 %23, i64 %25
  %26 = getelementptr inbounds i8, ptr %1, i64 48
  store i64 %spec.select.5, ptr %26, align 8, !tbaa !5
  %27 = shl i64 %spec.select.5, 1
  %28 = and i64 %spec.select.5, 32768
  %.not.6 = icmp eq i64 %28, 0
  %29 = xor i64 %27, 69649
  %spec.select.6 = select i1 %.not.6, i64 %27, i64 %29
  %30 = getelementptr inbounds i8, ptr %1, i64 56
  store i64 %spec.select.6, ptr %30, align 8, !tbaa !5
  %31 = shl i64 %spec.select.6, 1
  %32 = and i64 %spec.select.6, 32768
  %.not.7 = icmp eq i64 %32, 0
  %33 = xor i64 %31, 69649
  %spec.select.7 = select i1 %.not.7, i64 %31, i64 %33
  %34 = getelementptr inbounds i8, ptr %1, i64 64
  store i64 %spec.select.7, ptr %34, align 8, !tbaa !5
  %35 = shl i64 %spec.select.7, 1
  %36 = and i64 %spec.select.7, 32768
  %.not.8 = icmp eq i64 %36, 0
  %37 = xor i64 %35, 69649
  %spec.select.8 = select i1 %.not.8, i64 %35, i64 %37
  %38 = getelementptr inbounds i8, ptr %1, i64 72
  store i64 %spec.select.8, ptr %38, align 8, !tbaa !5
  %39 = shl i64 %spec.select.8, 1
  %40 = and i64 %spec.select.8, 32768
  %.not.9 = icmp eq i64 %40, 0
  %41 = xor i64 %39, 69649
  %spec.select.9 = select i1 %.not.9, i64 %39, i64 %41
  %42 = getelementptr inbounds i8, ptr %1, i64 80
  store i64 %spec.select.9, ptr %42, align 8, !tbaa !5
  %43 = shl i64 %spec.select.9, 1
  %44 = and i64 %spec.select.9, 32768
  %.not.10 = icmp eq i64 %44, 0
  %45 = xor i64 %43, 69649
  %spec.select.10 = select i1 %.not.10, i64 %43, i64 %45
  %46 = getelementptr inbounds i8, ptr %1, i64 88
  store i64 %spec.select.10, ptr %46, align 8, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass