; LLVM IR from oreparaz/dudect :: examples/aes32 (dut_aes32)

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

@randombytes.fd = external hidden global i32, align 4
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@__PRETTY_FUNCTION__.randombytes = external hidden unnamed_addr constant [36 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @randombytes(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %7 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %7, ptr %6, align 8, !tbaa !9
  %8 = load i64, ptr %6, align 8, !tbaa !9
  %9 = icmp sge i64 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %12

11:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 236, ptr noundef @__PRETTY_FUNCTION__.randombytes) #5
  unreachable

12:                                               ; preds = %10
  %13 = load i32, ptr @randombytes.fd, align 4, !tbaa !11
  %14 = icmp eq i32 %13, -1
  br i1 %14, label %15, label %24

15:                                               ; preds = %12
  br label %16

16:                                               ; preds = %21, %15
  %17 = call i32 (ptr, i32, ...) @open(ptr noundef @.str.2, i32 noundef 0)
  store i32 %17, ptr @randombytes.fd, align 4, !tbaa !11
  %18 = load i32, ptr @randombytes.fd, align 4, !tbaa !11
  %19 = icmp ne i32 %18, -1
  br i1 %19, label %20, label %21

20:                                               ; preds = %16
  br label %23

21:                                               ; preds = %16
  %22 = call i32 @sleep(i32 noundef 1)
  br label %16

23:                                               ; preds = %20
  br label %24

24:                                               ; preds = %23, %12
  br label %25

25:                                               ; preds = %43, %41, %24
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = icmp sgt i64 %26, 0
  br i1 %27, label %28, label %50

28:                                               ; preds = %25
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = icmp slt i64 %29, 1048576
  br i1 %30, label %31, label %33

31:                                               ; preds = %28
  %32 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %32, ptr %5, align 8, !tbaa !9
  br label %34

33:                                               ; preds = %28
  store i64 1048576, ptr %5, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %33, %31
  %35 = load i32, ptr @randombytes.fd, align 4, !tbaa !11
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load i64, ptr %5, align 8, !tbaa !9
  %38 = call i64 @read(i32 noundef %35, ptr noundef %36, i64 noundef %37)
  store i64 %38, ptr %5, align 8, !tbaa !9
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = icmp slt i64 %39, 1
  br i1 %40, label %41, label %43

41:                                               ; preds = %34
  %42 = call i32 @sleep(i32 noundef 1)
  br label %25, !llvm.loop !13

43:                                               ; preds = %34
  %44 = load i64, ptr %5, align 8, !tbaa !9
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 %44
  store ptr %46, ptr %3, align 8, !tbaa !5
  %47 = load i64, ptr %5, align 8, !tbaa !9
  %48 = load i64, ptr %6, align 8, !tbaa !9
  %49 = sub nsw i64 %48, %47
  store i64 %49, ptr %6, align 8, !tbaa !9
  br label %25, !llvm.loop !13

50:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

declare i32 @open(ptr noundef, i32 noundef, ...) #3

declare i32 @sleep(i32 noundef) #3

declare i64 @read(i32 noundef, ptr noundef, i64 noundef) #3

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

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 = { noreturn 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 #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 }
attributes #5 = { noreturn 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", !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"

@randombytes.fd = external hidden local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@__PRETTY_FUNCTION__.randombytes = external hidden unnamed_addr constant [36 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @randombytes(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i64 %1, -1
  br i1 %3, label %5, label %4

4:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 236, ptr noundef nonnull @__PRETTY_FUNCTION__.randombytes) #5
  unreachable

5:                                                ; preds = %2
  %6 = load i32, ptr @randombytes.fd, align 4, !tbaa !5
  %7 = icmp eq i32 %6, -1
  br i1 %7, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %5
  %8 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull @.str.2, i32 noundef 0) #6
  store i32 %8, ptr @randombytes.fd, align 4, !tbaa !5
  %.not15 = icmp eq i32 %8, -1
  br i1 %.not15, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %9 = tail call i32 @sleep(i32 noundef 1) #6
  %10 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull @.str.2, i32 noundef 0) #6
  store i32 %10, ptr @randombytes.fd, align 4, !tbaa !5
  %.not = icmp eq i32 %10, -1
  br i1 %.not, label %.lr.ph, label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.preheader, %5
  %.not21 = icmp eq i64 %1, 0
  br i1 %.not21, label %.outer._crit_edge, label %.lr.ph16.split.us

.lr.ph16.split.us:                                ; preds = %.loopexit, %.outer
  %.0.ph20 = phi i64 [ %19, %.outer ], [ %1, %.loopexit ]
  %.012.ph18 = phi ptr [ %18, %.outer ], [ %0, %.loopexit ]
  %.0. = tail call i64 @llvm.umin.i64(i64 %.0.ph20, i64 1048576)
  %11 = load i32, ptr @randombytes.fd, align 4, !tbaa !5
  %12 = tail call i64 @read(i32 noundef %11, ptr noundef %.012.ph18, i64 noundef %.0.) #6
  %13 = icmp slt i64 %12, 1
  br i1 %13, label %.lr.ph17, label %.outer

.lr.ph17:                                         ; preds = %.lr.ph16.split.us, %.lr.ph17
  %14 = tail call i32 @sleep(i32 noundef 1) #6
  %15 = load i32, ptr @randombytes.fd, align 4, !tbaa !5
  %16 = tail call i64 @read(i32 noundef %15, ptr noundef %.012.ph18, i64 noundef %.0.) #6
  %17 = icmp slt i64 %16, 1
  br i1 %17, label %.lr.ph17, label %.outer

.outer:                                           ; preds = %.lr.ph17, %.lr.ph16.split.us
  %.us-phi = phi i64 [ %12, %.lr.ph16.split.us ], [ %16, %.lr.ph17 ]
  %18 = getelementptr inbounds i8, ptr %.012.ph18, i64 %.us-phi
  %19 = sub nsw i64 %.0.ph20, %.us-phi
  %20 = icmp sgt i64 %19, 0
  br i1 %20, label %.lr.ph16.split.us, label %.outer._crit_edge, !llvm.loop !9

.outer._crit_edge:                                ; preds = %.outer, %.loopexit
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nofree
declare noundef i32 @open(ptr nocapture noundef readonly, i32 noundef, ...) local_unnamed_addr #2

declare i32 @sleep(i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree
declare noundef i64 @read(i32 noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #4

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 = { noreturn 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 #2 = { nofree "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 #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { noreturn nounwind }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass