; LLVM IR from ucb-bar/RoSE :: soc/sw/baremetal (spiflashread)

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

%union.spiflash_ffmt = type { %struct.anon }
%struct.anon = type { i32 }

@.str.2 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [41 x i8], align 1
@test_data = external hidden global [18 x i8], align 16
@test_len = external hidden global i8, align 1

; Function Attrs: nounwind uwtable
declare dso_local void @configure_spiflash(i32) #0

; Function Attrs: nounwind uwtable
declare dso_local void @write_spiflash(ptr noundef, i32 noundef, i32 noundef, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) #0

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

; 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 dso_local i32 @test_spiflash(i32 noundef, i32 noundef, i8 noundef zeroext) #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca %union.spiflash_ffmt, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %4 = load i32, ptr %2, align 4
  %5 = and i32 %4, -2
  %6 = or i32 %5, 1
  store i32 %6, ptr %2, align 4
  %7 = load i32, ptr %2, align 4
  %8 = and i32 %7, -15
  %9 = or i32 %8, 8
  store i32 %9, ptr %2, align 4
  %10 = load i32, ptr %2, align 4
  %11 = and i32 %10, -241
  %12 = or i32 %11, 0
  store i32 %12, ptr %2, align 4
  %13 = load i32, ptr %2, align 4
  %14 = and i32 %13, -769
  %15 = or i32 %14, 0
  store i32 %15, ptr %2, align 4
  %16 = load i32, ptr %2, align 4
  %17 = and i32 %16, -3073
  %18 = or i32 %17, 0
  store i32 %18, ptr %2, align 4
  %19 = load i32, ptr %2, align 4
  %20 = and i32 %19, -12289
  %21 = or i32 %20, 0
  store i32 %21, ptr %2, align 4
  %22 = load i32, ptr %2, align 4
  %23 = and i32 %22, -16711681
  %24 = or i32 %23, 1245184
  store i32 %24, ptr %2, align 4
  %25 = load i32, ptr %2, align 4
  %26 = and i32 %25, 16777215
  %27 = or i32 %26, 0
  store i32 %27, ptr %2, align 4
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  %29 = getelementptr inbounds %union.spiflash_ffmt, ptr %2, i32 0, i32 0
  %30 = getelementptr inbounds %struct.anon, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 4
  call void @configure_spiflash(i32 %31)
  %32 = call i32 @test_spiflash(i32 noundef 0, i32 noundef 256, i8 noundef zeroext 0)
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %0
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %146

35:                                               ; preds = %0
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %37 = load i32, ptr %2, align 4
  %38 = and i32 %37, -16711681
  %39 = or i32 %38, 196608
  store i32 %39, ptr %2, align 4
  %40 = load i32, ptr %2, align 4
  %41 = and i32 %40, -15
  %42 = or i32 %41, 6
  store i32 %42, ptr %2, align 4
  %43 = getelementptr inbounds %union.spiflash_ffmt, ptr %2, i32 0, i32 0
  %44 = getelementptr inbounds %struct.anon, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 4
  call void @configure_spiflash(i32 %45)
  %46 = call i32 @test_spiflash(i32 noundef 0, i32 noundef 256, i8 noundef zeroext 0)
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %35
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %146

49:                                               ; preds = %35
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %51 = load i32, ptr %2, align 4
  %52 = and i32 %51, -16711681
  %53 = or i32 %52, 720896
  store i32 %53, ptr %2, align 4
  %54 = load i32, ptr %2, align 4
  %55 = and i32 %54, -241
  %56 = or i32 %55, 128
  store i32 %56, ptr %2, align 4
  %57 = getelementptr inbounds %union.spiflash_ffmt, ptr %2, i32 0, i32 0
  %58 = getelementptr inbounds %struct.anon, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 4
  call void @configure_spiflash(i32 %59)
  %60 = call i32 @test_spiflash(i32 noundef 4096, i32 noundef 256, i8 noundef zeroext 0)
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %63

62:                                               ; preds = %49
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %146

63:                                               ; preds = %49
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  %65 = load i32, ptr %2, align 4
  %66 = and i32 %65, -16711681
  %67 = or i32 %66, 786432
  store i32 %67, ptr %2, align 4
  %68 = load i32, ptr %2, align 4
  %69 = and i32 %68, -15
  %70 = or i32 %69, 8
  store i32 %70, ptr %2, align 4
  %71 = getelementptr inbounds %union.spiflash_ffmt, ptr %2, i32 0, i32 0
  %72 = getelementptr inbounds %struct.anon, ptr %71, i32 0, i32 0
  %73 = load i32, ptr %72, align 4
  call void @configure_spiflash(i32 %73)
  %74 = call i32 @test_spiflash(i32 noundef 9024, i32 noundef 256, i8 noundef zeroext 0)
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %76, label %77

76:                                               ; preds = %63
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %146

77:                                               ; preds = %63
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  %79 = load i32, ptr %2, align 4
  %80 = and i32 %79, -16711681
  %81 = or i32 %80, 7077888
  store i32 %81, ptr %2, align 4
  %82 = load i32, ptr %2, align 4
  %83 = and i32 %82, -12289
  %84 = or i32 %83, 8192
  store i32 %84, ptr %2, align 4
  %85 = getelementptr inbounds %union.spiflash_ffmt, ptr %2, i32 0, i32 0
  %86 = getelementptr inbounds %struct.anon, ptr %85, i32 0, i32 0
  %87 = load i32, ptr %86, align 4
  call void @configure_spiflash(i32 %87)
  %88 = call i32 @test_spiflash(i32 noundef 16652, i32 noundef 256, i8 noundef zeroext 0)
  %89 = icmp ne i32 %88, 0
  br i1 %89, label %90, label %91

90:                                               ; preds = %77
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %146

91:                                               ; preds = %77
  %92 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  %93 = load i32, ptr %2, align 4
  %94 = and i32 %93, -16711681
  %95 = or i32 %94, 7012352
  store i32 %95, ptr %2, align 4
  %96 = load i32, ptr %2, align 4
  %97 = and i32 %96, -15
  %98 = or i32 %97, 6
  store i32 %98, ptr %2, align 4
  %99 = getelementptr inbounds %union.spiflash_ffmt, ptr %2, i32 0, i32 0
  %100 = getelementptr inbounds %struct.anon, ptr %99, i32 0, i32 0
  %101 = load i32, ptr %100, align 4
  call void @configure_spiflash(i32 %101)
  %102 = call i32 @test_spiflash(i32 noundef 24568, i32 noundef 256, i8 noundef zeroext 0)
  %103 = icmp ne i32 %102, 0
  br i1 %103, label %104, label %105

104:                                              ; preds = %91
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %146

105:                                              ; preds = %91
  %106 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  %107 = load i32, ptr %2, align 4
  %108 = and i32 %107, -16711681
  %109 = or i32 %108, 15400960
  store i32 %109, ptr %2, align 4
  %110 = load i32, ptr %2, align 4
  %111 = and i32 %110, -3073
  %112 = or i32 %111, 2048
  store i32 %112, ptr %2, align 4
  %113 = getelementptr inbounds %union.spiflash_ffmt, ptr %2, i32 0, i32 0
  %114 = getelementptr inbounds %struct.anon, ptr %113, i32 0, i32 0
  %115 = load i32, ptr %114, align 4
  call void @configure_spiflash(i32 %115)
  %116 = call i32 @test_spiflash(i32 noundef 31748, i32 noundef 256, i8 noundef zeroext 0)
  %117 = icmp ne i32 %116, 0
  br i1 %117, label %118, label %119

118:                                              ; preds = %105
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %146

119:                                              ; preds = %105
  %120 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  %121 = load i32, ptr %2, align 4
  %122 = and i32 %121, -16711681
  %123 = or i32 %122, 15466496
  store i32 %123, ptr %2, align 4
  %124 = load i32, ptr %2, align 4
  %125 = and i32 %124, -15
  %126 = or i32 %125, 8
  store i32 %126, ptr %2, align 4
  %127 = getelementptr inbounds %union.spiflash_ffmt, ptr %2, i32 0, i32 0
  %128 = getelementptr inbounds %struct.anon, ptr %127, i32 0, i32 0
  %129 = load i32, ptr %128, align 4
  call void @configure_spiflash(i32 %129)
  %130 = call i32 @test_spiflash(i32 noundef 36864, i32 noundef 256, i8 noundef zeroext 0)
  %131 = icmp ne i32 %130, 0
  br i1 %131, label %132, label %133

132:                                              ; preds = %119
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %146

133:                                              ; preds = %119
  %134 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  %135 = call i32 @test_spiflash(i32 noundef 1048576, i32 noundef 256, i8 noundef zeroext 1)
  %136 = icmp ne i32 %135, 0
  br i1 %136, label %137, label %138

137:                                              ; preds = %133
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %146

138:                                              ; preds = %133
  %139 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  %140 = load i8, ptr @test_len, align 1, !tbaa !5
  %141 = zext i8 %140 to i32
  call void @write_spiflash(ptr noundef @test_data, i32 noundef %141, i32 noundef 0, i8 noundef zeroext 62, i8 noundef zeroext 4, i8 noundef zeroext 2, i8 noundef zeroext 2)
  %142 = call i32 @test_spiflash(i32 noundef 0, i32 noundef 256, i8 noundef zeroext 0)
  %143 = icmp ne i32 %142, 0
  br i1 %143, label %144, label %145

144:                                              ; preds = %138
  store i32 1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %146

145:                                              ; preds = %138
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %146

146:                                              ; preds = %145, %144, %137, %132, %118, %104, %90, %76, %62, %48, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %147 = load i32, ptr %1, align 4
  ret i32 %147
}

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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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

@.str.2 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [41 x i8], align 1
@test_data = external hidden global [18 x i8], align 16
@test_len = external hidden local_unnamed_addr global i8, align 1

; Function Attrs: nounwind uwtable
declare dso_local void @configure_spiflash(i32) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @write_spiflash(ptr noundef, i32 noundef, i32 noundef, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @test_spiflash(i32 noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  tail call void @configure_spiflash(i32 1245193)
  %2 = tail call i32 @test_spiflash(i32 noundef 0, i32 noundef 256, i8 noundef zeroext 0)
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %3, label %32

3:                                                ; preds = %0
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  tail call void @configure_spiflash(i32 196615)
  %5 = tail call i32 @test_spiflash(i32 noundef 0, i32 noundef 256, i8 noundef zeroext 0)
  %.not30 = icmp eq i32 %5, 0
  br i1 %.not30, label %6, label %32

6:                                                ; preds = %3
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  tail call void @configure_spiflash(i32 721031)
  %8 = tail call i32 @test_spiflash(i32 noundef 4096, i32 noundef 256, i8 noundef zeroext 0)
  %.not31 = icmp eq i32 %8, 0
  br i1 %.not31, label %9, label %32

9:                                                ; preds = %6
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  tail call void @configure_spiflash(i32 786569)
  %11 = tail call i32 @test_spiflash(i32 noundef 9024, i32 noundef 256, i8 noundef zeroext 0)
  %.not32 = icmp eq i32 %11, 0
  br i1 %.not32, label %12, label %32

12:                                               ; preds = %9
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  tail call void @configure_spiflash(i32 7086217)
  %14 = tail call i32 @test_spiflash(i32 noundef 16652, i32 noundef 256, i8 noundef zeroext 0)
  %.not33 = icmp eq i32 %14, 0
  br i1 %.not33, label %15, label %32

15:                                               ; preds = %12
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  tail call void @configure_spiflash(i32 7020679)
  %17 = tail call i32 @test_spiflash(i32 noundef 24568, i32 noundef 256, i8 noundef zeroext 0)
  %.not34 = icmp eq i32 %17, 0
  br i1 %.not34, label %18, label %32

18:                                               ; preds = %15
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  tail call void @configure_spiflash(i32 15411335)
  %20 = tail call i32 @test_spiflash(i32 noundef 31748, i32 noundef 256, i8 noundef zeroext 0)
  %.not35 = icmp eq i32 %20, 0
  br i1 %.not35, label %21, label %32

21:                                               ; preds = %18
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  tail call void @configure_spiflash(i32 15476873)
  %23 = tail call i32 @test_spiflash(i32 noundef 36864, i32 noundef 256, i8 noundef zeroext 0)
  %.not36 = icmp eq i32 %23, 0
  br i1 %.not36, label %24, label %32

24:                                               ; preds = %21
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  %26 = tail call i32 @test_spiflash(i32 noundef 1048576, i32 noundef 256, i8 noundef zeroext 1)
  %.not37 = icmp eq i32 %26, 0
  br i1 %.not37, label %27, label %32

27:                                               ; preds = %24
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  %29 = load i8, ptr @test_len, align 1, !tbaa !5
  %30 = zext i8 %29 to i32
  tail call void @write_spiflash(ptr noundef nonnull @test_data, i32 noundef %30, i32 noundef 0, i8 noundef zeroext 62, i8 noundef zeroext 4, i8 noundef zeroext 2, i8 noundef zeroext 2)
  %31 = tail call i32 @test_spiflash(i32 noundef 0, i32 noundef 256, i8 noundef zeroext 0)
  %.not38 = icmp ne i32 %31, 0
  %. = zext i1 %.not38 to i32
  br label %32

32:                                               ; preds = %27, %24, %21, %18, %15, %12, %9, %6, %3, %0
  %.0 = phi i32 [ 1, %0 ], [ 1, %3 ], [ 1, %6 ], [ 1, %9 ], [ 1, %12 ], [ 1, %15 ], [ 1, %18 ], [ 1, %21 ], [ 1, %24 ], [ %., %27 ]
  ret i32 %.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 = { 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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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