; LLVM IR from fmela/libdict :: benchmark (timer_end)

; 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.rusage = type { %struct.timeval, %struct.timeval, %union.anon, %union.anon.0, %union.anon.1, %union.anon.2, %union.anon.3, %union.anon.4, %union.anon.5, %union.anon.6, %union.anon.7, %union.anon.8, %union.anon.9, %union.anon.10, %union.anon.11, %union.anon.12 }
%struct.timeval = type { i64, i64 }
%union.anon = type { i64 }
%union.anon.0 = type { i64 }
%union.anon.1 = type { i64 }
%union.anon.2 = type { i64 }
%union.anon.3 = type { i64 }
%union.anon.4 = type { i64 }
%union.anon.5 = type { i64 }
%union.anon.6 = type { i64 }
%union.anon.7 = type { i64 }
%union.anon.8 = type { i64 }
%union.anon.9 = type { i64 }
%union.anon.10 = type { i64 }
%union.anon.11 = type { i64 }
%union.anon.12 = type { i64 }

; Function Attrs: nounwind uwtable
define dso_local void @timer_end(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  %8 = call i32 @getrusage(i32 noundef 0, ptr noundef %7) #2
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.rusage, ptr %9, i32 0, i32 0
  %11 = getelementptr inbounds %struct.timeval, ptr %10, i32 0, i32 1
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.rusage, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.timeval, ptr %14, i32 0, i32 1
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %17 = icmp slt i64 %12, %16
  br i1 %17, label %18, label %29

18:                                               ; preds = %3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.rusage, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds %struct.timeval, ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = add nsw i64 %22, 1000000
  store i64 %23, ptr %21, align 8, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.rusage, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.timeval, ptr %25, i32 0, i32 0
  %27 = load i64, ptr %26, align 8, !tbaa !13
  %28 = add nsw i64 %27, -1
  store i64 %28, ptr %26, align 8, !tbaa !13
  br label %29

29:                                               ; preds = %18, %3
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.rusage, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.timeval, ptr %31, i32 0, i32 1
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.rusage, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds %struct.timeval, ptr %35, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = sub nsw i64 %37, %33
  store i64 %38, ptr %36, align 8, !tbaa !9
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.rusage, ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds %struct.timeval, ptr %40, i32 0, i32 0
  %42 = load i64, ptr %41, align 8, !tbaa !13
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.rusage, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds %struct.timeval, ptr %44, i32 0, i32 0
  %46 = load i64, ptr %45, align 8, !tbaa !13
  %47 = sub nsw i64 %46, %42
  store i64 %47, ptr %45, align 8, !tbaa !13
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.rusage, ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds %struct.timeval, ptr %49, i32 0, i32 0
  %51 = load i64, ptr %50, align 8, !tbaa !13
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.timeval, ptr %52, i32 0, i32 0
  %54 = load i64, ptr %53, align 8, !tbaa !14
  %55 = add nsw i64 %54, %51
  store i64 %55, ptr %53, align 8, !tbaa !14
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.rusage, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds %struct.timeval, ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !9
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.timeval, ptr %60, i32 0, i32 1
  %62 = load i64, ptr %61, align 8, !tbaa !15
  %63 = add nsw i64 %62, %59
  store i64 %63, ptr %61, align 8, !tbaa !15
  %64 = icmp sgt i64 %63, 1000000
  br i1 %64, label %65, label %74

65:                                               ; preds = %29
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.timeval, ptr %66, i32 0, i32 1
  %68 = load i64, ptr %67, align 8, !tbaa !15
  %69 = sub nsw i64 %68, 1000000
  store i64 %69, ptr %67, align 8, !tbaa !15
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.timeval, ptr %70, i32 0, i32 0
  %72 = load i64, ptr %71, align 8, !tbaa !14
  %73 = add nsw i64 %72, 1
  store i64 %73, ptr %71, align 8, !tbaa !14
  br label %74

74:                                               ; preds = %65, %29
  ret void
}

; Function Attrs: nounwind
declare i32 @getrusage(i32 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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 8}
!10 = !{!"rusage", !11, i64 0, !11, i64 16, !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}
!11 = !{!"timeval", !12, i64 0, !12, i64 8}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !12, i64 0}
!14 = !{!11, !12, i64 0}
!15 = !{!11, !12, i64 8}


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

; Function Attrs: nounwind uwtable
define dso_local void @timer_end(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @getrusage(i32 noundef 0, ptr noundef %1) #2
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = icmp slt i64 %6, %8
  %.pre16 = load i64, ptr %1, align 8, !tbaa !11
  br i1 %9, label %10, label %13

10:                                               ; preds = %3
  %11 = add nsw i64 %6, 1000000
  store i64 %11, ptr %5, align 8, !tbaa !5
  %12 = add nsw i64 %.pre16, -1
  store i64 %12, ptr %1, align 8, !tbaa !11
  %.pre = load i64, ptr %7, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %10, %3
  %14 = phi i64 [ %12, %10 ], [ %.pre16, %3 ]
  %15 = phi i64 [ %11, %10 ], [ %6, %3 ]
  %16 = phi i64 [ %.pre, %10 ], [ %8, %3 ]
  %17 = sub nsw i64 %15, %16
  store i64 %17, ptr %5, align 8, !tbaa !5
  %18 = load i64, ptr %0, align 8, !tbaa !11
  %19 = sub nsw i64 %14, %18
  store i64 %19, ptr %1, align 8, !tbaa !11
  %20 = load i64, ptr %2, align 8, !tbaa !12
  %21 = add nsw i64 %20, %19
  store i64 %21, ptr %2, align 8, !tbaa !12
  %22 = getelementptr inbounds i8, ptr %2, i64 8
  %23 = load i64, ptr %22, align 8, !tbaa !13
  %24 = add nsw i64 %23, %17
  store i64 %24, ptr %22, align 8, !tbaa !13
  %25 = icmp sgt i64 %24, 1000000
  br i1 %25, label %26, label %29

26:                                               ; preds = %13
  %27 = add nsw i64 %24, -1000000
  store i64 %27, ptr %22, align 8, !tbaa !13
  %28 = add nsw i64 %21, 1
  store i64 %28, ptr %2, align 8, !tbaa !12
  br label %29

29:                                               ; preds = %26, %13
  ret void
}

; Function Attrs: nounwind
declare i32 @getrusage(i32 noundef, ptr noundef) local_unnamed_addr #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 = { 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 #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 8}
!6 = !{!"rusage", !7, i64 0, !7, i64 16, !9, i64 32, !9, i64 40, !9, i64 48, !9, i64 56, !9, i64 64, !9, i64 72, !9, i64 80, !9, i64 88, !9, i64 96, !9, i64 104, !9, i64 112, !9, i64 120, !9, i64 128, !9, i64 136}
!7 = !{!"timeval", !8, i64 0, !8, i64 8}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!6, !8, i64 0}
!12 = !{!7, !8, i64 0}
!13 = !{!7, !8, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass