; LLVM IR from mentebinaria/maProc :: src/include/elf/relf.ll (Z4PElfPKc)

; 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.SELF = type { %"struct.SELF::elf64_s", %"struct.SELF::elf32_s", i32 }
%"struct.SELF::elf64_s" = type { ptr, ptr }
%"struct.SELF::elf32_s" = type { ptr, ptr }
%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 }
%struct.Elf64_Ehdr = type { [16 x i8], i16, i16, i32, i64, i64, i64, i32, i16, i16, i16, i16, i16, i16 }

@ElfPointer = external dso_local global ptr, align 8
@Elf = external dso_local global %struct.SELF, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4PElfPKc(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca %struct.stat, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 144, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = call i32 (ptr, i32, ...) @open(ptr noundef %6, i32 noundef 0)
  store i32 %7, ptr %5, align 4, !tbaa !9
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = icmp ne i32 %8, -1
  br i1 %9, label %10, label %40

10:                                               ; preds = %1
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = call i32 @fstat(i32 noundef %11, ptr noundef %4) #5
  %13 = getelementptr inbounds %struct.stat, ptr %4, i32 0, i32 8
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = call ptr @mmap(ptr noundef null, i64 noundef %14, i32 noundef 3, i32 noundef 2, i32 noundef %15, i64 noundef 0) #5
  store ptr %16, ptr @ElfPointer, align 8, !tbaa !5
  %17 = load ptr, ptr @ElfPointer, align 8, !tbaa !5
  %18 = icmp eq ptr %17, inttoptr (i64 -1 to ptr)
  br i1 %18, label %19, label %21

19:                                               ; preds = %10
  %20 = load ptr, ptr @ElfPointer, align 8, !tbaa !5
  call void @perror(ptr noundef %20)
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %37

21:                                               ; preds = %10
  %22 = load ptr, ptr @ElfPointer, align 8, !tbaa !5
  store ptr %22, ptr @Elf, align 8, !tbaa !15
  %23 = load ptr, ptr @Elf, align 8, !tbaa !15
  %24 = getelementptr inbounds %struct.Elf64_Ehdr, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 4
  %26 = load i8, ptr %25, align 4, !tbaa !19
  %27 = zext i8 %26 to i32
  %28 = icmp eq i32 %27, 1
  br i1 %28, label %29, label %31

29:                                               ; preds = %21
  %30 = load ptr, ptr @Elf, align 8, !tbaa !15
  store ptr %30, ptr getelementptr inbounds (%struct.SELF, ptr @Elf, i32 0, i32 1), align 8, !tbaa !20
  br label %31

31:                                               ; preds = %29, %21
  %32 = call noundef zeroext i1 @_ZL9VElfMagicv()
  %33 = zext i1 %32 to i32
  %34 = icmp eq i32 %33, 1
  br i1 %34, label %35, label %36

35:                                               ; preds = %31
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %35, %31
  br label %37

37:                                               ; preds = %36, %19
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = call i32 @close(i32 noundef %38)
  br label %42

40:                                               ; preds = %1
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  call void @perror(ptr noundef %41)
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %40, %37
  %43 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 144, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret i32 %43
}

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

declare i32 @open(ptr noundef, i32 noundef, ...) #2

; Function Attrs: nounwind
declare i32 @fstat(i32 noundef, ptr noundef) #3

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) #3

declare void @perror(ptr noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL9VElfMagicv() #4

declare i32 @close(i32 noundef) #2

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

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


; 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.SELF = type { %"struct.SELF::elf64_s", %"struct.SELF::elf32_s", i32 }
%"struct.SELF::elf64_s" = type { ptr, ptr }
%"struct.SELF::elf32_s" = type { ptr, ptr }
%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 }

@ElfPointer = external dso_local local_unnamed_addr global ptr, align 8
@Elf = external dso_local local_unnamed_addr global %struct.SELF, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z4PElfPKc(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca %struct.stat, align 8
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %2) #7
  %3 = tail call i32 (ptr, i32, ...) @open(ptr noundef %0, i32 noundef 0)
  %.not = icmp eq i32 %3, -1
  br i1 %.not, label %20, label %4

4:                                                ; preds = %1
  %5 = call i32 @fstat(i32 noundef %3, ptr noundef nonnull %2) #7
  %6 = getelementptr inbounds i8, ptr %2, i64 48
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = tail call ptr @mmap(ptr noundef null, i64 noundef %7, i32 noundef 3, i32 noundef 2, i32 noundef %3, i64 noundef 0) #7
  store ptr %8, ptr @ElfPointer, align 8, !tbaa !12
  %9 = icmp eq ptr %8, inttoptr (i64 -1 to ptr)
  br i1 %9, label %10, label %11

10:                                               ; preds = %4
  tail call void @perror(ptr noundef nonnull inttoptr (i64 -1 to ptr)) #8
  br label %18

11:                                               ; preds = %4
  store ptr %8, ptr @Elf, align 8, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %8, i64 4
  %13 = load i8, ptr %12, align 4, !tbaa !18
  %14 = icmp eq i8 %13, 1
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  store ptr %8, ptr getelementptr inbounds (i8, ptr @Elf, i64 16), align 8, !tbaa !19
  br label %16

16:                                               ; preds = %15, %11
  %17 = tail call noundef zeroext i1 @_ZL9VElfMagicv()
  %spec.select = zext i1 %17 to i32
  br label %18

18:                                               ; preds = %16, %10
  %.0 = phi i32 [ 0, %10 ], [ %spec.select, %16 ]
  %19 = tail call i32 @close(i32 noundef %3)
  br label %21

20:                                               ; preds = %1
  tail call void @perror(ptr noundef %0) #8
  br label %21

21:                                               ; preds = %20, %18
  %.1 = phi i32 [ %.0, %18 ], [ 1, %20 ]
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %2) #7
  ret i32 %.1
}

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

; Function Attrs: nofree
declare noundef i32 @open(ptr nocapture noundef readonly, i32 noundef, ...) local_unnamed_addr #2

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

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL9VElfMagicv() local_unnamed_addr #5

declare i32 @close(i32 noundef) local_unnamed_addr #6

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree "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 = { 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 #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 = { 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 #6 = { "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 #7 = { nounwind }
attributes #8 = { cold }

!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, !7, i64 48}
!6 = !{!"_ZTS4stat", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !11, i64 72, !11, i64 88, !11, i64 104, !8, i64 120}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTS8timespec", !7, i64 0, !7, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"_ZTS4SELF", !16, i64 0, !17, i64 16, !10, i64 32}
!16 = !{!"_ZTSN4SELF7elf64_sE", !13, i64 0, !13, i64 8}
!17 = !{!"_ZTSN4SELF7elf32_sE", !13, i64 0, !13, i64 8}
!18 = !{!8, !8, i64 0}
!19 = !{!15, !13, i64 16}


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