; LLVM IR from attractivechaos/klib :: kurl (sha1_final_hmac)

; 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.sha1nfo = type { %union.anon, i8, %union.anon.0, i32, [64 x i8], [20 x i8] }
%union.anon = type { [16 x i32] }
%union.anon.0 = type { [5 x i32] }

; 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 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @sha1_init(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @sha1_write1(ptr noundef, i8 noundef zeroext) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @sha1_final(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @sha1_final_hmac(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.sha1nfo, ptr %4, i32 0, i32 5
  %6 = getelementptr inbounds [20 x i8], ptr %5, i64 0, i64 0
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = call ptr @sha1_final(ptr noundef %7)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 1 %8, i64 20, i1 false)
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  call void @sha1_init(ptr noundef %9)
  store i8 0, ptr %3, align 1, !tbaa !9
  br label %10

10:                                               ; preds = %25, %1
  %11 = load i8, ptr %3, align 1, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = icmp slt i32 %12, 64
  br i1 %13, label %14, label %28

14:                                               ; preds = %10
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.sha1nfo, ptr %16, i32 0, i32 4
  %18 = load i8, ptr %3, align 1, !tbaa !9
  %19 = zext i8 %18 to i64
  %20 = getelementptr inbounds [64 x i8], ptr %17, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = zext i8 %21 to i32
  %23 = xor i32 %22, 92
  %24 = trunc i32 %23 to i8
  call void @sha1_write1(ptr noundef %15, i8 noundef zeroext %24)
  br label %25

25:                                               ; preds = %14
  %26 = load i8, ptr %3, align 1, !tbaa !9
  %27 = add i8 %26, 1
  store i8 %27, ptr %3, align 1, !tbaa !9
  br label %10, !llvm.loop !10

28:                                               ; preds = %10
  store i8 0, ptr %3, align 1, !tbaa !9
  br label %29

29:                                               ; preds = %41, %28
  %30 = load i8, ptr %3, align 1, !tbaa !9
  %31 = zext i8 %30 to i32
  %32 = icmp slt i32 %31, 20
  br i1 %32, label %33, label %44

33:                                               ; preds = %29
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.sha1nfo, ptr %35, i32 0, i32 5
  %37 = load i8, ptr %3, align 1, !tbaa !9
  %38 = zext i8 %37 to i64
  %39 = getelementptr inbounds [20 x i8], ptr %36, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !9
  call void @sha1_write1(ptr noundef %34, i8 noundef zeroext %40)
  br label %41

41:                                               ; preds = %33
  %42 = load i8, ptr %3, align 1, !tbaa !9
  %43 = add i8 %42, 1
  store i8 %43, ptr %3, align 1, !tbaa !9
  br label %29, !llvm.loop !12

44:                                               ; preds = %29
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = call ptr @sha1_final(ptr noundef %45)
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  ret ptr %46
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

; Function Attrs: nounwind uwtable
declare dso_local void @sha1_init(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @sha1_write1(ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @sha1_final(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @sha1_final_hmac(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 156
  %3 = tail call ptr @sha1_final(ptr noundef %0)
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(20) %2, ptr noundef nonnull align 1 dereferenceable(20) %3, i64 20, i1 false)
  tail call void @sha1_init(ptr noundef %0)
  %4 = getelementptr inbounds i8, ptr %0, i64 92
  br label %5

5:                                                ; preds = %1, %5
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %5 ]
  %6 = getelementptr inbounds [64 x i8], ptr %4, i64 0, i64 %indvars.iv
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = xor i8 %7, 92
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %8)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 64
  br i1 %exitcond.not, label %.preheader.preheader, label %5, !llvm.loop !8

.preheader.preheader:                             ; preds = %5
  %9 = load i8, ptr %2, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %9)
  %10 = getelementptr inbounds i8, ptr %0, i64 157
  %11 = load i8, ptr %10, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %11)
  %12 = getelementptr inbounds i8, ptr %0, i64 158
  %13 = load i8, ptr %12, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %13)
  %14 = getelementptr inbounds i8, ptr %0, i64 159
  %15 = load i8, ptr %14, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %15)
  %16 = getelementptr inbounds i8, ptr %0, i64 160
  %17 = load i8, ptr %16, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %17)
  %18 = getelementptr inbounds i8, ptr %0, i64 161
  %19 = load i8, ptr %18, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %19)
  %20 = getelementptr inbounds i8, ptr %0, i64 162
  %21 = load i8, ptr %20, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %21)
  %22 = getelementptr inbounds i8, ptr %0, i64 163
  %23 = load i8, ptr %22, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %23)
  %24 = getelementptr inbounds i8, ptr %0, i64 164
  %25 = load i8, ptr %24, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %25)
  %26 = getelementptr inbounds i8, ptr %0, i64 165
  %27 = load i8, ptr %26, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %27)
  %28 = getelementptr inbounds i8, ptr %0, i64 166
  %29 = load i8, ptr %28, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %29)
  %30 = getelementptr inbounds i8, ptr %0, i64 167
  %31 = load i8, ptr %30, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %31)
  %32 = getelementptr inbounds i8, ptr %0, i64 168
  %33 = load i8, ptr %32, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %33)
  %34 = getelementptr inbounds i8, ptr %0, i64 169
  %35 = load i8, ptr %34, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %35)
  %36 = getelementptr inbounds i8, ptr %0, i64 170
  %37 = load i8, ptr %36, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %37)
  %38 = getelementptr inbounds i8, ptr %0, i64 171
  %39 = load i8, ptr %38, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %39)
  %40 = getelementptr inbounds i8, ptr %0, i64 172
  %41 = load i8, ptr %40, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %41)
  %42 = getelementptr inbounds i8, ptr %0, i64 173
  %43 = load i8, ptr %42, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %43)
  %44 = getelementptr inbounds i8, ptr %0, i64 174
  %45 = load i8, ptr %44, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %45)
  %46 = getelementptr inbounds i8, ptr %0, i64 175
  %47 = load i8, ptr %46, align 1, !tbaa !5
  tail call void @sha1_write1(ptr noundef nonnull %0, i8 noundef zeroext %47)
  %48 = tail call ptr @sha1_final(ptr noundef nonnull %0)
  ret ptr %48
}

attributes #0 = { mustprogress nocallback nofree 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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass