; LLVM IR from kajott/GIPS :: src/file_util_posix.ll (ZN8FileUtil15FileFingerprint6updateEPKc)

; 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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }
%"class.FileUtil::FileFingerprint" = type { i64, i64 }

; 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

; Function Attrs: nounwind
declare i32 @stat(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN8FileUtil15FileFingerprint6updateEPKc(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.stat, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  %9 = getelementptr inbounds %"class.FileUtil::FileFingerprint", ptr %8, i32 0, i32 1
  store i64 0, ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds %"class.FileUtil::FileFingerprint", ptr %8, i32 0, i32 0
  store i64 0, ptr %10, align 8, !tbaa !12
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %18

13:                                               ; preds = %2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 0
  %16 = load i8, ptr %15, align 1, !tbaa !13
  %17 = icmp ne i8 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %13, %2
  store i1 false, ptr %3, align 1
  br label %38

19:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 144, ptr %6) #3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call i32 @stat(ptr noundef %20, ptr noundef %6) #3
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %37

24:                                               ; preds = %19
  %25 = getelementptr inbounds %struct.stat, ptr %6, i32 0, i32 8
  %26 = load i64, ptr %25, align 8, !tbaa !14
  %27 = getelementptr inbounds %"class.FileUtil::FileFingerprint", ptr %8, i32 0, i32 0
  store i64 %26, ptr %27, align 8, !tbaa !12
  %28 = getelementptr inbounds %struct.stat, ptr %6, i32 0, i32 12
  %29 = getelementptr inbounds %struct.timespec, ptr %28, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !18
  %31 = mul i64 %30, 1000000000
  %32 = getelementptr inbounds %struct.stat, ptr %6, i32 0, i32 12
  %33 = getelementptr inbounds %struct.timespec, ptr %32, i32 0, i32 1
  %34 = load i64, ptr %33, align 8, !tbaa !19
  %35 = add i64 %31, %34
  %36 = getelementptr inbounds %"class.FileUtil::FileFingerprint", ptr %8, i32 0, i32 1
  store i64 %35, ptr %36, align 8, !tbaa !9
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %37

37:                                               ; preds = %24, %23
  call void @llvm.lifetime.end.p0(i64 144, ptr %6) #3
  br label %38

38:                                               ; preds = %37, %18
  %39 = load i1, ptr %3, align 1
  ret i1 %39
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !11, i64 8}
!10 = !{!"_ZTSN8FileUtil15FileFingerprintE", !11, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !11, i64 48}
!15 = !{!"_ZTS4stat", !11, i64 0, !11, i64 8, !11, i64 16, !16, i64 24, !16, i64 28, !16, i64 32, !16, i64 36, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !17, i64 72, !17, i64 88, !17, i64 104, !7, i64 120}
!16 = !{!"int", !7, i64 0}
!17 = !{!"_ZTS8timespec", !11, i64 0, !11, i64 8}
!18 = !{!15, !11, i64 88}
!19 = !{!15, !11, i64 96}


; 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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @stat(ptr nocapture noundef readonly, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local noundef zeroext i1 @_ZN8FileUtil15FileFingerprint6updateEPKc(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(16) %0, ptr noundef readonly %1) local_unnamed_addr #2 align 2 {
  %3 = alloca %struct.stat, align 8
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %.not = icmp eq ptr %1, null
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 0, i64 16, i1 false)
  br i1 %.not, label %19, label %5

5:                                                ; preds = %2
  %6 = load i8, ptr %1, align 1, !tbaa !5
  %.not6 = icmp eq i8 %6, 0
  br i1 %.not6, label %19, label %7

7:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %3) #4
  %8 = call i32 @stat(ptr noundef nonnull %1, ptr noundef nonnull %3) #4
  %.not7 = icmp eq i32 %8, 0
  br i1 %.not7, label %9, label %18

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %3, i64 48
  %11 = load i64, ptr %10, align 8, !tbaa !8
  store i64 %11, ptr %0, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %3, i64 88
  %13 = load i64, ptr %12, align 8, !tbaa !15
  %14 = mul i64 %13, 1000000000
  %15 = getelementptr inbounds i8, ptr %3, i64 96
  %16 = load i64, ptr %15, align 8, !tbaa !16
  %17 = add i64 %14, %16
  store i64 %17, ptr %4, align 8, !tbaa !17
  br label %18

18:                                               ; preds = %7, %9
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %3) #4
  br label %19

19:                                               ; preds = %2, %5, %18
  %.1 = phi i1 [ %.not7, %18 ], [ false, %5 ], [ false, %2 ]
  ret i1 %.1
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !10, i64 48}
!9 = !{!"_ZTS4stat", !10, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !12, i64 72, !12, i64 88, !12, i64 104, !6, i64 120}
!10 = !{!"long", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"_ZTS8timespec", !10, i64 0, !10, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTSN8FileUtil15FileFingerprintE", !10, i64 0, !10, i64 8}
!15 = !{!9, !10, i64 88}
!16 = !{!9, !10, i64 96}
!17 = !{!14, !10, i64 8}


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