; LLVM IR from FrancesoM/Bisc8FX :: sdk_projects/bisc8_platform/ps7_cortexa9_0/standalone_domain/bsp/ps7_cortexa9_0_ (MmcModeInit)

; 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.XSdPs = type { %struct.XSdPs_Config, i32, i32, i32, i32, i8, i8, i8, i8, i32, i8, [4 x i32], i32, [4 x i32], i32, i32, i32, i32, i32, i64, i16, i32, i8, i32 }
%struct.XSdPs_Config = type { i16, i32, i32, i32, i32, i32, i32, i32, i8 }

@XSdPs_MmcModeInit.ExtCsd = external hidden global [512 x i8], align 32

; 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

declare i32 @XSdPs_Change_BusWidth(ptr noundef) #1

declare i32 @XSdPs_Change_BusSpeed(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XSdPs_MmcModeInit(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.XSdPs, ptr %4, i32 0, i32 8
  store i8 2, ptr %5, align 1, !tbaa !9
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = call i32 @XSdPs_Change_BusWidth(ptr noundef %6)
  store i32 %7, ptr %3, align 4, !tbaa !15
  %8 = load i32, ptr %3, align 4, !tbaa !15
  %9 = sext i32 %8 to i64
  %10 = icmp ne i64 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  store i32 1, ptr %3, align 4, !tbaa !15
  br label %78

12:                                               ; preds = %1
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call i32 @XSdPs_Get_Mmc_ExtCsd(ptr noundef %13, ptr noundef @XSdPs_MmcModeInit.ExtCsd)
  store i32 %14, ptr %3, align 4, !tbaa !15
  %15 = load i32, ptr %3, align 4, !tbaa !15
  %16 = sext i32 %15 to i64
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %12
  store i32 1, ptr %3, align 4, !tbaa !15
  br label %78

19:                                               ; preds = %12
  %20 = load i8, ptr getelementptr inbounds ([512 x i8], ptr @XSdPs_MmcModeInit.ExtCsd, i64 0, i64 215), align 1, !tbaa !16
  %21 = zext i8 %20 to i32
  %22 = shl i32 %21, 24
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.XSdPs, ptr %23, i32 0, i32 14
  store i32 %22, ptr %24, align 4, !tbaa !17
  %25 = load i8, ptr getelementptr inbounds ([512 x i8], ptr @XSdPs_MmcModeInit.ExtCsd, i64 0, i64 214), align 2, !tbaa !16
  %26 = zext i8 %25 to i32
  %27 = shl i32 %26, 16
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.XSdPs, ptr %28, i32 0, i32 14
  %30 = load i32, ptr %29, align 4, !tbaa !17
  %31 = or i32 %30, %27
  store i32 %31, ptr %29, align 4, !tbaa !17
  %32 = load i8, ptr getelementptr inbounds ([512 x i8], ptr @XSdPs_MmcModeInit.ExtCsd, i64 0, i64 213), align 1, !tbaa !16
  %33 = zext i8 %32 to i32
  %34 = shl i32 %33, 8
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XSdPs, ptr %35, i32 0, i32 14
  %37 = load i32, ptr %36, align 4, !tbaa !17
  %38 = or i32 %37, %34
  store i32 %38, ptr %36, align 4, !tbaa !17
  %39 = load i8, ptr getelementptr inbounds ([512 x i8], ptr @XSdPs_MmcModeInit.ExtCsd, i64 0, i64 212), align 4, !tbaa !16
  %40 = zext i8 %39 to i32
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.XSdPs, ptr %41, i32 0, i32 14
  %43 = load i32, ptr %42, align 4, !tbaa !17
  %44 = or i32 %43, %40
  store i32 %44, ptr %42, align 4, !tbaa !17
  %45 = load i8, ptr getelementptr inbounds ([512 x i8], ptr @XSdPs_MmcModeInit.ExtCsd, i64 0, i64 196), align 4, !tbaa !16
  %46 = zext i8 %45 to i32
  %47 = and i32 %46, 2
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %77

49:                                               ; preds = %19
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.XSdPs, ptr %50, i32 0, i32 8
  %52 = load i8, ptr %51, align 1, !tbaa !9
  %53 = zext i8 %52 to i32
  %54 = icmp uge i32 %53, 2
  br i1 %54, label %55, label %77

55:                                               ; preds = %49
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.XSdPs, ptr %56, i32 0, i32 16
  store i32 5, ptr %57, align 4, !tbaa !18
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = call i32 @XSdPs_Change_BusSpeed(ptr noundef %58)
  store i32 %59, ptr %3, align 4, !tbaa !15
  %60 = load i32, ptr %3, align 4, !tbaa !15
  %61 = sext i32 %60 to i64
  %62 = icmp ne i64 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %55
  store i32 1, ptr %3, align 4, !tbaa !15
  br label %78

64:                                               ; preds = %55
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = call i32 @XSdPs_Get_Mmc_ExtCsd(ptr noundef %65, ptr noundef @XSdPs_MmcModeInit.ExtCsd)
  store i32 %66, ptr %3, align 4, !tbaa !15
  %67 = load i32, ptr %3, align 4, !tbaa !15
  %68 = sext i32 %67 to i64
  %69 = icmp ne i64 %68, 0
  br i1 %69, label %70, label %71

70:                                               ; preds = %64
  store i32 1, ptr %3, align 4, !tbaa !15
  br label %78

71:                                               ; preds = %64
  %72 = load i8, ptr getelementptr inbounds ([512 x i8], ptr @XSdPs_MmcModeInit.ExtCsd, i64 0, i64 185), align 1, !tbaa !16
  %73 = zext i8 %72 to i32
  %74 = icmp ne i32 %73, 1
  br i1 %74, label %75, label %76

75:                                               ; preds = %71
  store i32 1, ptr %3, align 4, !tbaa !15
  br label %78

76:                                               ; preds = %71
  br label %77

77:                                               ; preds = %76, %49, %19
  store i32 0, ptr %3, align 4, !tbaa !15
  br label %78

78:                                               ; preds = %77, %75, %70, %63, %18, %11
  %79 = load i32, ptr %3, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %79
}

declare i32 @XSdPs_Get_Mmc_ExtCsd(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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/C++ TBAA"}
!9 = !{!10, !7, i64 55}
!10 = !{!"", !11, i64 0, !13, i64 36, !13, i64 40, !13, i64 44, !13, i64 48, !7, i64 52, !7, i64 53, !7, i64 54, !7, i64 55, !13, i64 56, !7, i64 60, !7, i64 64, !13, i64 80, !7, i64 84, !13, i64 100, !13, i64 104, !13, i64 108, !13, i64 112, !13, i64 116, !14, i64 120, !12, i64 128, !13, i64 132, !7, i64 136, !13, i64 140}
!11 = !{!"", !12, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !7, i64 32}
!12 = !{!"short", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!10, !13, i64 100}
!18 = !{!10, !13, i64 108}


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

@XSdPs_MmcModeInit.ExtCsd = external hidden global [512 x i8], align 32

declare i32 @XSdPs_Change_BusWidth(ptr noundef) local_unnamed_addr #0

declare i32 @XSdPs_Change_BusSpeed(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @XSdPs_MmcModeInit(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 55
  store i8 2, ptr %2, align 1, !tbaa !5
  %3 = tail call i32 @XSdPs_Change_BusWidth(ptr noundef %0) #2
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %34

4:                                                ; preds = %1
  %5 = tail call i32 @XSdPs_Get_Mmc_ExtCsd(ptr noundef nonnull %0, ptr noundef nonnull @XSdPs_MmcModeInit.ExtCsd) #2
  %.not15 = icmp eq i32 %5, 0
  br i1 %.not15, label %6, label %34

6:                                                ; preds = %4
  %7 = load i8, ptr getelementptr inbounds (i8, ptr @XSdPs_MmcModeInit.ExtCsd, i64 215), align 1, !tbaa !13
  %8 = zext i8 %7 to i32
  %9 = shl nuw i32 %8, 24
  %10 = getelementptr inbounds i8, ptr %0, i64 100
  store i32 %9, ptr %10, align 4, !tbaa !14
  %11 = load i8, ptr getelementptr inbounds (i8, ptr @XSdPs_MmcModeInit.ExtCsd, i64 214), align 2, !tbaa !13
  %12 = zext i8 %11 to i32
  %13 = shl nuw nsw i32 %12, 16
  %14 = or disjoint i32 %13, %9
  store i32 %14, ptr %10, align 4, !tbaa !14
  %15 = load i8, ptr getelementptr inbounds (i8, ptr @XSdPs_MmcModeInit.ExtCsd, i64 213), align 1, !tbaa !13
  %16 = zext i8 %15 to i32
  %17 = shl nuw nsw i32 %16, 8
  %18 = or disjoint i32 %17, %14
  store i32 %18, ptr %10, align 4, !tbaa !14
  %19 = load i8, ptr getelementptr inbounds (i8, ptr @XSdPs_MmcModeInit.ExtCsd, i64 212), align 4, !tbaa !13
  %20 = zext i8 %19 to i32
  %21 = or disjoint i32 %18, %20
  store i32 %21, ptr %10, align 4, !tbaa !14
  %22 = load i8, ptr getelementptr inbounds (i8, ptr @XSdPs_MmcModeInit.ExtCsd, i64 196), align 4, !tbaa !13
  %23 = and i8 %22, 2
  %.not16 = icmp eq i8 %23, 0
  br i1 %.not16, label %33, label %24

24:                                               ; preds = %6
  %25 = load i8, ptr %2, align 1, !tbaa !5
  %26 = icmp ugt i8 %25, 1
  br i1 %26, label %27, label %33

27:                                               ; preds = %24
  %28 = getelementptr inbounds i8, ptr %0, i64 108
  store i32 5, ptr %28, align 4, !tbaa !15
  %29 = tail call i32 @XSdPs_Change_BusSpeed(ptr noundef nonnull %0) #2
  %.not17 = icmp eq i32 %29, 0
  br i1 %.not17, label %30, label %34

30:                                               ; preds = %27
  %31 = tail call i32 @XSdPs_Get_Mmc_ExtCsd(ptr noundef nonnull %0, ptr noundef nonnull @XSdPs_MmcModeInit.ExtCsd) #2
  %.not18 = icmp eq i32 %31, 0
  %32 = load i8, ptr getelementptr inbounds (i8, ptr @XSdPs_MmcModeInit.ExtCsd, i64 185), align 1
  %.not19 = icmp eq i8 %32, 1
  %or.cond = select i1 %.not18, i1 %.not19, i1 false
  br i1 %or.cond, label %33, label %34

33:                                               ; preds = %30, %24, %6
  br label %34

34:                                               ; preds = %30, %27, %4, %1, %33
  %.0 = phi i32 [ 0, %33 ], [ 1, %1 ], [ 1, %4 ], [ 1, %27 ], [ 1, %30 ]
  ret i32 %.0
}

declare i32 @XSdPs_Get_Mmc_ExtCsd(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #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 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 #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, !9, i64 55}
!6 = !{!"", !7, i64 0, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !9, i64 52, !9, i64 53, !9, i64 54, !9, i64 55, !11, i64 56, !9, i64 60, !9, i64 64, !11, i64 80, !9, i64 84, !11, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !12, i64 120, !8, i64 128, !11, i64 132, !9, i64 136, !11, i64 140}
!7 = !{!"", !8, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !9, i64 32}
!8 = !{!"short", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"long", !9, i64 0}
!13 = !{!9, !9, i64 0}
!14 = !{!6, !11, i64 100}
!15 = !{!6, !11, i64 108}


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