; LLVM IR from kala13x/libxutils :: src/crypt (sha1)

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

@.str.2 = external hidden unnamed_addr constant [5 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

; 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 i32 @XSHA1_Compute(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XSHA1_ComputeSum(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i8, align 1
  %11 = alloca [20 x i8], align 16
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = icmp uge i64 %12, 41
  br i1 %13, label %14, label %17

14:                                               ; preds = %4
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %14, %4
  store i32 -2, ptr %5, align 4
  br label %47

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 20, ptr %11) #3
  %19 = getelementptr inbounds [20 x i8], ptr %11, i64 0, i64 0
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = call i32 @XSHA1_Compute(ptr noundef %19, i64 noundef %20, ptr noundef %21, i64 noundef %22)
  store i8 0, ptr %10, align 1, !tbaa !11
  br label %24

24:                                               ; preds = %41, %18
  %25 = load i8, ptr %10, align 1, !tbaa !11
  %26 = zext i8 %25 to i32
  %27 = icmp slt i32 %26, 20
  br i1 %27, label %28, label %44

28:                                               ; preds = %24
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i8, ptr %10, align 1, !tbaa !11
  %31 = zext i8 %30 to i32
  %32 = mul nsw i32 %31, 2
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %29, i64 %33
  %35 = load i8, ptr %10, align 1, !tbaa !11
  %36 = zext i8 %35 to i64
  %37 = getelementptr inbounds [20 x i8], ptr %11, i64 0, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !11
  %39 = zext i8 %38 to i32
  %40 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef %34, i64 noundef 3, ptr noundef @.str.2, i32 noundef %39)
  br label %41

41:                                               ; preds = %28
  %42 = load i8, ptr %10, align 1, !tbaa !11
  %43 = add i8 %42, 1
  store i8 %43, ptr %10, align 1, !tbaa !11
  br label %24, !llvm.loop !12

44:                                               ; preds = %24
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 40
  store i8 0, ptr %46, align 1, !tbaa !11
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 20, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  br label %47

47:                                               ; preds = %44, %17
  %48 = load i32, ptr %5, align 4
  ret i32 %48
}

declare i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) #2

attributes #0 = { nocallback nofree nosync 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" }
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 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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.2 = external hidden unnamed_addr constant [5 x i8], align 1

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

; Function Attrs: mustprogress 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 i32 @XSHA1_Compute(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2, 2) i32 @XSHA1_ComputeSum(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #1 {
  %5 = alloca [20 x i8], align 16
  %6 = icmp ugt i64 %1, 40
  %7 = icmp ne ptr %0, null
  %or.cond = and i1 %7, %6
  br i1 %or.cond, label %8, label %109

8:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %5) #3
  %9 = call i32 @XSHA1_Compute(ptr noundef nonnull %5, i64 noundef %1, ptr noundef %2, i64 noundef %3)
  %10 = load i8, ptr %5, align 16, !tbaa !5
  %11 = zext i8 %10 to i32
  %12 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %0, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %11) #3
  %13 = getelementptr inbounds i8, ptr %0, i64 2
  %14 = getelementptr inbounds i8, ptr %5, i64 1
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = zext i8 %15 to i32
  %17 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %13, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %16) #3
  %18 = getelementptr inbounds i8, ptr %0, i64 4
  %19 = getelementptr inbounds i8, ptr %5, i64 2
  %20 = load i8, ptr %19, align 2, !tbaa !5
  %21 = zext i8 %20 to i32
  %22 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %18, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %21) #3
  %23 = getelementptr inbounds i8, ptr %0, i64 6
  %24 = getelementptr inbounds i8, ptr %5, i64 3
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = zext i8 %25 to i32
  %27 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %23, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %26) #3
  %28 = getelementptr inbounds i8, ptr %0, i64 8
  %29 = getelementptr inbounds i8, ptr %5, i64 4
  %30 = load i8, ptr %29, align 4, !tbaa !5
  %31 = zext i8 %30 to i32
  %32 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %28, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %31) #3
  %33 = getelementptr inbounds i8, ptr %0, i64 10
  %34 = getelementptr inbounds i8, ptr %5, i64 5
  %35 = load i8, ptr %34, align 1, !tbaa !5
  %36 = zext i8 %35 to i32
  %37 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %33, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %36) #3
  %38 = getelementptr inbounds i8, ptr %0, i64 12
  %39 = getelementptr inbounds i8, ptr %5, i64 6
  %40 = load i8, ptr %39, align 2, !tbaa !5
  %41 = zext i8 %40 to i32
  %42 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %38, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %41) #3
  %43 = getelementptr inbounds i8, ptr %0, i64 14
  %44 = getelementptr inbounds i8, ptr %5, i64 7
  %45 = load i8, ptr %44, align 1, !tbaa !5
  %46 = zext i8 %45 to i32
  %47 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %43, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %46) #3
  %48 = getelementptr inbounds i8, ptr %0, i64 16
  %49 = getelementptr inbounds i8, ptr %5, i64 8
  %50 = load i8, ptr %49, align 8, !tbaa !5
  %51 = zext i8 %50 to i32
  %52 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %48, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %51) #3
  %53 = getelementptr inbounds i8, ptr %0, i64 18
  %54 = getelementptr inbounds i8, ptr %5, i64 9
  %55 = load i8, ptr %54, align 1, !tbaa !5
  %56 = zext i8 %55 to i32
  %57 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %53, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %56) #3
  %58 = getelementptr inbounds i8, ptr %0, i64 20
  %59 = getelementptr inbounds i8, ptr %5, i64 10
  %60 = load i8, ptr %59, align 2, !tbaa !5
  %61 = zext i8 %60 to i32
  %62 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %58, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %61) #3
  %63 = getelementptr inbounds i8, ptr %0, i64 22
  %64 = getelementptr inbounds i8, ptr %5, i64 11
  %65 = load i8, ptr %64, align 1, !tbaa !5
  %66 = zext i8 %65 to i32
  %67 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %63, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %66) #3
  %68 = getelementptr inbounds i8, ptr %0, i64 24
  %69 = getelementptr inbounds i8, ptr %5, i64 12
  %70 = load i8, ptr %69, align 4, !tbaa !5
  %71 = zext i8 %70 to i32
  %72 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %68, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %71) #3
  %73 = getelementptr inbounds i8, ptr %0, i64 26
  %74 = getelementptr inbounds i8, ptr %5, i64 13
  %75 = load i8, ptr %74, align 1, !tbaa !5
  %76 = zext i8 %75 to i32
  %77 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %73, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %76) #3
  %78 = getelementptr inbounds i8, ptr %0, i64 28
  %79 = getelementptr inbounds i8, ptr %5, i64 14
  %80 = load i8, ptr %79, align 2, !tbaa !5
  %81 = zext i8 %80 to i32
  %82 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %78, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %81) #3
  %83 = getelementptr inbounds i8, ptr %0, i64 30
  %84 = getelementptr inbounds i8, ptr %5, i64 15
  %85 = load i8, ptr %84, align 1, !tbaa !5
  %86 = zext i8 %85 to i32
  %87 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %83, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %86) #3
  %88 = getelementptr inbounds i8, ptr %0, i64 32
  %89 = getelementptr inbounds i8, ptr %5, i64 16
  %90 = load i8, ptr %89, align 16, !tbaa !5
  %91 = zext i8 %90 to i32
  %92 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %88, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %91) #3
  %93 = getelementptr inbounds i8, ptr %0, i64 34
  %94 = getelementptr inbounds i8, ptr %5, i64 17
  %95 = load i8, ptr %94, align 1, !tbaa !5
  %96 = zext i8 %95 to i32
  %97 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %93, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %96) #3
  %98 = getelementptr inbounds i8, ptr %0, i64 36
  %99 = getelementptr inbounds i8, ptr %5, i64 18
  %100 = load i8, ptr %99, align 2, !tbaa !5
  %101 = zext i8 %100 to i32
  %102 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %98, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %101) #3
  %103 = getelementptr inbounds i8, ptr %0, i64 38
  %104 = getelementptr inbounds i8, ptr %5, i64 19
  %105 = load i8, ptr %104, align 1, !tbaa !5
  %106 = zext i8 %105 to i32
  %107 = call i64 (ptr, i64, ptr, ...) @xstrncpyf(ptr noundef nonnull %103, i64 noundef 3, ptr noundef nonnull @.str.2, i32 noundef %106) #3
  %108 = getelementptr inbounds i8, ptr %0, i64 40
  store i8 0, ptr %108, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %5) #3
  br label %109

109:                                              ; preds = %4, %8
  %.012 = phi i32 [ 1, %8 ], [ -2, %4 ]
  ret i32 %.012
}

declare i64 @xstrncpyf(ptr noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync 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" }
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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass