; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/ShellPkg/Library (HBufferImageCreateLine)

; 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.HEFI_EDITOR_BUFFER_IMAGE = type { ptr, ptr, i64, ptr, %struct.HEFI_EDITOR_POSITION, %struct.HEFI_EDITOR_POSITION, %struct.HEFI_EDITOR_POSITION, i64, i8, i8, i32, ptr, ptr, ptr }
%struct.HEFI_EDITOR_POSITION = type { i64, i64 }
%struct._HEFI_EDITOR_LINE = type { i64, [16 x i8], i64, %struct._LIST_ENTRY }
%struct._LIST_ENTRY = type { ptr, ptr }

@HBufferImage = external dso_local global %struct.HEFI_EDITOR_BUFFER_IMAGE, align 8
@.str.10 = external hidden unnamed_addr constant [167 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [21 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

declare ptr @AllocateZeroPool(i64 noundef) #1

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

declare zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @HBufferImageCreateLine() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %4 = call ptr @AllocateZeroPool(i64 noundef 48)
  store ptr %4, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %8

7:                                                ; preds = %0
  store ptr null, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %50

8:                                                ; preds = %0
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %9, i32 0, i32 0
  store i64 1819043173, ptr %10, align 8, !tbaa !9
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %11, i32 0, i32 2
  store i64 0, ptr %12, align 8, !tbaa !13
  %13 = load i64, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 2), align 8, !tbaa !14
  %14 = add i64 %13, 1
  store i64 %14, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 2), align 8, !tbaa !14
  %15 = load ptr, ptr @HBufferImage, align 8, !tbaa !18
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %16, i32 0, i32 3
  %18 = call ptr @InsertTailList(ptr noundef %15, ptr noundef %17)
  %19 = load ptr, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 1), align 8, !tbaa !19
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %48

21:                                               ; preds = %8
  %22 = call zeroext i8 @DebugAssertEnabled()
  %23 = zext i8 %22 to i32
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %39

25:                                               ; preds = %21
  %26 = load ptr, ptr @HBufferImage, align 8, !tbaa !18
  %27 = getelementptr inbounds %struct._LIST_ENTRY, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !20
  %29 = ptrtoint ptr %28 to i64
  %30 = sub i64 %29, ptrtoint (ptr getelementptr inbounds (%struct._HEFI_EDITOR_LINE, ptr null, i32 0, i32 3) to i64)
  %31 = inttoptr i64 %30 to ptr
  %32 = getelementptr inbounds %struct._HEFI_EDITOR_LINE, ptr %31, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = icmp ne i64 %33, 1819043173
  br i1 %34, label %35, label %39

35:                                               ; preds = %25
  call void @DebugAssert(ptr noundef @.str.10, i64 noundef 1071, ptr noundef @.str.11)
  %36 = load ptr, ptr @HBufferImage, align 8, !tbaa !18
  %37 = getelementptr inbounds %struct._LIST_ENTRY, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !20
  br label %46

39:                                               ; preds = %25, %21
  %40 = load ptr, ptr @HBufferImage, align 8, !tbaa !18
  %41 = getelementptr inbounds %struct._LIST_ENTRY, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !20
  %43 = ptrtoint ptr %42 to i64
  %44 = sub i64 %43, ptrtoint (ptr getelementptr inbounds (%struct._HEFI_EDITOR_LINE, ptr null, i32 0, i32 3) to i64)
  %45 = inttoptr i64 %44 to ptr
  br label %46

46:                                               ; preds = %39, %35
  %47 = phi ptr [ %38, %35 ], [ %45, %39 ]
  store ptr %47, ptr getelementptr inbounds (%struct.HEFI_EDITOR_BUFFER_IMAGE, ptr @HBufferImage, i32 0, i32 1), align 8, !tbaa !19
  br label %48

48:                                               ; preds = %46, %8
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %49, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %50

50:                                               ; preds = %48, %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %51 = load ptr, ptr %1, align 8
  ret ptr %51
}

declare ptr @InsertTailList(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!10, !11, i64 0}
!10 = !{!"_HEFI_EDITOR_LINE", !11, i64 0, !7, i64 8, !11, i64 24, !12, i64 32}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!10, !11, i64 24}
!14 = !{!15, !11, i64 16}
!15 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !16, i64 32, !16, i64 48, !16, i64 64, !11, i64 80, !7, i64 88, !7, i64 89, !17, i64 92, !6, i64 96, !6, i64 104, !6, i64 112}
!16 = !{!"", !11, i64 0, !11, i64 8}
!17 = !{!"int", !7, i64 0}
!18 = !{!15, !6, i64 0}
!19 = !{!15, !6, i64 8}
!20 = !{!12, !6, 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"

%struct.HEFI_EDITOR_BUFFER_IMAGE = type { ptr, ptr, i64, ptr, %struct.HEFI_EDITOR_POSITION, %struct.HEFI_EDITOR_POSITION, %struct.HEFI_EDITOR_POSITION, i64, i8, i8, i32, ptr, ptr, ptr }
%struct.HEFI_EDITOR_POSITION = type { i64, i64 }

@HBufferImage = external dso_local local_unnamed_addr global %struct.HEFI_EDITOR_BUFFER_IMAGE, align 8
@.str.10 = external hidden unnamed_addr constant [167 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [21 x i8], align 1

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #0

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @HBufferImageCreateLine() local_unnamed_addr #1 {
  %1 = tail call ptr @AllocateZeroPool(i64 noundef 48) #2
  %2 = icmp eq ptr %1, null
  br i1 %2, label %20, label %3

3:                                                ; preds = %0
  store i64 1819043173, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 24
  store i64 0, ptr %4, align 8, !tbaa !12
  %5 = load i64, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 16), align 8, !tbaa !13
  %6 = add i64 %5, 1
  store i64 %6, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 16), align 8, !tbaa !13
  %7 = load ptr, ptr @HBufferImage, align 8, !tbaa !17
  %8 = getelementptr inbounds i8, ptr %1, i64 32
  %9 = tail call ptr @InsertTailList(ptr noundef %7, ptr noundef nonnull %8) #2
  %10 = load ptr, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 8), align 8, !tbaa !18
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %20

12:                                               ; preds = %3
  %13 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %13, 0
  %.pre = load ptr, ptr @HBufferImage, align 8, !tbaa !17
  %.pre8 = load ptr, ptr %.pre, align 8, !tbaa !19
  %.pre9 = ptrtoint ptr %.pre8 to i64
  %.pre10 = add i64 %.pre9, -32
  %.pre12 = inttoptr i64 %.pre10 to ptr
  br i1 %.not, label %._crit_edge, label %14

14:                                               ; preds = %12
  %15 = load i64, ptr %.pre12, align 8, !tbaa !5
  %.not7 = icmp eq i64 %15, 1819043173
  br i1 %.not7, label %._crit_edge, label %16

16:                                               ; preds = %14
  tail call void @DebugAssert(ptr noundef nonnull @.str.10, i64 noundef 1071, ptr noundef nonnull @.str.11) #2
  %17 = load ptr, ptr @HBufferImage, align 8, !tbaa !17
  %18 = load ptr, ptr %17, align 8, !tbaa !19
  br label %._crit_edge

._crit_edge:                                      ; preds = %12, %14, %16
  %19 = phi ptr [ %18, %16 ], [ %.pre12, %14 ], [ %.pre12, %12 ]
  store ptr %19, ptr getelementptr inbounds (i8, ptr @HBufferImage, i64 8), align 8, !tbaa !18
  br label %20

20:                                               ; preds = %3, %._crit_edge, %0
  ret ptr %1
}

declare ptr @InsertTailList(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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, !7, i64 0}
!6 = !{!"_HEFI_EDITOR_LINE", !7, i64 0, !8, i64 8, !7, i64 24, !10, i64 32}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 24}
!13 = !{!14, !7, i64 16}
!14 = !{!"", !11, i64 0, !11, i64 8, !7, i64 16, !11, i64 24, !15, i64 32, !15, i64 48, !15, i64 64, !7, i64 80, !8, i64 88, !8, i64 89, !16, i64 92, !11, i64 96, !11, i64 104, !11, i64 112}
!15 = !{!"", !7, i64 0, !7, i64 8}
!16 = !{!"int", !8, i64 0}
!17 = !{!14, !11, i64 0}
!18 = !{!14, !11, i64 8}
!19 = !{!10, !11, i64 0}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass