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

; 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.ENV_VAR_LIST = type { %struct._LIST_ENTRY, ptr, ptr, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [142 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.5 = 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 zeroext i8 @DebugAssertEnabled() #1

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

declare void @FreePool(ptr noundef) #1

; 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
define dso_local void @FreeEnvironmentVariableList(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  br label %5

5:                                                ; preds = %1
  %6 = call zeroext i8 @DebugAssertEnabled()
  %7 = icmp ne i8 %6, 0
  br i1 %7, label %8, label %13

8:                                                ; preds = %5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @DebugAssert(ptr noundef @.str, i64 noundef 94, ptr noundef @.str.4)
  br label %12

12:                                               ; preds = %11, %8
  br label %13

13:                                               ; preds = %12, %5
  br label %14

14:                                               ; preds = %13
  br label %15

15:                                               ; preds = %14
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  store i32 1, ptr %4, align 4
  br label %65

19:                                               ; preds = %15
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = call ptr @GetFirstNode(ptr noundef %20)
  store ptr %21, ptr %3, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %61, %19
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = call zeroext i8 @IsListEmpty(ptr noundef %23)
  %25 = icmp ne i8 %24, 0
  %26 = xor i1 %25, true
  br i1 %26, label %27, label %64

27:                                               ; preds = %22
  br label %28

28:                                               ; preds = %27
  %29 = call zeroext i8 @DebugAssertEnabled()
  %30 = icmp ne i8 %29, 0
  br i1 %30, label %31, label %36

31:                                               ; preds = %28
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %35, label %34

34:                                               ; preds = %31
  call void @DebugAssert(ptr noundef @.str, i64 noundef 103, ptr noundef @.str.5)
  br label %35

35:                                               ; preds = %34, %31
  br label %36

36:                                               ; preds = %35, %28
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ENV_VAR_LIST, ptr %39, i32 0, i32 0
  %41 = call ptr @RemoveEntryList(ptr noundef %40)
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ENV_VAR_LIST, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %50

46:                                               ; preds = %38
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ENV_VAR_LIST, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  call void @FreePool(ptr noundef %49)
  br label %50

50:                                               ; preds = %46, %38
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ENV_VAR_LIST, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %59

55:                                               ; preds = %50
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ENV_VAR_LIST, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  call void @FreePool(ptr noundef %58)
  br label %59

59:                                               ; preds = %55, %50
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  call void @FreePool(ptr noundef %60)
  br label %61

61:                                               ; preds = %59
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = call ptr @GetFirstNode(ptr noundef %62)
  store ptr %63, ptr %3, align 8, !tbaa !5
  br label %22, !llvm.loop !14

64:                                               ; preds = %22
  store i32 0, ptr %4, align 4
  br label %65

65:                                               ; preds = %64, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %66 = load i32, ptr %4, align 4
  switch i32 %66, label %68 [
    i32 0, label %67
    i32 1, label %67
  ]

67:                                               ; preds = %65, %65
  ret void

68:                                               ; preds = %65
  unreachable
}

declare ptr @GetFirstNode(ptr noundef) #1

declare zeroext i8 @IsListEmpty(ptr noundef) #1

declare ptr @RemoveEntryList(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, !6, i64 16}
!10 = !{!"", !11, i64 0, !6, i64 16, !6, i64 24, !12, i64 32}
!11 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 24}
!14 = distinct !{!14, !15}
!15 = !{!"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 = external hidden unnamed_addr constant [142 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

declare void @FreePool(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @FreeEnvironmentVariableList(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call zeroext i8 @DebugAssertEnabled() #2
  %3 = icmp eq i8 %2, 0
  %4 = icmp ne ptr %0, null
  %or.cond = or i1 %4, %3
  br i1 %or.cond, label %5, label %.thread

.thread:                                          ; preds = %1
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 94, ptr noundef nonnull @.str.4) #2
  br label %.loopexit

5:                                                ; preds = %1
  %6 = icmp eq ptr %0, null
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %5
  %8 = tail call ptr @GetFirstNode(ptr noundef nonnull %0) #2
  %9 = tail call zeroext i8 @IsListEmpty(ptr noundef nonnull %0) #2
  %.not20 = icmp eq i8 %9, 0
  br i1 %.not20, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %7, %23
  %.021 = phi ptr [ %24, %23 ], [ %8, %7 ]
  %10 = tail call zeroext i8 @DebugAssertEnabled() #2
  %11 = icmp eq i8 %10, 0
  %12 = icmp ne ptr %.021, null
  %or.cond3 = select i1 %11, i1 true, i1 %12
  br i1 %or.cond3, label %14, label %13

13:                                               ; preds = %.lr.ph
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 103, ptr noundef nonnull @.str.5) #2
  br label %14

14:                                               ; preds = %13, %.lr.ph
  %15 = tail call ptr @RemoveEntryList(ptr noundef %.021) #2
  %16 = getelementptr inbounds i8, ptr %.021, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %.not18 = icmp eq ptr %17, null
  br i1 %.not18, label %19, label %18

18:                                               ; preds = %14
  tail call void @FreePool(ptr noundef nonnull %17) #2
  br label %19

19:                                               ; preds = %18, %14
  %20 = getelementptr inbounds i8, ptr %.021, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %.not19 = icmp eq ptr %21, null
  br i1 %.not19, label %23, label %22

22:                                               ; preds = %19
  tail call void @FreePool(ptr noundef nonnull %21) #2
  br label %23

23:                                               ; preds = %22, %19
  tail call void @FreePool(ptr noundef nonnull %.021) #2
  %24 = tail call ptr @GetFirstNode(ptr noundef nonnull %0) #2
  %25 = tail call zeroext i8 @IsListEmpty(ptr noundef nonnull %0) #2
  %.not = icmp eq i8 %25, 0
  br i1 %.not, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %23, %7, %.thread, %5
  ret void
}

declare ptr @GetFirstNode(ptr noundef) local_unnamed_addr #0

declare zeroext i8 @IsListEmpty(ptr noundef) local_unnamed_addr #0

declare ptr @RemoveEntryList(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, !8, i64 16}
!6 = !{!"", !7, i64 0, !8, i64 16, !8, i64 24, !11, i64 32}
!7 = !{!"_LIST_ENTRY", !8, i64 0, !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!6, !8, i64 24}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass