; LLVM IR from siconos/siconos :: mechanisms/src/TIMERMBTB/acetime.ll (ZN7aceTime4stopEv)

; 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.timeval = type { i64, i64 }
%class.aceTime = type <{ ptr, i64, %struct.timeval, i64, [128 x i8], i8, [7 x i8] }>

; Function Attrs: nounwind
declare i32 @gettimeofday(ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7aceTime4stopEv(ptr noundef nonnull align 8 dereferenceable(169) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.timeval, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %class.aceTime, ptr %4, i32 0, i32 5
  %6 = load i8, ptr %5, align 8, !tbaa !9, !range !14, !noundef !15
  %7 = trunc i8 %6 to i1
  br i1 %7, label %8, label %28

8:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #3
  %9 = call i32 @gettimeofday(ptr noundef %3, ptr noundef null) #3
  %10 = getelementptr inbounds %struct.timeval, ptr %3, i32 0, i32 0
  %11 = load i64, ptr %10, align 8, !tbaa !16
  %12 = getelementptr inbounds %class.aceTime, ptr %4, i32 0, i32 2
  %13 = getelementptr inbounds %struct.timeval, ptr %12, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !17
  %15 = sub nsw i64 %11, %14
  %16 = mul nsw i64 %15, 1000000
  %17 = getelementptr inbounds %struct.timeval, ptr %3, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !18
  %19 = getelementptr inbounds %class.aceTime, ptr %4, i32 0, i32 2
  %20 = getelementptr inbounds %struct.timeval, ptr %19, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !19
  %22 = sub nsw i64 %18, %21
  %23 = add nsw i64 %16, %22
  %24 = getelementptr inbounds %class.aceTime, ptr %4, i32 0, i32 3
  %25 = load i64, ptr %24, align 8, !tbaa !20
  %26 = add nsw i64 %25, %23
  store i64 %26, ptr %24, align 8, !tbaa !20
  %27 = getelementptr inbounds %class.aceTime, ptr %4, i32 0, i32 5
  store i8 0, ptr %27, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #3
  br label %28

28:                                               ; preds = %8, %1
  ret void
}

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

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

attributes #0 = { nounwind "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 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 nosync nounwind willreturn memory(argmem: readwrite) }
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, !13, i64 168}
!10 = !{!"_ZTS7aceTime", !11, i64 8, !12, i64 16, !11, i64 32, !7, i64 40, !13, i64 168}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_ZTS7timeval", !11, i64 0, !11, i64 8}
!13 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!12, !11, i64 0}
!17 = !{!10, !11, i64 16}
!18 = !{!12, !11, i64 8}
!19 = !{!10, !11, i64 24}
!20 = !{!10, !11, i64 32}


; 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.timeval = type { i64, i64 }

; Function Attrs: nofree nounwind
declare noundef i32 @gettimeofday(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_ZN7aceTime4stopEv(ptr nocapture noundef nonnull align 8 dereferenceable(169) %0) local_unnamed_addr #1 align 2 {
  %2 = alloca %struct.timeval, align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 168
  %4 = load i8, ptr %3, align 8, !tbaa !5, !range !12, !noundef !13
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %6, label %22

6:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  %7 = call i32 @gettimeofday(ptr noundef nonnull %2, ptr noundef null) #3
  %8 = load i64, ptr %2, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load i64, ptr %9, align 8, !tbaa !15
  %11 = sub nsw i64 %8, %10
  %12 = mul nsw i64 %11, 1000000
  %13 = getelementptr inbounds i8, ptr %2, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load i64, ptr %15, align 8, !tbaa !17
  %17 = sub i64 %14, %16
  %18 = add nsw i64 %17, %12
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = load i64, ptr %19, align 8, !tbaa !18
  %21 = add nsw i64 %18, %20
  store i64 %21, ptr %19, align 8, !tbaa !18
  store i8 0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  br label %22

22:                                               ; preds = %6, %1
  ret void
}

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

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

attributes #0 = { nofree nounwind "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 nofree 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 168}
!6 = !{!"_ZTS7aceTime", !7, i64 8, !10, i64 16, !7, i64 32, !8, i64 40, !11, i64 168}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS7timeval", !7, i64 0, !7, i64 8}
!11 = !{!"bool", !8, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!10, !7, i64 0}
!15 = !{!6, !7, i64 16}
!16 = !{!10, !7, i64 8}
!17 = !{!6, !7, i64 24}
!18 = !{!6, !7, i64 32}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass