; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/IScsiDxe (IScsiCHAPCalculateResponse)

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

; Function Attrs: nounwind uwtable
define dso_local i64 @IScsiCHAPCalculateResponse(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, ptr noundef %5) #0 {
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca [1 x i8], align 1
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  store i32 %0, ptr %8, align 4, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %19 = load i32, ptr %10, align 4, !tbaa !5
  %20 = icmp ult i32 %19, 12
  br i1 %20, label %21, label %22

21:                                               ; preds = %6
  store i64 -9223372036854775784, ptr %7, align 8
  store i32 1, ptr %18, align 4
  br label %69

22:                                               ; preds = %6
  %23 = call i64 @Md5GetContextSize()
  store i64 %23, ptr %14, align 8, !tbaa !11
  %24 = load i64, ptr %14, align 8, !tbaa !11
  %25 = call ptr @AllocatePool(i64 noundef %24)
  store ptr %25, ptr %15, align 8, !tbaa !9
  %26 = load ptr, ptr %15, align 8, !tbaa !9
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %22
  store i64 -9223372036854775799, ptr %7, align 8
  store i32 1, ptr %18, align 4
  br label %69

29:                                               ; preds = %22
  store i64 -9223372036854775784, ptr %17, align 8, !tbaa !11
  %30 = load ptr, ptr %15, align 8, !tbaa !9
  %31 = call zeroext i8 @Md5Init(ptr noundef %30)
  %32 = icmp ne i8 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  br label %66

34:                                               ; preds = %29
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = trunc i32 %35 to i8
  %37 = getelementptr inbounds [1 x i8], ptr %16, i64 0, i64 0
  store i8 %36, ptr %37, align 1, !tbaa !13
  %38 = load ptr, ptr %15, align 8, !tbaa !9
  %39 = getelementptr inbounds [1 x i8], ptr %16, i64 0, i64 0
  %40 = call zeroext i8 @Md5Update(ptr noundef %38, ptr noundef %39, i64 noundef 1)
  %41 = icmp ne i8 %40, 0
  br i1 %41, label %43, label %42

42:                                               ; preds = %34
  br label %66

43:                                               ; preds = %34
  %44 = load ptr, ptr %15, align 8, !tbaa !9
  %45 = load ptr, ptr %9, align 8, !tbaa !9
  %46 = load i32, ptr %10, align 4, !tbaa !5
  %47 = zext i32 %46 to i64
  %48 = call zeroext i8 @Md5Update(ptr noundef %44, ptr noundef %45, i64 noundef %47)
  %49 = icmp ne i8 %48, 0
  br i1 %49, label %51, label %50

50:                                               ; preds = %43
  br label %66

51:                                               ; preds = %43
  %52 = load ptr, ptr %15, align 8, !tbaa !9
  %53 = load ptr, ptr %11, align 8, !tbaa !9
  %54 = load i32, ptr %12, align 4, !tbaa !5
  %55 = zext i32 %54 to i64
  %56 = call zeroext i8 @Md5Update(ptr noundef %52, ptr noundef %53, i64 noundef %55)
  %57 = icmp ne i8 %56, 0
  br i1 %57, label %59, label %58

58:                                               ; preds = %51
  br label %66

59:                                               ; preds = %51
  %60 = load ptr, ptr %15, align 8, !tbaa !9
  %61 = load ptr, ptr %13, align 8, !tbaa !9
  %62 = call zeroext i8 @Md5Final(ptr noundef %60, ptr noundef %61)
  %63 = icmp ne i8 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %59
  store i64 0, ptr %17, align 8, !tbaa !11
  br label %65

65:                                               ; preds = %64, %59
  br label %66

66:                                               ; preds = %65, %58, %50, %42, %33
  %67 = load ptr, ptr %15, align 8, !tbaa !9
  call void @FreePool(ptr noundef %67)
  %68 = load i64, ptr %17, align 8, !tbaa !11
  store i64 %68, ptr %7, align 8
  store i32 1, ptr %18, align 4
  br label %69

69:                                               ; preds = %66, %28, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %70 = load i64, ptr %7, align 8
  ret i64 %70
}

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

declare i64 @Md5GetContextSize() #2

declare ptr @AllocatePool(i64 noundef) #2

declare zeroext i8 @Md5Init(ptr noundef) #2

declare zeroext i8 @Md5Update(ptr noundef, ptr noundef, i64 noundef) #2

declare zeroext i8 @Md5Final(ptr noundef, ptr noundef) #2

declare void @FreePool(ptr noundef) #2

; 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 = { "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 = !{!"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, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!7, !7, i64 0}


; 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: nounwind uwtable
define dso_local range(i64 -9223372036854775799, 1) i64 @IScsiCHAPCalculateResponse(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = alloca [1 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %7) #3
  %8 = icmp ult i32 %2, 12
  br i1 %8, label %27, label %9

9:                                                ; preds = %6
  %10 = tail call i64 @Md5GetContextSize() #3
  %11 = tail call ptr @AllocatePool(i64 noundef %10) #3
  %12 = icmp eq ptr %11, null
  br i1 %12, label %27, label %13

13:                                               ; preds = %9
  %14 = tail call zeroext i8 @Md5Init(ptr noundef nonnull %11) #3
  %.not = icmp eq i8 %14, 0
  br i1 %.not, label %26, label %15

15:                                               ; preds = %13
  %16 = trunc i32 %0 to i8
  store i8 %16, ptr %7, align 1, !tbaa !5
  %17 = call zeroext i8 @Md5Update(ptr noundef nonnull %11, ptr noundef nonnull %7, i64 noundef 1) #3
  %.not19 = icmp eq i8 %17, 0
  br i1 %.not19, label %26, label %18

18:                                               ; preds = %15
  %19 = zext i32 %2 to i64
  %20 = call zeroext i8 @Md5Update(ptr noundef nonnull %11, ptr noundef %1, i64 noundef %19) #3
  %.not20 = icmp eq i8 %20, 0
  br i1 %.not20, label %26, label %21

21:                                               ; preds = %18
  %22 = zext i32 %4 to i64
  %23 = call zeroext i8 @Md5Update(ptr noundef nonnull %11, ptr noundef %3, i64 noundef %22) #3
  %.not21 = icmp eq i8 %23, 0
  br i1 %.not21, label %26, label %24

24:                                               ; preds = %21
  %25 = call zeroext i8 @Md5Final(ptr noundef nonnull %11, ptr noundef %5) #3
  %.not22 = icmp eq i8 %25, 0
  %spec.select = select i1 %.not22, i64 -9223372036854775784, i64 0
  br label %26

26:                                               ; preds = %24, %21, %18, %15, %13
  %.0 = phi i64 [ -9223372036854775784, %21 ], [ -9223372036854775784, %18 ], [ -9223372036854775784, %15 ], [ -9223372036854775784, %13 ], [ %spec.select, %24 ]
  call void @FreePool(ptr noundef nonnull %11) #3
  br label %27

27:                                               ; preds = %9, %6, %26
  %.016 = phi i64 [ %.0, %26 ], [ -9223372036854775784, %6 ], [ -9223372036854775799, %9 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %7) #3
  ret i64 %.016
}

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

declare i64 @Md5GetContextSize() local_unnamed_addr #2

declare ptr @AllocatePool(i64 noundef) local_unnamed_addr #2

declare zeroext i8 @Md5Init(ptr noundef) local_unnamed_addr #2

declare zeroext i8 @Md5Update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare zeroext i8 @Md5Final(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @FreePool(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 = { mustprogress 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 = { 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,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass