; LLVM IR from vul337/PrIntFuzz :: config/linux/firmware/carl9170fw/tools/src (miniboot)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store ptr null, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 3
  br i1 %10, label %14, label %11

11:                                               ; preds = %2
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp sgt i32 %12, 4
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %2
  store i32 -22, ptr %7, align 4, !tbaa !5
  br label %71

15:                                               ; preds = %11
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds ptr, ptr %16, i64 1
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %18, i64 0
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = sext i8 %20 to i32
  switch i32 %21, label %63 [
    i32 97, label %22
    i32 100, label %44
  ]

22:                                               ; preds = %15
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = icmp ne i32 %23, 4
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  br label %71

26:                                               ; preds = %22
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  %28 = getelementptr inbounds ptr, ptr %27, i64 2
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = call ptr @carlfw_load(ptr noundef %29)
  store ptr %30, ptr %6, align 8, !tbaa !9
  %31 = load ptr, ptr %6, align 8, !tbaa !9
  %32 = call i64 @IS_ERR_OR_NULL(ptr noundef %31)
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %38

34:                                               ; preds = %26
  %35 = load ptr, ptr %6, align 8, !tbaa !9
  %36 = call i64 @PTR_ERR(ptr noundef %35)
  %37 = trunc i64 %36 to i32
  store i32 %37, ptr %7, align 4, !tbaa !5
  br label %66

38:                                               ; preds = %26
  %39 = load ptr, ptr %6, align 8, !tbaa !9
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds ptr, ptr %40, i64 3
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = call i32 @add_mini(ptr noundef %39, ptr noundef %42)
  store i32 %43, ptr %7, align 4, !tbaa !5
  br label %64

44:                                               ; preds = %15
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = icmp ne i32 %45, 3
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  br label %71

48:                                               ; preds = %44
  %49 = load ptr, ptr %5, align 8, !tbaa !9
  %50 = getelementptr inbounds ptr, ptr %49, i64 2
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = call ptr @carlfw_load(ptr noundef %51)
  store ptr %52, ptr %6, align 8, !tbaa !9
  %53 = load ptr, ptr %6, align 8, !tbaa !9
  %54 = call i64 @IS_ERR_OR_NULL(ptr noundef %53)
  %55 = icmp ne i64 %54, 0
  br i1 %55, label %56, label %60

56:                                               ; preds = %48
  %57 = load ptr, ptr %6, align 8, !tbaa !9
  %58 = call i64 @PTR_ERR(ptr noundef %57)
  %59 = trunc i64 %58 to i32
  store i32 %59, ptr %7, align 4, !tbaa !5
  br label %66

60:                                               ; preds = %48
  %61 = load ptr, ptr %6, align 8, !tbaa !9
  %62 = call i32 @del_mini(ptr noundef %61)
  store i32 %62, ptr %7, align 4, !tbaa !5
  br label %64

63:                                               ; preds = %15
  br label %71

64:                                               ; preds = %60, %38
  %65 = load ptr, ptr %6, align 8, !tbaa !9
  call void @carlfw_release(ptr noundef %65)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %73

66:                                               ; preds = %56, %34
  %67 = load ptr, ptr %6, align 8, !tbaa !9
  call void @carlfw_release(ptr noundef %67)
  %68 = load ptr, ptr @stderr, align 8, !tbaa !9
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef @.str, i32 noundef %69) #5
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %73

71:                                               ; preds = %63, %47, %25, %14
  %72 = load ptr, ptr %6, align 8, !tbaa !9
  call void @carlfw_release(ptr noundef %72)
  call void @mini_help()
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %73

73:                                               ; preds = %71, %66, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %74 = load i32, ptr %3, align 4
  ret i32 %74
}

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

declare ptr @carlfw_load(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @IS_ERR_OR_NULL(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @PTR_ERR(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @add_mini(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @del_mini(ptr noundef) #0

declare void @carlfw_release(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #4

; Function Attrs: nounwind uwtable
declare hidden void @mini_help() #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = { inlinehint 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 #4 = { 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" }
attributes #5 = { 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = add i32 %0, -5
  %or.cond = icmp ult i32 %3, -2
  br i1 %or.cond, label %31, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = load i8, ptr %6, align 1, !tbaa !9
  switch i8 %7, label %31 [
    i8 97, label %8
    i8 100, label %18
  ]

8:                                                ; preds = %4
  %.not23 = icmp eq i32 %0, 4
  br i1 %.not23, label %9, label %31

9:                                                ; preds = %8
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = tail call ptr @carlfw_load(ptr noundef %11) #4
  %13 = tail call i64 @IS_ERR_OR_NULL(ptr noundef %12)
  %.not24 = icmp eq i64 %13, 0
  br i1 %.not24, label %14, label %27

14:                                               ; preds = %9
  %15 = getelementptr inbounds i8, ptr %1, i64 24
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = tail call i32 @add_mini(ptr noundef %12, ptr noundef %16)
  br label %26

18:                                               ; preds = %4
  %.not = icmp eq i32 %0, 3
  br i1 %.not, label %19, label %31

19:                                               ; preds = %18
  %20 = getelementptr inbounds i8, ptr %1, i64 16
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = tail call ptr @carlfw_load(ptr noundef %21) #4
  %23 = tail call i64 @IS_ERR_OR_NULL(ptr noundef %22)
  %.not22 = icmp eq i64 %23, 0
  br i1 %.not22, label %24, label %27

24:                                               ; preds = %19
  %25 = tail call i32 @del_mini(ptr noundef %22)
  br label %26

26:                                               ; preds = %24, %14
  %.019 = phi ptr [ %22, %24 ], [ %12, %14 ]
  tail call void @carlfw_release(ptr noundef %.019) #4
  br label %32

27:                                               ; preds = %19, %9
  %.sink = phi ptr [ %12, %9 ], [ %22, %19 ]
  %28 = tail call i64 @PTR_ERR(ptr noundef %.sink)
  %.0 = trunc i64 %28 to i32
  tail call void @carlfw_release(ptr noundef %.sink) #4
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str, i32 noundef %.0) #5
  br label %32

31:                                               ; preds = %2, %4, %18, %8
  tail call void @carlfw_release(ptr noundef null) #4
  tail call void @mini_help()
  br label %32

32:                                               ; preds = %31, %27, %26
  %.020 = phi i32 [ 1, %31 ], [ 1, %27 ], [ 0, %26 ]
  ret i32 %.020
}

declare ptr @carlfw_load(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @IS_ERR_OR_NULL(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @PTR_ERR(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @add_mini(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @del_mini(ptr noundef) local_unnamed_addr #0

declare void @carlfw_release(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden void @mini_help() local_unnamed_addr #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 = { "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 = { inlinehint 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 = { 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" }
attributes #4 = { nounwind }
attributes #5 = { cold 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 = !{!7, !7, i64 0}


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