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

; 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.Elf64_Ehdr = type { [16 x i8], i16, i16, i32, i64, i64, i64, i32, i16, i16, i16, i16, i16, i16 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9ElfStructR4SELF(ptr noundef nonnull align 8 dereferenceable(40) %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr @Elf, align 8, !tbaa !9
  %4 = getelementptr inbounds %struct.Elf64_Ehdr, ptr %3, i32 0, i32 0
  %5 = getelementptr inbounds [16 x i8], ptr %4, i64 0, i64 4
  %6 = load i8, ptr %5, align 4, !tbaa !14
  %7 = zext i8 %6 to i32
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %9, label %22

9:                                                ; preds = %1
  %10 = load ptr, ptr getelementptr inbounds (%struct.SELF, ptr @Elf, i32 0, i32 1), align 8, !tbaa !15
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.SELF, ptr %11, i32 0, i32 1
  %13 = getelementptr inbounds %"struct.SELF::elf32_s", ptr %12, i32 0, i32 0
  store ptr %10, ptr %13, align 8, !tbaa !15
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.SELF, ptr %14, i32 0, i32 2
  store i32 1, ptr %15, align 8, !tbaa !16
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.SELF, ptr %16, i32 0, i32 0
  %18 = getelementptr inbounds %"struct.SELF::elf64_s", ptr %17, i32 0, i32 0
  store ptr null, ptr %18, align 8, !tbaa !9
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.SELF, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds %"struct.SELF::elf64_s", ptr %20, i32 0, i32 1
  store ptr null, ptr %21, align 8, !tbaa !17
  br label %35

22:                                               ; preds = %1
  %23 = load ptr, ptr @Elf, align 8, !tbaa !9
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SELF, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %"struct.SELF::elf64_s", ptr %25, i32 0, i32 0
  store ptr %23, ptr %26, align 8, !tbaa !9
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.SELF, ptr %27, i32 0, i32 2
  store i32 2, ptr %28, align 8, !tbaa !16
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.SELF, ptr %29, i32 0, i32 1
  %31 = getelementptr inbounds %"struct.SELF::elf32_s", ptr %30, i32 0, i32 0
  store ptr null, ptr %31, align 8, !tbaa !15
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.SELF, ptr %32, i32 0, i32 1
  %34 = getelementptr inbounds %"struct.SELF::elf32_s", ptr %33, i32 0, i32 1
  store ptr null, ptr %34, align 8, !tbaa !18
  br label %35

35:                                               ; preds = %22, %9
  %36 = load ptr, ptr @Elf, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.Elf64_Ehdr, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds [16 x i8], ptr %37, i64 0, i64 5
  %39 = load i8, ptr %38, align 1, !tbaa !14
  %40 = zext i8 %39 to i32
  %41 = icmp ne i32 %40, 1
  br i1 %41, label %42, label %52

42:                                               ; preds = %35
  %43 = load ptr, ptr @Elf, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.Elf64_Ehdr, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds [16 x i8], ptr %44, i64 0, i64 4
  %46 = load i8, ptr %45, align 4, !tbaa !14
  %47 = zext i8 %46 to i32
  %48 = icmp eq i32 %47, 2
  br i1 %48, label %49, label %50

49:                                               ; preds = %42
  call void @_ZL12SwapEndian64v()
  br label %51

50:                                               ; preds = %42
  call void @_ZL12SwapEndian32v()
  br label %51

51:                                               ; preds = %50, %49
  br label %52

52:                                               ; preds = %51, %35
  ret void
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL12SwapEndian64v() #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL12SwapEndian32v() #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 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" }

!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, !6, i64 0}
!10 = !{!"_ZTS4SELF", !11, i64 0, !12, i64 16, !13, i64 32}
!11 = !{!"_ZTSN4SELF7elf64_sE", !6, i64 0, !6, i64 8}
!12 = !{!"_ZTSN4SELF7elf32_sE", !6, i64 0, !6, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!10, !6, i64 16}
!16 = !{!10, !13, i64 32}
!17 = !{!10, !6, i64 8}
!18 = !{!10, !6, i64 24}


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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9ElfStructR4SELF(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(40) %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @Elf, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 4
  %4 = load i8, ptr %3, align 4, !tbaa !13
  %5 = icmp eq i8 %4, 1
  br i1 %5, label %6, label %8

6:                                                ; preds = %1
  %7 = load ptr, ptr getelementptr inbounds (i8, ptr @Elf, i64 16), align 8, !tbaa !14
  br label %8

8:                                                ; preds = %1, %6
  %.sink11 = phi i64 [ 8, %6 ], [ 24, %1 ]
  %.sink9 = phi ptr [ %7, %6 ], [ null, %1 ]
  %.sink8 = phi i32 [ 1, %6 ], [ 2, %1 ]
  %.sink = phi ptr [ null, %6 ], [ %2, %1 ]
  %9 = getelementptr inbounds i8, ptr %0, i64 %.sink11
  store ptr null, ptr %9, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %.sink9, ptr %10, align 8
  %11 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %.sink8, ptr %11, align 8
  store ptr %.sink, ptr %0, align 8
  %12 = load ptr, ptr @Elf, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 5
  %14 = load i8, ptr %13, align 1, !tbaa !13
  %.not = icmp eq i8 %14, 1
  br i1 %.not, label %21, label %15

15:                                               ; preds = %8
  %16 = getelementptr inbounds i8, ptr %12, i64 4
  %17 = load i8, ptr %16, align 4, !tbaa !13
  %18 = icmp eq i8 %17, 2
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  tail call void @_ZL12SwapEndian64v()
  br label %21

20:                                               ; preds = %15
  tail call void @_ZL12SwapEndian32v()
  br label %21

21:                                               ; preds = %19, %20, %8
  ret void
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL12SwapEndian64v() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL12SwapEndian32v() local_unnamed_addr #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 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" }

!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 0}
!6 = !{!"_ZTS4SELF", !7, i64 0, !11, i64 16, !12, i64 32}
!7 = !{!"_ZTSN4SELF7elf64_sE", !8, i64 0, !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN4SELF7elf32_sE", !8, i64 0, !8, i64 8}
!12 = !{!"int", !9, i64 0}
!13 = !{!9, !9, i64 0}
!14 = !{!6, !8, i64 16}
!15 = !{!8, !8, i64 0}


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