; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (whirlpool)

; 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.ByteArray_st = type { ptr, i64 }
%struct.WhirlpoolCtx_st = type { i64, [8 x i64], [64 x i8], i64 }

@.str = external hidden unnamed_addr constant [19 x i8], align 1

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

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #1

; 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

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

9:                                                ; preds = %2
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %14, label %12

12:                                               ; preds = %9
  store i32 2, ptr %5, align 4, !tbaa !9
  %13 = load i32, ptr %5, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 220, i32 noundef %13, ptr noundef null)
  br label %84

14:                                               ; preds = %9
  br label %15

15:                                               ; preds = %14
  br label %16

16:                                               ; preds = %15
  br label %17

17:                                               ; preds = %16
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %22, label %20

20:                                               ; preds = %17
  store i32 2, ptr %5, align 4, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 221, i32 noundef %21, ptr noundef null)
  br label %84

22:                                               ; preds = %17
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ByteArray_st, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  store ptr %27, ptr %8, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ByteArray_st, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !14
  store i64 %30, ptr %7, align 8, !tbaa !15
  %31 = load i64, ptr %7, align 8, !tbaa !15
  %32 = mul i64 %31, 8
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.WhirlpoolCtx_st, ptr %33, i32 0, i32 0
  %35 = load i64, ptr %34, align 8, !tbaa !16
  %36 = add i64 %35, %32
  store i64 %36, ptr %34, align 8, !tbaa !16
  br label %37

37:                                               ; preds = %82, %24
  %38 = load i64, ptr %7, align 8, !tbaa !15
  %39 = icmp ugt i64 %38, 0
  br i1 %39, label %40, label %83

40:                                               ; preds = %37
  %41 = load i64, ptr %7, align 8, !tbaa !15
  store i64 %41, ptr %6, align 8, !tbaa !15
  %42 = load i64, ptr %6, align 8, !tbaa !15
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.WhirlpoolCtx_st, ptr %43, i32 0, i32 3
  %45 = load i64, ptr %44, align 8, !tbaa !18
  %46 = sub i64 64, %45
  %47 = icmp ugt i64 %42, %46
  br i1 %47, label %48, label %53

48:                                               ; preds = %40
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.WhirlpoolCtx_st, ptr %49, i32 0, i32 3
  %51 = load i64, ptr %50, align 8, !tbaa !18
  %52 = sub i64 64, %51
  store i64 %52, ptr %6, align 8, !tbaa !15
  br label %53

53:                                               ; preds = %48, %40
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.WhirlpoolCtx_st, ptr %54, i32 0, i32 2
  %56 = getelementptr inbounds [64 x i8], ptr %55, i64 0, i64 0
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.WhirlpoolCtx_st, ptr %57, i32 0, i32 3
  %59 = load i64, ptr %58, align 8, !tbaa !18
  %60 = getelementptr inbounds i8, ptr %56, i64 %59
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load i64, ptr %6, align 8, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %60, ptr align 1 %61, i64 %62, i1 false)
  %63 = load i64, ptr %6, align 8, !tbaa !15
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.WhirlpoolCtx_st, ptr %64, i32 0, i32 3
  %66 = load i64, ptr %65, align 8, !tbaa !18
  %67 = add i64 %66, %63
  store i64 %67, ptr %65, align 8, !tbaa !18
  %68 = load i64, ptr %6, align 8, !tbaa !15
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %69, i64 %68
  store ptr %70, ptr %8, align 8, !tbaa !5
  %71 = load i64, ptr %6, align 8, !tbaa !15
  %72 = load i64, ptr %7, align 8, !tbaa !15
  %73 = sub i64 %72, %71
  store i64 %73, ptr %7, align 8, !tbaa !15
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.WhirlpoolCtx_st, ptr %74, i32 0, i32 3
  %76 = load i64, ptr %75, align 8, !tbaa !18
  %77 = icmp eq i64 %76, 64
  br i1 %77, label %78, label %82

78:                                               ; preds = %53
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  call void @whirlpool_compress(ptr noundef %79)
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.WhirlpoolCtx_st, ptr %80, i32 0, i32 3
  store i64 0, ptr %81, align 8, !tbaa !18
  br label %82

82:                                               ; preds = %78, %53
  br label %37, !llvm.loop !19

83:                                               ; preds = %37
  br label %84

84:                                               ; preds = %83, %20, %12
  %85 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %85
}

; Function Attrs: nounwind uwtable
declare hidden void @whirlpool_compress(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!"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 = !{!12, !6, i64 0}
!12 = !{!"ByteArray_st", !6, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!13, !13, i64 0}
!16 = !{!17, !13, i64 0}
!17 = !{!"WhirlpoolCtx_st", !13, i64 0, !7, i64 8, !7, i64 72, !13, i64 136}
!18 = !{!17, !13, i64 136}
!19 = distinct !{!19, !20}
!20 = !{!"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"

@.str = external hidden unnamed_addr constant [19 x i8], align 1

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; 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) #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @whirlpool_update(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit.sink.split, label %3

3:                                                ; preds = %2
  %.not32 = icmp eq ptr %1, null
  br i1 %.not32, label %.loopexit.sink.split, label %4

4:                                                ; preds = %3
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %8 = shl i64 %7, 3
  %9 = load i64, ptr %0, align 8, !tbaa !12
  %10 = add i64 %9, %8
  store i64 %10, ptr %0, align 8, !tbaa !12
  %.not3334 = icmp eq i64 %7, 0
  br i1 %.not3334, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %11 = getelementptr inbounds i8, ptr %0, i64 136
  %12 = getelementptr inbounds i8, ptr %0, i64 72
  %.pre = load i64, ptr %11, align 8, !tbaa !14
  br label %13

13:                                               ; preds = %.lr.ph, %23
  %14 = phi i64 [ %.pre, %.lr.ph ], [ %24, %23 ]
  %.036 = phi ptr [ %5, %.lr.ph ], [ %19, %23 ]
  %.02635 = phi i64 [ %7, %.lr.ph ], [ %20, %23 ]
  %15 = sub i64 64, %14
  %spec.select = tail call i64 @llvm.umin.i64(i64 %.02635, i64 %15)
  %16 = getelementptr inbounds i8, ptr %12, i64 %14
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %16, ptr align 1 %.036, i64 %spec.select, i1 false)
  %17 = load i64, ptr %11, align 8, !tbaa !14
  %18 = add i64 %17, %spec.select
  store i64 %18, ptr %11, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %.036, i64 %spec.select
  %20 = sub i64 %.02635, %spec.select
  %21 = icmp eq i64 %18, 64
  br i1 %21, label %22, label %23

22:                                               ; preds = %13
  tail call void @whirlpool_compress(ptr noundef nonnull %0)
  store i64 0, ptr %11, align 8, !tbaa !14
  br label %23

23:                                               ; preds = %22, %13
  %24 = phi i64 [ 0, %22 ], [ %18, %13 ]
  %.not33 = icmp eq i64 %20, 0
  br i1 %.not33, label %.loopexit, label %13, !llvm.loop !15

.loopexit.sink.split:                             ; preds = %3, %2
  %.sink = phi i64 [ 220, %2 ], [ 221, %3 ]
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef %.sink, i32 noundef 2, ptr noundef null) #4
  br label %.loopexit

.loopexit:                                        ; preds = %23, %.loopexit.sink.split, %4
  %.028 = phi i32 [ 0, %4 ], [ 2, %.loopexit.sink.split ], [ 0, %23 ]
  ret i32 %.028
}

; Function Attrs: nounwind uwtable
declare hidden void @whirlpool_compress(ptr noundef) local_unnamed_addr #2

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

attributes #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 nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"ByteArray_st", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!13, !10, i64 0}
!13 = !{!"WhirlpoolCtx_st", !10, i64 0, !8, i64 8, !8, i64 72, !10, i64 136}
!14 = !{!13, !10, i64 136}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass