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

; 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._TCP4_HEARTBEAT_TIMER = type { ptr, i64 }
%struct.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }

@mTcp4Timer = external dso_local global %struct._TCP4_HEARTBEAT_TIMER, align 8
@gBS = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @Tcp4CreateTimer() #0 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  store i64 0, ptr %1, align 8, !tbaa !5
  %2 = load i64, ptr getelementptr inbounds (%struct._TCP4_HEARTBEAT_TIMER, ptr @mTcp4Timer, i32 0, i32 1), align 8, !tbaa !9
  %3 = icmp eq i64 %2, 0
  br i1 %3, label %4, label %18

4:                                                ; preds = %0
  %5 = load ptr, ptr @gBS, align 8, !tbaa !12
  %6 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %5, i32 0, i32 8
  %7 = load ptr, ptr %6, align 8, !tbaa !13
  %8 = call i64 %7(i32 noundef -2147483136, i64 noundef 16, ptr noundef @TcpTicking, ptr noundef null, ptr noundef @mTcp4Timer)
  store i64 %8, ptr %1, align 8, !tbaa !5
  %9 = load i64, ptr %1, align 8, !tbaa !5
  %10 = icmp slt i64 %9, 0
  br i1 %10, label %17, label %11

11:                                               ; preds = %4
  %12 = load ptr, ptr @gBS, align 8, !tbaa !12
  %13 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %12, i32 0, i32 9
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = load ptr, ptr @mTcp4Timer, align 8, !tbaa !18
  %16 = call i64 %14(ptr noundef %15, i32 noundef 1, i64 noundef 2000000)
  store i64 %16, ptr %1, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %11, %4
  br label %18

18:                                               ; preds = %17, %0
  %19 = load i64, ptr %1, align 8, !tbaa !5
  %20 = icmp slt i64 %19, 0
  br i1 %20, label %24, label %21

21:                                               ; preds = %18
  %22 = load i64, ptr getelementptr inbounds (%struct._TCP4_HEARTBEAT_TIMER, ptr @mTcp4Timer, i32 0, i32 1), align 8, !tbaa !9
  %23 = add nsw i64 %22, 1
  store i64 %23, ptr getelementptr inbounds (%struct._TCP4_HEARTBEAT_TIMER, ptr @mTcp4Timer, i32 0, i32 1), align 8, !tbaa !9
  br label %24

24:                                               ; preds = %21, %18
  %25 = load i64, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret i64 %25
}

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

declare void @TcpTicking(ptr noundef, ptr noundef) #2

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_TCP4_HEARTBEAT_TIMER", !11, i64 0, !6, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 80}
!14 = !{!"", !15, i64 0, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152, !11, i64 160, !11, i64 168, !11, i64 176, !11, i64 184, !11, i64 192, !11, i64 200, !11, i64 208, !11, i64 216, !11, i64 224, !11, i64 232, !11, i64 240, !11, i64 248, !11, i64 256, !11, i64 264, !11, i64 272, !11, i64 280, !11, i64 288, !11, i64 296, !11, i64 304, !11, i64 312, !11, i64 320, !11, i64 328, !11, i64 336, !11, i64 344, !11, i64 352, !11, i64 360, !11, i64 368}
!15 = !{!"", !6, i64 0, !16, i64 8, !16, i64 12, !16, i64 16, !16, i64 20}
!16 = !{!"int", !7, i64 0}
!17 = !{!14, !11, i64 88}
!18 = !{!10, !11, 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._TCP4_HEARTBEAT_TIMER = type { ptr, i64 }

@mTcp4Timer = external dso_local global %struct._TCP4_HEARTBEAT_TIMER, align 8
@gBS = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @Tcp4CreateTimer() local_unnamed_addr #0 {
  %1 = load i64, ptr getelementptr inbounds (i8, ptr @mTcp4Timer, i64 8), align 8, !tbaa !5
  %2 = icmp eq i64 %1, 0
  br i1 %2, label %3, label %.thread6

3:                                                ; preds = %0
  %4 = load ptr, ptr @gBS, align 8, !tbaa !11
  %5 = getelementptr inbounds i8, ptr %4, i64 80
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = tail call i64 %6(i32 noundef -2147483136, i64 noundef 16, ptr noundef nonnull @TcpTicking, ptr noundef null, ptr noundef nonnull @mTcp4Timer) #2
  %8 = icmp slt i64 %7, 0
  br i1 %8, label %.thread, label %9

9:                                                ; preds = %3
  %10 = load ptr, ptr @gBS, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %10, i64 88
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  %13 = load ptr, ptr @mTcp4Timer, align 8, !tbaa !17
  %14 = tail call i64 %12(ptr noundef %13, i32 noundef 1, i64 noundef 2000000) #2
  %15 = icmp slt i64 %14, 0
  br i1 %15, label %.thread, label %..thread6_crit_edge

..thread6_crit_edge:                              ; preds = %9
  %.pre = load i64, ptr getelementptr inbounds (i8, ptr @mTcp4Timer, i64 8), align 8, !tbaa !5
  br label %.thread6

.thread6:                                         ; preds = %..thread6_crit_edge, %0
  %16 = phi i64 [ %.pre, %..thread6_crit_edge ], [ %1, %0 ]
  %.08 = phi i64 [ %14, %..thread6_crit_edge ], [ 0, %0 ]
  %17 = add nsw i64 %16, 1
  store i64 %17, ptr getelementptr inbounds (i8, ptr @mTcp4Timer, i64 8), align 8, !tbaa !5
  br label %.thread

.thread:                                          ; preds = %3, %.thread6, %9
  %.05 = phi i64 [ %.08, %.thread6 ], [ %14, %9 ], [ %7, %3 ]
  ret i64 %.05
}

declare void @TcpTicking(ptr noundef, ptr noundef) #1

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

!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, !10, i64 8}
!6 = !{!"_TCP4_HEARTBEAT_TIMER", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 80}
!13 = !{!"", !14, i64 0, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !7, i64 160, !7, i64 168, !7, i64 176, !7, i64 184, !7, i64 192, !7, i64 200, !7, i64 208, !7, i64 216, !7, i64 224, !7, i64 232, !7, i64 240, !7, i64 248, !7, i64 256, !7, i64 264, !7, i64 272, !7, i64 280, !7, i64 288, !7, i64 296, !7, i64 304, !7, i64 312, !7, i64 320, !7, i64 328, !7, i64 336, !7, i64 344, !7, i64 352, !7, i64 360, !7, i64 368}
!14 = !{!"", !10, i64 0, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20}
!15 = !{!"int", !8, i64 0}
!16 = !{!13, !7, i64 88}
!17 = !{!6, !7, i64 0}


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