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

; 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.EFI_EDITOR_FILE_BUFFER = type { ptr, i32, ptr, ptr, i64, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, i8, i8, i8, ptr }
%struct.EFI_EDITOR_POSITION = type { i64, i64 }
%struct._EFI_EDITOR_LINE = type { i64, ptr, i64, i64, i32, %struct._LIST_ENTRY }
%struct._LIST_ENTRY = type { ptr, ptr }

@FileBuffer = external dso_local global %struct.EFI_EDITOR_FILE_BUFFER, align 8
@.str.1 = external hidden unnamed_addr constant [163 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [2 x i32], align 4

declare ptr @AllocateZeroPool(i64 noundef) #0

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

declare zeroext i8 @DebugAssertEnabled() #0

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @FileBufferCreateLine() #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 56)
  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 %70

8:                                                ; preds = %0
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._EFI_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._EFI_EDITOR_LINE, ptr %11, i32 0, i32 2
  store i64 0, ptr %12, align 8, !tbaa !14
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %13, i32 0, i32 3
  store i64 0, ptr %14, align 8, !tbaa !15
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %15, i32 0, i32 4
  store i32 0, ptr %16, align 8, !tbaa !16
  br label %17

17:                                               ; preds = %8
  %18 = call zeroext i8 @DebugAssertEnabled()
  %19 = icmp ne i8 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  br label %21

21:                                               ; preds = %20, %17
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %24 = call ptr (ptr, ptr, ...) @CatSPrint(ptr noundef null, ptr noundef @.str.10)
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %25, i32 0, i32 1
  store ptr %24, ptr %26, align 8, !tbaa !17
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !17
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %23
  store ptr null, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %70

32:                                               ; preds = %23
  %33 = load i64, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 4), align 8, !tbaa !18
  %34 = add i64 %33, 1
  store i64 %34, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 4), align 8, !tbaa !18
  %35 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !21
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %36, i32 0, i32 5
  %38 = call ptr @InsertTailList(ptr noundef %35, ptr noundef %37)
  %39 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 3), align 8, !tbaa !22
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %68

41:                                               ; preds = %32
  %42 = call zeroext i8 @DebugAssertEnabled()
  %43 = zext i8 %42 to i32
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %59

45:                                               ; preds = %41
  %46 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !21
  %47 = getelementptr inbounds %struct._LIST_ENTRY, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !23
  %49 = ptrtoint ptr %48 to i64
  %50 = sub i64 %49, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %51 = inttoptr i64 %50 to ptr
  %52 = getelementptr inbounds %struct._EFI_EDITOR_LINE, ptr %51, i32 0, i32 0
  %53 = load i64, ptr %52, align 8, !tbaa !9
  %54 = icmp ne i64 %53, 1819043173
  br i1 %54, label %55, label %59

55:                                               ; preds = %45
  call void @DebugAssert(ptr noundef @.str.1, i64 noundef 714, ptr noundef @.str.2)
  %56 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !21
  %57 = getelementptr inbounds %struct._LIST_ENTRY, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !23
  br label %66

59:                                               ; preds = %45, %41
  %60 = load ptr, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 2), align 8, !tbaa !21
  %61 = getelementptr inbounds %struct._LIST_ENTRY, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !23
  %63 = ptrtoint ptr %62 to i64
  %64 = sub i64 %63, ptrtoint (ptr getelementptr inbounds (%struct._EFI_EDITOR_LINE, ptr null, i32 0, i32 5) to i64)
  %65 = inttoptr i64 %64 to ptr
  br label %66

66:                                               ; preds = %59, %55
  %67 = phi ptr [ %58, %55 ], [ %65, %59 ]
  store ptr %67, ptr getelementptr inbounds (%struct.EFI_EDITOR_FILE_BUFFER, ptr @FileBuffer, i32 0, i32 3), align 8, !tbaa !22
  br label %68

68:                                               ; preds = %66, %32
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %69, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %70

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

declare ptr @CatSPrint(ptr noundef, ptr noundef, ...) #0

declare ptr @InsertTailList(ptr noundef, ptr noundef) #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 = { nocallback nofree nosync 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 = !{!10, !11, i64 0}
!10 = !{!"_EFI_EDITOR_LINE", !11, i64 0, !6, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !13, i64 40}
!11 = !{!"long long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!14 = !{!10, !11, i64 16}
!15 = !{!10, !11, i64 24}
!16 = !{!10, !12, i64 32}
!17 = !{!10, !6, i64 8}
!18 = !{!19, !11, i64 32}
!19 = !{!"", !6, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !20, i64 40, !20, i64 56, !20, i64 72, !20, i64 88, !7, i64 104, !7, i64 105, !7, i64 106, !6, i64 112}
!20 = !{!"", !11, i64 0, !11, i64 8}
!21 = !{!19, !6, i64 16}
!22 = !{!19, !6, i64 24}
!23 = !{!13, !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.EFI_EDITOR_FILE_BUFFER = type { ptr, i32, ptr, ptr, i64, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, %struct.EFI_EDITOR_POSITION, i8, i8, i8, ptr }
%struct.EFI_EDITOR_POSITION = type { i64, i64 }

@FileBuffer = external dso_local local_unnamed_addr global %struct.EFI_EDITOR_FILE_BUFFER, align 8
@.str.1 = external hidden unnamed_addr constant [163 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [2 x i32], align 4

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 @FileBufferCreateLine() local_unnamed_addr #1 {
  %1 = tail call ptr @AllocateZeroPool(i64 noundef 56) #3
  %2 = icmp eq ptr %1, null
  br i1 %2, label %25, label %3

3:                                                ; preds = %0
  store i64 1819043173, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %4, i8 0, i64 20, i1 false)
  %5 = tail call zeroext i8 @DebugAssertEnabled() #3
  %6 = tail call ptr (ptr, ptr, ...) @CatSPrint(ptr noundef null, ptr noundef nonnull @.str.10) #3
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %6, ptr %7, align 8, !tbaa !13
  %8 = icmp eq ptr %6, null
  br i1 %8, label %25, label %9

9:                                                ; preds = %3
  %10 = load i64, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 32), align 8, !tbaa !14
  %11 = add i64 %10, 1
  store i64 %11, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 32), align 8, !tbaa !14
  %12 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 16), align 8, !tbaa !17
  %13 = getelementptr inbounds i8, ptr %1, i64 40
  %14 = tail call ptr @InsertTailList(ptr noundef %12, ptr noundef nonnull %13) #3
  %15 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 24), align 8, !tbaa !18
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %25

17:                                               ; preds = %9
  %18 = tail call zeroext i8 @DebugAssertEnabled() #3
  %.not = icmp eq i8 %18, 0
  %.pre = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 16), align 8, !tbaa !17
  %.pre12 = load ptr, ptr %.pre, align 8, !tbaa !19
  %.pre13 = ptrtoint ptr %.pre12 to i64
  %.pre14 = add i64 %.pre13, -40
  %.pre16 = inttoptr i64 %.pre14 to ptr
  br i1 %.not, label %._crit_edge, label %19

19:                                               ; preds = %17
  %20 = load i64, ptr %.pre16, align 8, !tbaa !5
  %.not11 = icmp eq i64 %20, 1819043173
  br i1 %.not11, label %._crit_edge, label %21

21:                                               ; preds = %19
  tail call void @DebugAssert(ptr noundef nonnull @.str.1, i64 noundef 714, ptr noundef nonnull @.str.2) #3
  %22 = load ptr, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 16), align 8, !tbaa !17
  %23 = load ptr, ptr %22, align 8, !tbaa !19
  br label %._crit_edge

._crit_edge:                                      ; preds = %17, %19, %21
  %24 = phi ptr [ %23, %21 ], [ %.pre16, %19 ], [ %.pre16, %17 ]
  store ptr %24, ptr getelementptr inbounds (i8, ptr @FileBuffer, i64 24), align 8, !tbaa !18
  br label %25

25:                                               ; preds = %9, %._crit_edge, %3, %0
  %.0 = phi ptr [ null, %0 ], [ null, %3 ], [ %1, %._crit_edge ], [ %1, %9 ]
  ret ptr %.0
}

declare ptr @CatSPrint(ptr noundef, ptr noundef, ...) local_unnamed_addr #0

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"_EFI_EDITOR_LINE", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !12, i64 40}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!13 = !{!6, !10, i64 8}
!14 = !{!15, !7, i64 32}
!15 = !{!"", !10, i64 0, !11, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !16, i64 40, !16, i64 56, !16, i64 72, !16, i64 88, !8, i64 104, !8, i64 105, !8, i64 106, !10, i64 112}
!16 = !{!"", !7, i64 0, !7, i64 8}
!17 = !{!15, !10, i64 16}
!18 = !{!15, !10, i64 24}
!19 = !{!12, !10, i64 0}


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