; LLVM IR from stamparm/cryptospecs :: symmetrical/sources (scop)

; 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.st_key = type { [384 x i64], i8, i8, i8 }

@kt = external dso_local global %struct.st_key, align 8
@__const.main.key = external hidden unnamed_addr constant [16 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@buf = external dso_local global [1024 x i64], align 16
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @init_key(ptr noundef, i32 noundef) #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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @main() #0 {
  %1 = alloca [16 x i8], align 16
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr %1) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %1, ptr align 16 @__const.main.key, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %5 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %6 = getelementptr inbounds [16 x i8], ptr %1, i64 0, i64 0
  call void @init_key(ptr noundef %6, i32 noundef 16)
  %7 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %15, %0
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 1024
  br i1 %10, label %11, label %18

11:                                               ; preds = %8
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [1024 x i64], ptr @buf, i64 0, i64 %13
  store i64 0, ptr %14, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %11
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %3, align 4, !tbaa !5
  br label %8, !llvm.loop !11

18:                                               ; preds = %8
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  call void @encrypt(ptr noundef @buf, i32 noundef 1024, ptr noundef @kt)
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i64 0, ptr %2, align 8, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %31, %18
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = icmp slt i32 %22, 1024
  br i1 %23, label %24, label %34

24:                                               ; preds = %21
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1024 x i64], ptr @buf, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = load i64, ptr %2, align 8, !tbaa !9
  %30 = xor i64 %29, %28
  store i64 %30, ptr %2, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %24
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %3, align 4, !tbaa !5
  br label %21, !llvm.loop !13

34:                                               ; preds = %21
  %35 = load i64, ptr %2, align 8, !tbaa !9
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %35)
  %37 = getelementptr inbounds [16 x i8], ptr %1, i64 0, i64 0
  call void @init_key(ptr noundef %37, i32 noundef 16)
  call void @decrypt(ptr noundef @buf, i32 noundef 1024, ptr noundef @kt)
  store i32 0, ptr %4, align 4, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %49, %34
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = icmp slt i32 %39, 1024
  br i1 %40, label %41, label %52

41:                                               ; preds = %38
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1024 x i64], ptr @buf, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = icmp ne i64 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %41
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %47, %41
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %3, align 4, !tbaa !5
  br label %38, !llvm.loop !14

52:                                               ; preds = %38
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %57

55:                                               ; preds = %52
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  br label %59

57:                                               ; preds = %52
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  br label %59

59:                                               ; preds = %57, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %1) #4
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare i32 @printf(ptr noundef, ...) #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: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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.st_key = type { [384 x i64], i8, i8, i8 }

@kt = external dso_local global %struct.st_key, align 8
@__const.main.key = external hidden unnamed_addr constant [16 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@buf = external dso_local global [1024 x i64], align 16
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @init_key(ptr noundef, i32 noundef) local_unnamed_addr #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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @main() local_unnamed_addr #0 {
vector.ph:
  %0 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %0) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %0, ptr noundef nonnull align 16 dereferenceable(16) @__const.main.key, i64 16, i1 false)
  %1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  call void @init_key(ptr noundef nonnull %0, i32 noundef 16)
  %2 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(8192) @buf, i8 0, i64 8192, i1 false), !tbaa !5
  %3 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  call void @encrypt(ptr noundef nonnull @buf, i32 noundef 1024, ptr noundef nonnull @kt)
  %4 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next.3, %vector.body ]
  %vec.phi = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %19, %vector.body ]
  %vec.phi27 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %20, %vector.body ]
  %5 = getelementptr inbounds [1024 x i64], ptr @buf, i64 0, i64 %index
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %wide.load = load <2 x i64>, ptr %5, align 16, !tbaa !5
  %wide.load28 = load <2 x i64>, ptr %6, align 16, !tbaa !5
  %7 = xor <2 x i64> %wide.load, %vec.phi
  %8 = xor <2 x i64> %wide.load28, %vec.phi27
  %index.next = or disjoint i64 %index, 4
  %9 = getelementptr inbounds [1024 x i64], ptr @buf, i64 0, i64 %index.next
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  %wide.load.1 = load <2 x i64>, ptr %9, align 16, !tbaa !5
  %wide.load28.1 = load <2 x i64>, ptr %10, align 16, !tbaa !5
  %11 = xor <2 x i64> %wide.load.1, %7
  %12 = xor <2 x i64> %wide.load28.1, %8
  %index.next.1 = or disjoint i64 %index, 8
  %13 = getelementptr inbounds [1024 x i64], ptr @buf, i64 0, i64 %index.next.1
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %wide.load.2 = load <2 x i64>, ptr %13, align 16, !tbaa !5
  %wide.load28.2 = load <2 x i64>, ptr %14, align 16, !tbaa !5
  %15 = xor <2 x i64> %wide.load.2, %11
  %16 = xor <2 x i64> %wide.load28.2, %12
  %index.next.2 = or disjoint i64 %index, 12
  %17 = getelementptr inbounds [1024 x i64], ptr @buf, i64 0, i64 %index.next.2
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %wide.load.3 = load <2 x i64>, ptr %17, align 16, !tbaa !5
  %wide.load28.3 = load <2 x i64>, ptr %18, align 16, !tbaa !5
  %19 = xor <2 x i64> %wide.load.3, %15
  %20 = xor <2 x i64> %wide.load28.3, %16
  %index.next.3 = add nuw nsw i64 %index, 16
  %21 = icmp eq i64 %index.next.3, 1024
  br i1 %21, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = xor <2 x i64> %20, %19
  %22 = call i64 @llvm.vector.reduce.xor.v2i64(<2 x i64> %bin.rdx)
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %22)
  call void @init_key(ptr noundef nonnull %0, i32 noundef 16)
  call void @decrypt(ptr noundef nonnull @buf, i32 noundef 1024, ptr noundef nonnull @kt)
  br label %24

24:                                               ; preds = %24, %middle.block
  %indvars.iv23 = phi i64 [ 0, %middle.block ], [ %indvars.iv.next24.3, %24 ]
  %.020 = phi i32 [ 0, %middle.block ], [ %spec.select.3, %24 ]
  %25 = getelementptr inbounds [1024 x i64], ptr @buf, i64 0, i64 %indvars.iv23
  %26 = load i64, ptr %25, align 16, !tbaa !5
  %.not15 = icmp eq i64 %26, 0
  %indvars.iv.next24 = or disjoint i64 %indvars.iv23, 1
  %27 = getelementptr inbounds [1024 x i64], ptr @buf, i64 0, i64 %indvars.iv.next24
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %.not15.1 = icmp eq i64 %28, 0
  %indvars.iv.next24.1 = or disjoint i64 %indvars.iv23, 2
  %29 = getelementptr inbounds [1024 x i64], ptr @buf, i64 0, i64 %indvars.iv.next24.1
  %30 = load i64, ptr %29, align 16, !tbaa !5
  %.not15.2 = icmp eq i64 %30, 0
  %indvars.iv.next24.2 = or disjoint i64 %indvars.iv23, 3
  %31 = getelementptr inbounds [1024 x i64], ptr @buf, i64 0, i64 %indvars.iv.next24.2
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %.not15.3 = icmp eq i64 %32, 0
  %33 = select i1 %.not15.3, i1 %.not15.2, i1 false
  %34 = select i1 %33, i1 %.not15.1, i1 false
  %35 = select i1 %34, i1 %.not15, i1 false
  %spec.select.3 = select i1 %35, i32 %.020, i32 1
  %indvars.iv.next24.3 = add nuw nsw i64 %indvars.iv23, 4
  %exitcond26.not.3 = icmp eq i64 %indvars.iv.next24.3, 1024
  br i1 %exitcond26.not.3, label %36, label %24, !llvm.loop !13

36:                                               ; preds = %24
  %.not = icmp eq i32 %spec.select.3, 0
  %.str.6..str.5 = select i1 %.not, ptr @.str.6, ptr @.str.5
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.6..str.5)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %0) #6
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.xor.v2i64(<2 x i64>) #5

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: readwrite) }
attributes #3 = { nofree nounwind "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass