; LLVM IR from AngoraFuzzer/Angora :: llvm_mode/dfsan_rt/dfsan/dfsan_custom.ll_ (dfsw_poll)

; 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.pollfd = type { i32, i16, i16 }

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

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

declare void @dfsan_set_label(i32 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local i32 @__dfsw_poll(ptr noundef %0, i64 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, ptr noundef %6) #2 {
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !11
  store i32 %3, ptr %11, align 4, !tbaa !11
  store i32 %4, ptr %12, align 4, !tbaa !11
  store i32 %5, ptr %13, align 4, !tbaa !11
  store ptr %6, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = load i64, ptr %9, align 8, !tbaa !9
  %18 = load i32, ptr %10, align 4, !tbaa !11
  %19 = call i32 @poll(ptr noundef %16, i64 noundef %17, i32 noundef %18)
  store i32 %19, ptr %15, align 4, !tbaa !11
  %20 = load i32, ptr %15, align 4, !tbaa !11
  %21 = icmp sge i32 %20, 0
  br i1 %21, label %22, label %36

22:                                               ; preds = %7
  br label %23

23:                                               ; preds = %32, %22
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = icmp ugt i64 %24, 0
  br i1 %25, label %26, label %35

26:                                               ; preds = %23
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = sub i64 %28, 1
  %30 = getelementptr inbounds %struct.pollfd, ptr %27, i64 %29
  %31 = getelementptr inbounds %struct.pollfd, ptr %30, i32 0, i32 2
  call void @dfsan_set_label(i32 noundef 0, ptr noundef %31, i64 noundef 2)
  br label %32

32:                                               ; preds = %26
  %33 = load i64, ptr %9, align 8, !tbaa !9
  %34 = add i64 %33, -1
  store i64 %34, ptr %9, align 8, !tbaa !9
  br label %23, !llvm.loop !13

35:                                               ; preds = %23
  br label %36

36:                                               ; preds = %35, %7
  %37 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 0, ptr %37, align 4, !tbaa !11
  %38 = load i32, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  ret i32 %38
}

declare i32 @poll(ptr noundef, i64 noundef, i32 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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%struct.pollfd = type { i32, i16, i16 }

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

; Function Attrs: mustprogress uwtable
define dso_local i32 @__dfsw_poll(ptr noundef %0, i64 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, ptr nocapture noundef writeonly %6) local_unnamed_addr #1 {
  %8 = tail call i32 @poll(ptr noundef %0, i64 noundef %1, i32 noundef %2)
  %9 = icmp sgt i32 %8, -1
  %10 = icmp ne i64 %1, 0
  %or.cond = and i1 %10, %9
  br i1 %or.cond, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %7
  %invariant.gep = getelementptr i8, ptr %0, i64 -2
  br label %11

11:                                               ; preds = %.preheader, %11
  %.0 = phi i64 [ %12, %11 ], [ %1, %.preheader ]
  %gep = getelementptr %struct.pollfd, ptr %invariant.gep, i64 %.0
  tail call void @dfsan_set_label(i32 noundef 0, ptr noundef %gep, i64 noundef 2)
  %12 = add i64 %.0, -1
  %.old1.not = icmp eq i64 %12, 0
  br i1 %.old1.not, label %.loopexit, label %11

.loopexit:                                        ; preds = %11, %7
  store i32 0, ptr %6, align 4, !tbaa !5
  ret i32 %8
}

declare i32 @poll(ptr noundef, i64 noundef, i32 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 = { mustprogress 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass