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

; 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
@test_data = external hidden global [18 x i8], align 16
@test_len = external hidden global 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

; 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
declare dso_local i32 @check_write(ptr noundef, i32 noundef, i32 noundef) #0

; 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 %90

35:                                               ; preds = %0
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %37 = load i8, ptr @test_len, align 1, !tbaa !5
  %38 = zext i8 %37 to i32
  call void @write_spiflash(ptr noundef @test_data, i32 noundef %38, i32 noundef 512, i8 noundef zeroext 2, i8 noundef zeroext 3, i8 noundef zeroext 0, i8 noundef zeroext 0)
  %39 = load i8, ptr @test_len, align 1, !tbaa !5
  %40 = zext i8 %39 to i32
  %41 = call i32 @check_write(ptr noundef @test_data, i32 noundef %40, i32 noundef 512)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %44

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

44:                                               ; preds = %35
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %46 = load i8, ptr @test_len, align 1, !tbaa !5
  %47 = zext i8 %46 to i32
  call void @write_spiflash(ptr noundef @test_data, i32 noundef %47, i32 noundef 768, i8 noundef zeroext 50, i8 noundef zeroext 3, i8 noundef zeroext 0, i8 noundef zeroext 2)
  %48 = load i8, ptr @test_len, align 1, !tbaa !5
  %49 = zext i8 %48 to i32
  %50 = call i32 @check_write(ptr noundef @test_data, i32 noundef %49, i32 noundef 768)
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %53

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

53:                                               ; preds = %44
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  %55 = load i8, ptr @test_len, align 1, !tbaa !5
  %56 = zext i8 %55 to i32
  call void @write_spiflash(ptr noundef @test_data, i32 noundef %56, i32 noundef 1024, i8 noundef zeroext 56, i8 noundef zeroext 3, i8 noundef zeroext 2, i8 noundef zeroext 2)
  %57 = load i8, ptr @test_len, align 1, !tbaa !5
  %58 = zext i8 %57 to i32
  %59 = call i32 @check_write(ptr noundef @test_data, i32 noundef %58, i32 noundef 1024)
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %62

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

62:                                               ; preds = %53
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  %64 = load i8, ptr @test_len, align 1, !tbaa !5
  %65 = zext i8 %64 to i32
  call void @write_spiflash(ptr noundef @test_data, i32 noundef %65, i32 noundef 1280, i8 noundef zeroext 18, i8 noundef zeroext 4, i8 noundef zeroext 0, i8 noundef zeroext 0)
  %66 = load i8, ptr @test_len, align 1, !tbaa !5
  %67 = zext i8 %66 to i32
  %68 = call i32 @check_write(ptr noundef @test_data, i32 noundef %67, i32 noundef 1280)
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %71

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

71:                                               ; preds = %62
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  %73 = load i8, ptr @test_len, align 1, !tbaa !5
  %74 = zext i8 %73 to i32
  call void @write_spiflash(ptr noundef @test_data, i32 noundef %74, i32 noundef 1536, i8 noundef zeroext 52, i8 noundef zeroext 4, i8 noundef zeroext 0, i8 noundef zeroext 2)
  %75 = load i8, ptr @test_len, align 1, !tbaa !5
  %76 = zext i8 %75 to i32
  %77 = call i32 @check_write(ptr noundef @test_data, i32 noundef %76, i32 noundef 1536)
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %80

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

80:                                               ; preds = %71
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  %82 = load i8, ptr @test_len, align 1, !tbaa !5
  %83 = zext i8 %82 to i32
  call void @write_spiflash(ptr noundef @test_data, i32 noundef %83, i32 noundef 1792, i8 noundef zeroext 62, i8 noundef zeroext 4, i8 noundef zeroext 2, i8 noundef zeroext 2)
  %84 = load i8, ptr @test_len, align 1, !tbaa !5
  %85 = zext i8 %84 to i32
  %86 = call i32 @check_write(ptr noundef @test_data, i32 noundef %85, i32 noundef 1792)
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %89

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

89:                                               ; preds = %80
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %90

90:                                               ; preds = %89, %88, %79, %70, %61, %52, %43, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %91 = load i32, ptr %1, align 4
  ret i32 %91
}

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
@test_data = external hidden global [18 x i8], align 16
@test_len = external hidden local_unnamed_addr global 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

; 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
declare dso_local i32 @check_write(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; 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 %45

3:                                                ; preds = %0
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %5 = load i8, ptr @test_len, align 1, !tbaa !5
  %6 = zext i8 %5 to i32
  tail call void @write_spiflash(ptr noundef nonnull @test_data, i32 noundef %6, i32 noundef 512, i8 noundef zeroext 2, i8 noundef zeroext 3, i8 noundef zeroext 0, i8 noundef zeroext 0)
  %7 = load i8, ptr @test_len, align 1, !tbaa !5
  %8 = zext i8 %7 to i32
  %9 = tail call i32 @check_write(ptr noundef nonnull @test_data, i32 noundef %8, i32 noundef 512)
  %.not9 = icmp eq i32 %9, 0
  br i1 %.not9, label %10, label %45

10:                                               ; preds = %3
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %12 = load i8, ptr @test_len, align 1, !tbaa !5
  %13 = zext i8 %12 to i32
  tail call void @write_spiflash(ptr noundef nonnull @test_data, i32 noundef %13, i32 noundef 768, i8 noundef zeroext 50, i8 noundef zeroext 3, i8 noundef zeroext 0, i8 noundef zeroext 2)
  %14 = load i8, ptr @test_len, align 1, !tbaa !5
  %15 = zext i8 %14 to i32
  %16 = tail call i32 @check_write(ptr noundef nonnull @test_data, i32 noundef %15, i32 noundef 768)
  %.not10 = icmp eq i32 %16, 0
  br i1 %.not10, label %17, label %45

17:                                               ; preds = %10
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %19 = load i8, ptr @test_len, align 1, !tbaa !5
  %20 = zext i8 %19 to i32
  tail call void @write_spiflash(ptr noundef nonnull @test_data, i32 noundef %20, i32 noundef 1024, i8 noundef zeroext 56, i8 noundef zeroext 3, i8 noundef zeroext 2, i8 noundef zeroext 2)
  %21 = load i8, ptr @test_len, align 1, !tbaa !5
  %22 = zext i8 %21 to i32
  %23 = tail call i32 @check_write(ptr noundef nonnull @test_data, i32 noundef %22, i32 noundef 1024)
  %.not11 = icmp eq i32 %23, 0
  br i1 %.not11, label %24, label %45

24:                                               ; preds = %17
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  %26 = load i8, ptr @test_len, align 1, !tbaa !5
  %27 = zext i8 %26 to i32
  tail call void @write_spiflash(ptr noundef nonnull @test_data, i32 noundef %27, i32 noundef 1280, i8 noundef zeroext 18, i8 noundef zeroext 4, i8 noundef zeroext 0, i8 noundef zeroext 0)
  %28 = load i8, ptr @test_len, align 1, !tbaa !5
  %29 = zext i8 %28 to i32
  %30 = tail call i32 @check_write(ptr noundef nonnull @test_data, i32 noundef %29, i32 noundef 1280)
  %.not12 = icmp eq i32 %30, 0
  br i1 %.not12, label %31, label %45

31:                                               ; preds = %24
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  %33 = load i8, ptr @test_len, align 1, !tbaa !5
  %34 = zext i8 %33 to i32
  tail call void @write_spiflash(ptr noundef nonnull @test_data, i32 noundef %34, i32 noundef 1536, i8 noundef zeroext 52, i8 noundef zeroext 4, i8 noundef zeroext 0, i8 noundef zeroext 2)
  %35 = load i8, ptr @test_len, align 1, !tbaa !5
  %36 = zext i8 %35 to i32
  %37 = tail call i32 @check_write(ptr noundef nonnull @test_data, i32 noundef %36, i32 noundef 1536)
  %.not13 = icmp eq i32 %37, 0
  br i1 %.not13, label %38, label %45

38:                                               ; preds = %31
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %40 = load i8, ptr @test_len, align 1, !tbaa !5
  %41 = zext i8 %40 to i32
  tail call void @write_spiflash(ptr noundef nonnull @test_data, i32 noundef %41, i32 noundef 1792, i8 noundef zeroext 62, i8 noundef zeroext 4, i8 noundef zeroext 2, i8 noundef zeroext 2)
  %42 = load i8, ptr @test_len, align 1, !tbaa !5
  %43 = zext i8 %42 to i32
  %44 = tail call i32 @check_write(ptr noundef nonnull @test_data, i32 noundef %43, i32 noundef 1792)
  %.not14 = icmp ne i32 %44, 0
  %. = zext i1 %.not14 to i32
  br label %45

45:                                               ; preds = %38, %31, %24, %17, %10, %3, %0
  %.0 = phi i32 [ 1, %0 ], [ 1, %3 ], [ 1, %10 ], [ 1, %17 ], [ 1, %24 ], [ 1, %31 ], [ %., %38 ]
  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