; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (IScsiUpdateCmdSN)

; 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._ISCSI_SESSION = type { i32, %struct._ISCSI_SESSION_CONFIG_DATA, %struct._ISCSI_CHAP_AUTH_DATA, [224 x i8], i64, i8, [6 x i8], i16, i32, i32, i32, i32, i16, %struct._LIST_ENTRY, i32, %struct._LIST_ENTRY, i16, i32, i8, i8, i32, i32, i32, i32, i16, i8, i8, i8 }
%struct._ISCSI_SESSION_CONFIG_DATA = type { %struct.ISCSI_SESSION_CONFIG_NVDATA, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS }
%struct.ISCSI_SESSION_CONFIG_NVDATA = type <{ i8, i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i8, [224 x i8], %struct.EFI_IPv4_ADDRESS, i16, [8 x i8], [6 x i8] }>
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct._ISCSI_CHAP_AUTH_DATA = type { %struct._ISCSI_CHAP_AUTH_CONFIG_NVDATA, i32, [1024 x i8], i32, [16 x i8], i32, [1024 x i8], i32 }
%struct._ISCSI_CHAP_AUTH_CONFIG_NVDATA = type { i8, [127 x i8], [17 x i8], [127 x i8], [17 x i8] }
%struct._LIST_ENTRY = type { ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @IScsiUpdateCmdSN(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %7 = load i32, ptr %5, align 4, !tbaa !9
  %8 = load i32, ptr %6, align 4, !tbaa !9
  %9 = sub i32 %8, 1
  %10 = icmp slt i32 %7, %9
  br i1 %10, label %11, label %17

11:                                               ; preds = %3
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = sub i32 %12, 1
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = sub i32 %13, %14
  %16 = icmp ult i32 %15, -2147483648
  br i1 %16, label %28, label %17

17:                                               ; preds = %11, %3
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = sub i32 %19, 1
  %21 = icmp sgt i32 %18, %20
  br i1 %21, label %22, label %29

22:                                               ; preds = %17
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = sub i32 %23, %24
  %26 = sub i32 %25, 1
  %27 = icmp ugt i32 %26, -2147483648
  br i1 %27, label %28, label %29

28:                                               ; preds = %22, %11
  br label %89

29:                                               ; preds = %22, %17
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %31, i32 0, i32 10
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = icmp slt i32 %30, %33
  br i1 %34, label %35, label %42

35:                                               ; preds = %29
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %36, i32 0, i32 10
  %38 = load i32, ptr %37, align 4, !tbaa !11
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = sub i32 %38, %39
  %41 = icmp ugt i32 %40, -2147483648
  br i1 %41, label %55, label %42

42:                                               ; preds = %35, %29
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %44, i32 0, i32 10
  %46 = load i32, ptr %45, align 4, !tbaa !11
  %47 = icmp sgt i32 %43, %46
  br i1 %47, label %48, label %59

48:                                               ; preds = %42
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %50, i32 0, i32 10
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = sub i32 %49, %52
  %54 = icmp ult i32 %53, -2147483648
  br i1 %54, label %55, label %59

55:                                               ; preds = %48, %35
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %57, i32 0, i32 10
  store i32 %56, ptr %58, align 4, !tbaa !11
  br label %59

59:                                               ; preds = %55, %48, %42
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %61, i32 0, i32 9
  %63 = load i32, ptr %62, align 8, !tbaa !21
  %64 = icmp slt i32 %60, %63
  br i1 %64, label %65, label %72

65:                                               ; preds = %59
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %66, i32 0, i32 9
  %68 = load i32, ptr %67, align 8, !tbaa !21
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = sub i32 %68, %69
  %71 = icmp ugt i32 %70, -2147483648
  br i1 %71, label %85, label %72

72:                                               ; preds = %65, %59
  %73 = load i32, ptr %6, align 4, !tbaa !9
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %74, i32 0, i32 9
  %76 = load i32, ptr %75, align 8, !tbaa !21
  %77 = icmp sgt i32 %73, %76
  br i1 %77, label %78, label %89

78:                                               ; preds = %72
  %79 = load i32, ptr %6, align 4, !tbaa !9
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %80, i32 0, i32 9
  %82 = load i32, ptr %81, align 8, !tbaa !21
  %83 = sub i32 %79, %82
  %84 = icmp ult i32 %83, -2147483648
  br i1 %84, label %85, label %89

85:                                               ; preds = %78, %65
  %86 = load i32, ptr %6, align 4, !tbaa !9
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct._ISCSI_SESSION, ptr %87, i32 0, i32 9
  store i32 %86, ptr %88, align 8, !tbaa !21
  br label %89

89:                                               ; preds = %85, %78, %72, %28
  ret void
}

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

!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, !10, i64 2900}
!12 = !{!"_ISCSI_SESSION", !10, i64 0, !13, i64 4, !17, i64 276, !7, i64 2648, !19, i64 2872, !7, i64 2880, !7, i64 2881, !16, i64 2888, !10, i64 2892, !10, i64 2896, !10, i64 2900, !10, i64 2904, !16, i64 2908, !20, i64 2912, !10, i64 2928, !20, i64 2936, !16, i64 2952, !10, i64 2956, !7, i64 2960, !7, i64 2961, !10, i64 2964, !10, i64 2968, !10, i64 2972, !10, i64 2976, !16, i64 2980, !7, i64 2982, !7, i64 2983, !7, i64 2984}
!13 = !{!"_ISCSI_SESSION_CONFIG_DATA", !14, i64 0, !15, i64 259, !15, i64 263, !15, i64 267}
!14 = !{!"", !7, i64 0, !7, i64 1, !15, i64 2, !15, i64 6, !15, i64 10, !7, i64 14, !7, i64 15, !15, i64 239, !16, i64 243, !7, i64 245, !7, i64 253}
!15 = !{!"", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!"_ISCSI_CHAP_AUTH_DATA", !18, i64 0, !10, i64 292, !7, i64 296, !10, i64 1320, !7, i64 1324, !10, i64 1340, !7, i64 1344, !10, i64 2368}
!18 = !{!"_ISCSI_CHAP_AUTH_CONFIG_NVDATA", !7, i64 0, !7, i64 1, !7, i64 128, !7, i64 145, !7, i64 272}
!19 = !{!"long long", !7, i64 0}
!20 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!21 = !{!12, !10, i64 2896}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @IScsiUpdateCmdSN(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = add i32 %2, -1
  %5 = icmp sgt i32 %4, %1
  %6 = sub i32 %4, %1
  %7 = icmp sgt i32 %6, -1
  %or.cond = and i1 %5, %7
  br i1 %or.cond, label %34, label %8

8:                                                ; preds = %3
  %9 = icmp slt i32 %4, %1
  %10 = sub i32 %2, %1
  %11 = icmp ult i32 %10, 2147483647
  %or.cond36 = and i1 %9, %11
  br i1 %or.cond36, label %34, label %12

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 2900
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp sgt i32 %14, %1
  %16 = sub i32 %14, %1
  %17 = icmp ugt i32 %16, -2147483648
  %or.cond38 = and i1 %15, %17
  br i1 %or.cond38, label %22, label %18

18:                                               ; preds = %12
  %19 = icmp slt i32 %14, %1
  %20 = sub i32 %1, %14
  %21 = icmp sgt i32 %20, -1
  %or.cond40 = and i1 %19, %21
  br i1 %or.cond40, label %22, label %23

22:                                               ; preds = %18, %12
  store i32 %1, ptr %13, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %22, %18
  %24 = getelementptr inbounds i8, ptr %0, i64 2896
  %25 = load i32, ptr %24, align 8, !tbaa !19
  %26 = icmp sgt i32 %25, %2
  %27 = sub i32 %25, %2
  %28 = icmp ugt i32 %27, -2147483648
  %or.cond42 = and i1 %26, %28
  br i1 %or.cond42, label %33, label %29

29:                                               ; preds = %23
  %30 = icmp slt i32 %25, %2
  %31 = sub i32 %2, %25
  %32 = icmp sgt i32 %31, -1
  %or.cond44 = and i1 %30, %32
  br i1 %or.cond44, label %33, label %34

33:                                               ; preds = %29, %23
  store i32 %2, ptr %24, align 8, !tbaa !19
  br label %34

34:                                               ; preds = %8, %3, %33, %29
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !7, i64 2900}
!6 = !{!"_ISCSI_SESSION", !7, i64 0, !10, i64 4, !14, i64 276, !8, i64 2648, !16, i64 2872, !8, i64 2880, !8, i64 2881, !13, i64 2888, !7, i64 2892, !7, i64 2896, !7, i64 2900, !7, i64 2904, !13, i64 2908, !17, i64 2912, !7, i64 2928, !17, i64 2936, !13, i64 2952, !7, i64 2956, !8, i64 2960, !8, i64 2961, !7, i64 2964, !7, i64 2968, !7, i64 2972, !7, i64 2976, !13, i64 2980, !8, i64 2982, !8, i64 2983, !8, i64 2984}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_ISCSI_SESSION_CONFIG_DATA", !11, i64 0, !12, i64 259, !12, i64 263, !12, i64 267}
!11 = !{!"", !8, i64 0, !8, i64 1, !12, i64 2, !12, i64 6, !12, i64 10, !8, i64 14, !8, i64 15, !12, i64 239, !13, i64 243, !8, i64 245, !8, i64 253}
!12 = !{!"", !8, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = !{!"_ISCSI_CHAP_AUTH_DATA", !15, i64 0, !7, i64 292, !8, i64 296, !7, i64 1320, !8, i64 1324, !7, i64 1340, !8, i64 1344, !7, i64 2368}
!15 = !{!"_ISCSI_CHAP_AUTH_CONFIG_NVDATA", !8, i64 0, !8, i64 1, !8, i64 128, !8, i64 145, !8, i64 272}
!16 = !{!"long long", !8, i64 0}
!17 = !{!"_LIST_ENTRY", !18, i64 0, !18, i64 8}
!18 = !{!"any pointer", !8, i64 0}
!19 = !{!6, !7, i64 2896}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass