; LLVM IR from xing1357/SimpleOS :: src (ide)

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

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@g_ide_devices = external dso_local global [5 x %struct.IDE_DEVICE], align 16
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [6 x i8], align 1

; 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 uwtable
declare hidden zeroext i8 @ide_read_register(i8 noundef zeroext, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @ide_print_error(i32 noundef %0, i8 noundef zeroext %1) #1 {
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca [2 x ptr], align 8
  %8 = alloca [2 x ptr], align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  %9 = load i8, ptr %5, align 1, !tbaa !9
  %10 = zext i8 %9 to i32
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %14

12:                                               ; preds = %2
  %13 = load i8, ptr %5, align 1, !tbaa !9
  store i8 %13, ptr %3, align 1
  br label %116

14:                                               ; preds = %2
  call void (ptr, ...) @printf(ptr noundef @.str)
  %15 = load i8, ptr %5, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  call void (ptr, ...) @printf(ptr noundef @.str.1)
  store i8 19, ptr %5, align 1, !tbaa !9
  br label %91

19:                                               ; preds = %14
  %20 = load i8, ptr %5, align 1, !tbaa !9
  %21 = zext i8 %20 to i32
  %22 = icmp eq i32 %21, 2
  br i1 %22, label %23, label %78

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds [5 x %struct.IDE_DEVICE], ptr @g_ide_devices, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.IDE_DEVICE, ptr %26, i32 0, i32 1
  %28 = load i8, ptr %27, align 1, !tbaa !10
  %29 = call zeroext i8 @ide_read_register(i8 noundef zeroext %28, i8 noundef zeroext 1)
  store i8 %29, ptr %6, align 1, !tbaa !9
  %30 = load i8, ptr %6, align 1, !tbaa !9
  %31 = zext i8 %30 to i32
  %32 = and i32 %31, 1
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %23
  call void (ptr, ...) @printf(ptr noundef @.str.2)
  store i8 7, ptr %5, align 1, !tbaa !9
  br label %35

35:                                               ; preds = %34, %23
  %36 = load i8, ptr %6, align 1, !tbaa !9
  %37 = zext i8 %36 to i32
  %38 = and i32 %37, 2
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %35
  call void (ptr, ...) @printf(ptr noundef @.str.3)
  store i8 3, ptr %5, align 1, !tbaa !9
  br label %41

41:                                               ; preds = %40, %35
  %42 = load i8, ptr %6, align 1, !tbaa !9
  %43 = zext i8 %42 to i32
  %44 = and i32 %43, 4
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %41
  call void (ptr, ...) @printf(ptr noundef @.str.4)
  store i8 20, ptr %5, align 1, !tbaa !9
  br label %47

47:                                               ; preds = %46, %41
  %48 = load i8, ptr %6, align 1, !tbaa !9
  %49 = zext i8 %48 to i32
  %50 = and i32 %49, 8
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %47
  call void (ptr, ...) @printf(ptr noundef @.str.3)
  store i8 3, ptr %5, align 1, !tbaa !9
  br label %53

53:                                               ; preds = %52, %47
  %54 = load i8, ptr %6, align 1, !tbaa !9
  %55 = zext i8 %54 to i32
  %56 = and i32 %55, 16
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %53
  call void (ptr, ...) @printf(ptr noundef @.str.5)
  store i8 21, ptr %5, align 1, !tbaa !9
  br label %59

59:                                               ; preds = %58, %53
  %60 = load i8, ptr %6, align 1, !tbaa !9
  %61 = zext i8 %60 to i32
  %62 = and i32 %61, 32
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %59
  call void (ptr, ...) @printf(ptr noundef @.str.3)
  store i8 3, ptr %5, align 1, !tbaa !9
  br label %65

65:                                               ; preds = %64, %59
  %66 = load i8, ptr %6, align 1, !tbaa !9
  %67 = zext i8 %66 to i32
  %68 = and i32 %67, 64
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %71

70:                                               ; preds = %65
  call void (ptr, ...) @printf(ptr noundef @.str.6)
  store i8 22, ptr %5, align 1, !tbaa !9
  br label %71

71:                                               ; preds = %70, %65
  %72 = load i8, ptr %6, align 1, !tbaa !9
  %73 = zext i8 %72 to i32
  %74 = and i32 %73, 128
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %77

76:                                               ; preds = %71
  call void (ptr, ...) @printf(ptr noundef @.str.7)
  store i8 13, ptr %5, align 1, !tbaa !9
  br label %77

77:                                               ; preds = %76, %71
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  br label %90

78:                                               ; preds = %19
  %79 = load i8, ptr %5, align 1, !tbaa !9
  %80 = zext i8 %79 to i32
  %81 = icmp eq i32 %80, 3
  br i1 %81, label %82, label %83

82:                                               ; preds = %78
  call void (ptr, ...) @printf(ptr noundef @.str.8)
  store i8 23, ptr %5, align 1, !tbaa !9
  br label %89

83:                                               ; preds = %78
  %84 = load i8, ptr %5, align 1, !tbaa !9
  %85 = zext i8 %84 to i32
  %86 = icmp eq i32 %85, 4
  br i1 %86, label %87, label %88

87:                                               ; preds = %83
  call void (ptr, ...) @printf(ptr noundef @.str.9)
  store i8 8, ptr %5, align 1, !tbaa !9
  br label %88

88:                                               ; preds = %87, %83
  br label %89

89:                                               ; preds = %88, %82
  br label %90

90:                                               ; preds = %89, %77
  br label %91

91:                                               ; preds = %90, %18
  store ptr @.str.11, ptr %7, align 8, !tbaa !13
  %92 = getelementptr inbounds ptr, ptr %7, i64 1
  store ptr @.str.12, ptr %92, align 8, !tbaa !13
  %93 = load i32, ptr %4, align 4, !tbaa !5
  %94 = zext i32 %93 to i64
  %95 = getelementptr inbounds [5 x %struct.IDE_DEVICE], ptr @g_ide_devices, i64 0, i64 %94
  %96 = getelementptr inbounds %struct.IDE_DEVICE, ptr %95, i32 0, i32 1
  %97 = load i8, ptr %96, align 1, !tbaa !10
  %98 = zext i8 %97 to i64
  %99 = getelementptr inbounds [2 x ptr], ptr %7, i64 0, i64 %98
  %100 = load ptr, ptr %99, align 8, !tbaa !13
  store ptr @.str.13, ptr %8, align 8, !tbaa !13
  %101 = getelementptr inbounds ptr, ptr %8, i64 1
  store ptr @.str.14, ptr %101, align 8, !tbaa !13
  %102 = load i32, ptr %4, align 4, !tbaa !5
  %103 = zext i32 %102 to i64
  %104 = getelementptr inbounds [5 x %struct.IDE_DEVICE], ptr @g_ide_devices, i64 0, i64 %103
  %105 = getelementptr inbounds %struct.IDE_DEVICE, ptr %104, i32 0, i32 2
  %106 = load i8, ptr %105, align 2, !tbaa !15
  %107 = zext i8 %106 to i64
  %108 = getelementptr inbounds [2 x ptr], ptr %8, i64 0, i64 %107
  %109 = load ptr, ptr %108, align 8, !tbaa !13
  %110 = load i32, ptr %4, align 4, !tbaa !5
  %111 = zext i32 %110 to i64
  %112 = getelementptr inbounds [5 x %struct.IDE_DEVICE], ptr @g_ide_devices, i64 0, i64 %111
  %113 = getelementptr inbounds %struct.IDE_DEVICE, ptr %112, i32 0, i32 8
  %114 = getelementptr inbounds [41 x i8], ptr %113, i64 0, i64 0
  call void (ptr, ...) @printf(ptr noundef @.str.10, ptr noundef %100, ptr noundef %109, ptr noundef %114)
  %115 = load i8, ptr %5, align 1, !tbaa !9
  store i8 %115, ptr %3, align 1
  br label %116

116:                                              ; preds = %91, %12
  %117 = load i8, ptr %3, align 1
  ret i8 %117
}

declare void @printf(ptr noundef, ...) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 1}
!11 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !12, i64 4, !12, i64 6, !12, i64 8, !6, i64 12, !6, i64 16, !7, i64 20}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!11, !7, i64 2}


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

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@g_ide_devices = external dso_local global [5 x %struct.IDE_DEVICE], align 16
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @ide_read_register(i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @ide_print_error(i32 noundef %0, i8 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = alloca [2 x ptr], align 8
  %4 = alloca [2 x ptr], align 8
  %5 = icmp eq i8 %1, 0
  br i1 %5, label %52, label %6

6:                                                ; preds = %2
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str) #2
  switch i8 %1, label %36 [
    i8 1, label %.sink.split
    i8 2, label %7
    i8 3, label %34
    i8 4, label %35
  ]

7:                                                ; preds = %6
  %8 = zext i32 %0 to i64
  %9 = getelementptr inbounds [5 x %struct.IDE_DEVICE], ptr @g_ide_devices, i64 0, i64 %8, i32 1
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = tail call zeroext i8 @ide_read_register(i8 noundef zeroext %10, i8 noundef zeroext 1)
  %12 = zext i8 %11 to i32
  %13 = and i32 %12, 1
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %15, label %14

14:                                               ; preds = %7
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str.2) #2
  br label %15

15:                                               ; preds = %14, %7
  %.020 = phi i8 [ 7, %14 ], [ 2, %7 ]
  %16 = and i32 %12, 2
  %.not22 = icmp eq i32 %16, 0
  br i1 %.not22, label %18, label %17

17:                                               ; preds = %15
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str.3) #2
  br label %18

18:                                               ; preds = %17, %15
  %.1 = phi i8 [ 3, %17 ], [ %.020, %15 ]
  %19 = and i32 %12, 4
  %.not23 = icmp eq i32 %19, 0
  br i1 %.not23, label %21, label %20

20:                                               ; preds = %18
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str.4) #2
  br label %21

21:                                               ; preds = %20, %18
  %.2 = phi i8 [ 20, %20 ], [ %.1, %18 ]
  %22 = and i32 %12, 8
  %.not24 = icmp eq i32 %22, 0
  br i1 %.not24, label %24, label %23

23:                                               ; preds = %21
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str.3) #2
  br label %24

24:                                               ; preds = %23, %21
  %.3 = phi i8 [ 3, %23 ], [ %.2, %21 ]
  %25 = and i32 %12, 16
  %.not25 = icmp eq i32 %25, 0
  br i1 %.not25, label %27, label %26

26:                                               ; preds = %24
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str.5) #2
  br label %27

27:                                               ; preds = %26, %24
  %.4 = phi i8 [ 21, %26 ], [ %.3, %24 ]
  %28 = and i32 %12, 32
  %.not26 = icmp eq i32 %28, 0
  br i1 %.not26, label %30, label %29

29:                                               ; preds = %27
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str.3) #2
  br label %30

30:                                               ; preds = %29, %27
  %.5 = phi i8 [ 3, %29 ], [ %.4, %27 ]
  %31 = and i32 %12, 64
  %.not27 = icmp eq i32 %31, 0
  br i1 %.not27, label %33, label %32

32:                                               ; preds = %30
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str.6) #2
  br label %33

33:                                               ; preds = %32, %30
  %.6 = phi i8 [ 22, %32 ], [ %.5, %30 ]
  %.not28 = icmp sgt i8 %11, -1
  br i1 %.not28, label %36, label %.sink.split

34:                                               ; preds = %6
  br label %.sink.split

35:                                               ; preds = %6
  br label %.sink.split

.sink.split:                                      ; preds = %33, %6, %34, %35
  %.str.7.sink = phi ptr [ @.str.9, %35 ], [ @.str.8, %34 ], [ @.str.1, %6 ], [ @.str.7, %33 ]
  %.8.ph = phi i8 [ 8, %35 ], [ 23, %34 ], [ 19, %6 ], [ 13, %33 ]
  tail call void (ptr, ...) @printf(ptr noundef nonnull %.str.7.sink) #2
  br label %36

36:                                               ; preds = %.sink.split, %6, %33
  %.8 = phi i8 [ %.6, %33 ], [ %1, %6 ], [ %.8.ph, %.sink.split ]
  store ptr @.str.11, ptr %3, align 8, !tbaa !11
  %37 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr @.str.12, ptr %37, align 8, !tbaa !11
  %38 = zext i32 %0 to i64
  %39 = getelementptr inbounds [5 x %struct.IDE_DEVICE], ptr @g_ide_devices, i64 0, i64 %38
  %40 = getelementptr inbounds i8, ptr %39, i64 1
  %41 = load i8, ptr %40, align 1, !tbaa !5
  %42 = zext i8 %41 to i64
  %43 = getelementptr inbounds [2 x ptr], ptr %3, i64 0, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  store ptr @.str.13, ptr %4, align 8, !tbaa !11
  %45 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr @.str.14, ptr %45, align 8, !tbaa !11
  %46 = getelementptr inbounds i8, ptr %39, i64 2
  %47 = load i8, ptr %46, align 2, !tbaa !13
  %48 = zext i8 %47 to i64
  %49 = getelementptr inbounds [2 x ptr], ptr %4, i64 0, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds i8, ptr %39, i64 20
  tail call void (ptr, ...) @printf(ptr noundef nonnull @.str.10, ptr noundef %44, ptr noundef %50, ptr noundef nonnull %51) #2
  br label %52

52:                                               ; preds = %2, %36
  %.0 = phi i8 [ %.8, %36 ], [ 0, %2 ]
  ret i8 %.0
}

declare void @printf(ptr noundef, ...) local_unnamed_addr #1

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 = { "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, !7, i64 1}
!6 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !9, i64 4, !9, i64 6, !9, i64 8, !10, i64 12, !10, i64 16, !7, i64 20}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!6, !7, i64 2}


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