; LLVM IR from artagnon/phoenixfs :: pack (find_pack_entry)

; 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.packed_git = type { [4096 x i8], [4096 x i8], ptr, ptr, i64, i64, i32 }

@packroot = external hidden global %struct.packed_git, align 8
@.str = external hidden unnamed_addr constant [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [36 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @find_pack_entry(ptr noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca [40 x i8], align 16
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %14 = load ptr, ptr getelementptr inbounds (%struct.packed_git, ptr @packroot, i32 0, i32 3), align 8, !tbaa !9
  store ptr %14, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %15 = load ptr, ptr getelementptr inbounds (%struct.packed_git, ptr @packroot, i32 0, i32 3), align 8, !tbaa !9
  store ptr %15, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 40, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds i32, ptr %16, i64 2
  store ptr %17, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  store ptr %19, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 1024
  store ptr %21, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i8, ptr %23, align 1, !tbaa !13
  %25 = zext i8 %24 to i64
  %26 = getelementptr inbounds i32, ptr %22, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !14
  %28 = call i32 @__bswap_32(i32 noundef %27)
  store i32 %28, ptr %6, align 4, !tbaa !14
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load i8, ptr %29, align 1, !tbaa !13
  %31 = zext i8 %30 to i32
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %1
  br label %44

34:                                               ; preds = %1
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load i8, ptr %36, align 1, !tbaa !13
  %38 = zext i8 %37 to i32
  %39 = sub nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i32, ptr %35, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !14
  %43 = call i32 @__bswap_32(i32 noundef %42)
  br label %44

44:                                               ; preds = %34, %33
  %45 = phi i32 [ 0, %33 ], [ %43, %34 ]
  store i32 %45, ptr %7, align 4, !tbaa !14
  store i32 20, ptr %8, align 4, !tbaa !14
  %46 = getelementptr inbounds [40 x i8], ptr %9, i64 0, i64 0
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  call void @print_sha1(ptr noundef %46, ptr noundef %47)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %48 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.1)
  store ptr %48, ptr %11, align 8, !tbaa !5
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %60

51:                                               ; preds = %44
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = getelementptr inbounds [40 x i8], ptr %9, i64 0, i64 0
  %54 = load i32, ptr %7, align 4, !tbaa !14
  %55 = load i32, ptr %6, align 4, !tbaa !14
  %56 = load i32, ptr getelementptr inbounds (%struct.packed_git, ptr @packroot, i32 0, i32 6), align 8, !tbaa !15
  %57 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef @.str.2, i32 noundef 154, ptr noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef %56) #5
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = call i32 @fclose(ptr noundef %58)
  br label %60

60:                                               ; preds = %51, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !14
  %63 = zext i32 %62 to i64
  %64 = load i32, ptr %7, align 4, !tbaa !14
  %65 = load i32, ptr %6, align 4, !tbaa !14
  %66 = load i32, ptr getelementptr inbounds (%struct.packed_git, ptr @packroot, i32 0, i32 6), align 8, !tbaa !15
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = call i32 @sha1_entry_pos(ptr noundef %61, i64 noundef %63, i64 noundef 0, i32 noundef %64, i32 noundef %65, i32 noundef %66, ptr noundef %67)
  store i32 %68, ptr %10, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %69 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.1)
  store ptr %69, ptr %12, align 8, !tbaa !5
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %78

72:                                               ; preds = %60
  %73 = load ptr, ptr %12, align 8, !tbaa !5
  %74 = load i32, ptr %10, align 4, !tbaa !14
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %73, ptr noundef @.str.3, i32 noundef 159, i32 noundef %74) #5
  %76 = load ptr, ptr %12, align 8, !tbaa !5
  %77 = call i32 @fclose(ptr noundef %76)
  br label %78

78:                                               ; preds = %72, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %79 = load i32, ptr %10, align 4, !tbaa !14
  %80 = icmp slt i32 %79, 0
  br i1 %80, label %81, label %82

81:                                               ; preds = %78
  store i64 0, ptr %2, align 8
  store i32 1, ptr %13, align 4
  br label %85

82:                                               ; preds = %78
  %83 = load i32, ptr %10, align 4, !tbaa !14
  %84 = call i64 @nth_packed_object_offset(i32 noundef %83)
  store i64 %84, ptr %2, align 8
  store i32 1, ptr %13, align 4
  br label %85

85:                                               ; preds = %82, %81
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %86 = load i64, ptr %2, align 8
  ret i64 %86
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__bswap_32(i32 noundef) #2

declare void @print_sha1(ptr noundef, ptr noundef) #3

declare noalias ptr @fopen(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #4

declare i32 @fclose(ptr noundef) #3

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

; Function Attrs: nounwind uwtable
declare hidden i32 @sha1_entry_pos(ptr noundef, i64 noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i64 @nth_packed_object_offset(i32 noundef) #0

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 = { inlinehint 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 = { "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 #4 = { 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 #5 = { 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, !6, i64 8200}
!10 = !{!"packed_git", !7, i64 0, !7, i64 4096, !6, i64 8192, !6, i64 8200, !11, i64 8208, !11, i64 8216, !12, i64 8224}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !12, i64 8224}


; 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.packed_git = type { [4096 x i8], [4096 x i8], ptr, ptr, i64, i64, i32 }

@packroot = external hidden local_unnamed_addr global %struct.packed_git, align 8
@.str = external hidden unnamed_addr constant [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [36 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @find_pack_entry(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca [40 x i8], align 16
  %3 = load ptr, ptr getelementptr inbounds (i8, ptr @packroot, i64 8200), align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %2) #5
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  %5 = getelementptr inbounds i8, ptr %3, i64 1032
  %6 = load i8, ptr %0, align 1, !tbaa !12
  %7 = zext i8 %6 to i64
  %8 = getelementptr inbounds i32, ptr %4, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !13
  %10 = tail call i32 @__bswap_32(i32 noundef %9)
  %11 = load i8, ptr %0, align 1, !tbaa !12
  %12 = icmp eq i8 %11, 0
  br i1 %12, label %20, label %13

13:                                               ; preds = %1
  %14 = zext i8 %11 to i64
  %15 = add nuw nsw i64 %14, 4294967295
  %16 = and i64 %15, 4294967295
  %17 = getelementptr inbounds i32, ptr %4, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !13
  %19 = tail call i32 @__bswap_32(i32 noundef %18)
  br label %20

20:                                               ; preds = %1, %13
  %21 = phi i32 [ %19, %13 ], [ 0, %1 ]
  call void @print_sha1(ptr noundef nonnull %2, ptr noundef nonnull %0) #5
  %22 = call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1)
  %.not = icmp eq ptr %22, null
  br i1 %.not, label %27, label %23

23:                                               ; preds = %20
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @packroot, i64 8224), align 8, !tbaa !14
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %22, ptr noundef nonnull @.str.2, i32 noundef 154, ptr noundef nonnull %2, i32 noundef %21, i32 noundef %10, i32 noundef %24) #5
  %26 = call i32 @fclose(ptr noundef nonnull %22)
  br label %27

27:                                               ; preds = %23, %20
  %28 = load i32, ptr getelementptr inbounds (i8, ptr @packroot, i64 8224), align 8, !tbaa !14
  %29 = call i32 @sha1_entry_pos(ptr noundef nonnull %5, i64 noundef 20, i64 noundef 0, i32 noundef %21, i32 noundef %10, i32 noundef %28, ptr noundef nonnull %0)
  %30 = call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1)
  %.not29 = icmp eq ptr %30, null
  br i1 %.not29, label %34, label %31

31:                                               ; preds = %27
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %30, ptr noundef nonnull @.str.3, i32 noundef 159, i32 noundef %29) #5
  %33 = call i32 @fclose(ptr noundef nonnull %30)
  br label %34

34:                                               ; preds = %31, %27
  %35 = icmp slt i32 %29, 0
  br i1 %35, label %38, label %36

36:                                               ; preds = %34
  %37 = call i64 @nth_packed_object_offset(i32 noundef %29)
  br label %38

38:                                               ; preds = %34, %36
  %.0 = phi i64 [ %37, %36 ], [ 0, %34 ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %2) #5
  ret i64 %.0
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__bswap_32(i32 noundef) local_unnamed_addr #2

declare void @print_sha1(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #4

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

; Function Attrs: nounwind uwtable
declare hidden i32 @sha1_entry_pos(ptr noundef, i64 noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i64 @nth_packed_object_offset(i32 noundef) local_unnamed_addr #0

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = { "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 #4 = { 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 #5 = { 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, !9, i64 8200}
!6 = !{!"packed_git", !7, i64 0, !7, i64 4096, !9, i64 8192, !9, i64 8200, !10, i64 8208, !10, i64 8216, !11, i64 8224}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!6, !11, i64 8224}


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