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

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #0

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @ripemd_alloc(i32 noundef %0) #4 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  store ptr null, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %1
  %6 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 160) #7
  store ptr %6, ptr %3, align 8, !tbaa !9
  %7 = icmp eq ptr null, %6
  br i1 %7, label %8, label %10

8:                                                ; preds = %5
  store i32 1, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 655, i32 noundef %9, ptr noundef null)
  br label %36

10:                                               ; preds = %5
  br label %11

11:                                               ; preds = %10
  br label %12

12:                                               ; preds = %11
  %13 = load i32, ptr %2, align 4, !tbaa !5
  switch i32 %13, label %26 [
    i32 0, label %14
    i32 1, label %20
  ]

14:                                               ; preds = %12
  %15 = load ptr, ptr %3, align 8, !tbaa !9
  call void @ripemd_init128(ptr noundef %15)
  %16 = load ptr, ptr %3, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.RipemdCtx_st, ptr %16, i32 0, i32 3
  store i64 128, ptr %17, align 8, !tbaa !11
  %18 = load ptr, ptr %3, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.RipemdCtx_st, ptr %18, i32 0, i32 5
  store ptr @compress_128, ptr %19, align 8, !tbaa !14
  br label %31

20:                                               ; preds = %12
  %21 = load ptr, ptr %3, align 8, !tbaa !9
  call void @ripemd_init160(ptr noundef %21)
  %22 = load ptr, ptr %3, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.RipemdCtx_st, ptr %22, i32 0, i32 3
  store i64 160, ptr %23, align 8, !tbaa !11
  %24 = load ptr, ptr %3, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.RipemdCtx_st, ptr %24, i32 0, i32 5
  store ptr @compress_160, ptr %25, align 8, !tbaa !14
  br label %31

26:                                               ; preds = %12
  br label %27

27:                                               ; preds = %26
  store i32 2, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 668, i32 noundef %28, ptr noundef null)
  br label %36

29:                                               ; No predecessors!
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30, %20, %14
  %32 = load ptr, ptr %3, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.RipemdCtx_st, ptr %32, i32 0, i32 4
  store i64 0, ptr %33, align 8, !tbaa !15
  %34 = load ptr, ptr %3, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.RipemdCtx_st, ptr %34, i32 0, i32 2
  store i64 0, ptr %35, align 8, !tbaa !16
  br label %36

36:                                               ; preds = %31, %27, %8
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %41

39:                                               ; preds = %36
  %40 = load ptr, ptr %3, align 8, !tbaa !9
  call void @free(ptr noundef %40) #6
  store ptr null, ptr %3, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %39, %36
  %42 = load ptr, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret ptr %42
}

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #5

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { inlinehint 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 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 #5 = { nounwind allocsize(0,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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0,1) }

!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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 136}
!12 = !{!"RipemdCtx_st", !7, i64 0, !7, i64 64, !13, i64 128, !13, i64 136, !13, i64 144, !10, i64 152}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !10, i64 152}
!15 = !{!12, !13, i64 144}
!16 = !{!12, !13, i64 128}


; 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 [16 x i8], align 1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @ripemd_alloc(i32 noundef %0) local_unnamed_addr #3 {
  %2 = tail call noalias dereferenceable_or_null(160) ptr @calloc(i64 noundef 1, i64 noundef 160) #5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %5

4:                                                ; preds = %1
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 655, i32 noundef 1, ptr noundef null) #6
  br label %.critedge

5:                                                ; preds = %1
  switch i32 %0, label %8 [
    i32 0, label %6
    i32 1, label %7
  ]

6:                                                ; preds = %5
  tail call void @ripemd_init128(ptr noundef nonnull %2)
  br label %9

7:                                                ; preds = %5
  tail call void @ripemd_init160(ptr noundef nonnull %2)
  br label %9

8:                                                ; preds = %5
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 668, i32 noundef 2, ptr noundef null) #6
  br label %.critedge

9:                                                ; preds = %7, %6
  %.sink = phi i64 [ 160, %7 ], [ 128, %6 ]
  %compress_160.sink = phi ptr [ @compress_160, %7 ], [ @compress_128, %6 ]
  %10 = getelementptr inbounds i8, ptr %2, i64 136
  store i64 %.sink, ptr %10, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %2, i64 152
  store ptr %compress_160.sink, ptr %11, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %2, i64 144
  store i64 0, ptr %12, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %2, i64 128
  store i64 0, ptr %13, align 8, !tbaa !13
  br label %14

.critedge:                                        ; preds = %8, %4
  tail call void @free(ptr noundef %2) #6
  br label %14

14:                                               ; preds = %9, %.critedge
  %.013 = phi ptr [ null, %.critedge ], [ %2, %9 ]
  ret ptr %.013
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @compress_128(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @compress_160(ptr noundef, ptr noundef) #2

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 = { inlinehint 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 = { 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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { nounwind allocsize(0,1) }
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, !9, i64 136}
!6 = !{!"RipemdCtx_st", !7, i64 0, !7, i64 64, !9, i64 128, !9, i64 136, !9, i64 144, !10, i64 152}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!6, !10, i64 152}
!12 = !{!6, !9, i64 144}
!13 = !{!6, !9, i64 128}


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