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

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

@.str.2 = external hidden unnamed_addr constant [6 x i32], align 4
@.str.12 = external hidden unnamed_addr constant [9 x i32], align 4

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

declare i64 @StrnCmp(ptr noundef, ptr noundef, i64 noundef) #1

declare i64 @StrLen(ptr noundef) #1

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

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

declare ptr @AllocateCopyPool(i64 noundef, ptr noundef) #1

declare i64 @StrSize(ptr noundef) #1

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

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

15:                                               ; preds = %12, %2
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %63

16:                                               ; preds = %12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call i64 @StrLen(ptr noundef @.str.12)
  %19 = call i64 @StrnCmp(ptr noundef %17, ptr noundef @.str.12, i64 noundef %18)
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %63

22:                                               ; preds = %16
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = call ptr @StrStr(ptr noundef %23, ptr noundef @.str.2)
  store ptr %24, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %38

27:                                               ; preds = %22
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call i64 @StrSize(ptr noundef %28)
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = call ptr @AllocateCopyPool(i64 noundef %29, ptr noundef %30)
  store ptr %31, ptr %7, align 8, !tbaa !5
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %27
  store i64 -9223372036854775799, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %63

35:                                               ; preds = %27
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %36, ptr %37, align 8, !tbaa !5
  store i64 0, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %63

38:                                               ; preds = %22
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = ptrtoint ptr %39 to i64
  %42 = ptrtoint ptr %40 to i64
  %43 = sub i64 %41, %42
  %44 = sdiv exact i64 %43, 2
  store i64 %44, ptr %8, align 8, !tbaa !9
  %45 = load i64, ptr %8, align 8, !tbaa !9
  %46 = icmp eq i64 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %38
  store i64 -9223372036854775794, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %63

48:                                               ; preds = %38
  %49 = load i64, ptr %8, align 8, !tbaa !9
  %50 = mul i64 %49, 2
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = call ptr @AllocateCopyPool(i64 noundef %50, ptr noundef %51)
  store ptr %52, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = icmp eq ptr %53, null
  br i1 %54, label %55, label %56

55:                                               ; preds = %48
  store i64 -9223372036854775799, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %63

56:                                               ; preds = %48
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = load i64, ptr %8, align 8, !tbaa !9
  %59 = getelementptr inbounds i16, ptr %57, i64 %58
  %60 = getelementptr inbounds i16, ptr %59, i64 -1
  store i16 0, ptr %60, align 2, !tbaa !11
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %61, ptr %62, align 8, !tbaa !5
  store i64 0, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %63

63:                                               ; preds = %56, %55, %47, %35, %34, %21, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %64 = load i64, ptr %3, align 8
  ret i64 %64
}

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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !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"

@.str.2 = external hidden unnamed_addr constant [6 x i32], align 4
@.str.12 = external hidden unnamed_addr constant [9 x i32], align 4

declare i64 @StrnCmp(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

declare i64 @StrLen(ptr noundef) local_unnamed_addr #0

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

declare ptr @AllocateCopyPool(i64 noundef, ptr noundef) local_unnamed_addr #0

declare i64 @StrSize(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775806, 1) i64 @OutputConfigBody(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %27, label %5

5:                                                ; preds = %2
  %6 = tail call i64 @StrLen(ptr noundef nonnull @.str.12) #2
  %7 = tail call i64 @StrnCmp(ptr noundef nonnull %0, ptr noundef nonnull @.str.12, i64 noundef %6) #2
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %27, label %9

9:                                                ; preds = %5
  %10 = tail call ptr @StrStr(ptr noundef nonnull %0, ptr noundef nonnull @.str.2) #2
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %16

12:                                               ; preds = %9
  %13 = tail call i64 @StrSize(ptr noundef nonnull %0) #2
  %14 = tail call ptr @AllocateCopyPool(i64 noundef %13, ptr noundef nonnull %0) #2
  %15 = icmp eq ptr %14, null
  br i1 %15, label %27, label %.sink.split

16:                                               ; preds = %9
  %17 = ptrtoint ptr %10 to i64
  %18 = ptrtoint ptr %0 to i64
  %19 = sub i64 %17, %18
  %20 = icmp eq ptr %10, %0
  br i1 %20, label %27, label %21

21:                                               ; preds = %16
  %22 = tail call ptr @AllocateCopyPool(i64 noundef %19, ptr noundef nonnull %0) #2
  %23 = icmp eq ptr %22, null
  br i1 %23, label %27, label %24

24:                                               ; preds = %21
  %25 = getelementptr inbounds i8, ptr %22, i64 %19
  %26 = getelementptr inbounds i8, ptr %25, i64 -2
  store i16 0, ptr %26, align 2, !tbaa !5
  br label %.sink.split

.sink.split:                                      ; preds = %12, %24
  %.sink = phi ptr [ %22, %24 ], [ %14, %12 ]
  store ptr %.sink, ptr %1, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %.sink.split, %21, %16, %12, %5, %2
  %.0 = phi i64 [ -9223372036854775806, %2 ], [ -9223372036854775806, %5 ], [ -9223372036854775799, %12 ], [ -9223372036854775794, %16 ], [ -9223372036854775799, %21 ], [ 0, %.sink.split ]
  ret i64 %.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, !6, i64 0}
!6 = !{!"short", !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}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass