; LLVM IR from bitbank2/AnimatedGIF :: examples/gif_from_spi_flash (ff)

; 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.DIR = type { %struct.FFOBJID, i32, i32, i32, ptr, [12 x i8] }
%struct.FFOBJID = type { ptr, i16, i8, i8, i32, i32 }
%struct.FATFS = type { i8, i8, i8, i8, i8, i16, i16, i16, i32, i32, i32, i32, i32, i32, i32, i32, i32, [512 x i8] }

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

; Function Attrs: nounwind uwtable
declare hidden i32 @find_volume(ptr noundef, ptr noundef, i8 noundef zeroext) #1

; 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 i32 @follow_path(ptr noundef, ptr noundef) #1

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

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

11:                                               ; preds = %2
  store i32 9, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %80

12:                                               ; preds = %2
  %13 = call i32 @find_volume(ptr noundef %5, ptr noundef %7, i8 noundef zeroext 0)
  store i32 %13, ptr %6, align 4, !tbaa !9
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %71

16:                                               ; preds = %12
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.DIR, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds %struct.FFOBJID, ptr %19, i32 0, i32 0
  store ptr %17, ptr %20, align 8, !tbaa !11
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call i32 @follow_path(ptr noundef %21, ptr noundef %22)
  store i32 %23, ptr %6, align 4, !tbaa !9
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %66

26:                                               ; preds = %16
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.DIR, ptr %27, i32 0, i32 5
  %29 = getelementptr inbounds [12 x i8], ptr %28, i64 0, i64 11
  %30 = load i8, ptr %29, align 1, !tbaa !15
  %31 = zext i8 %30 to i32
  %32 = and i32 %31, 128
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %53, label %34

34:                                               ; preds = %26
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.DIR, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds %struct.FFOBJID, ptr %36, i32 0, i32 2
  %38 = load i8, ptr %37, align 2, !tbaa !16
  %39 = zext i8 %38 to i32
  %40 = and i32 %39, 16
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %51

42:                                               ; preds = %34
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.DIR, ptr %44, i32 0, i32 4
  %46 = load ptr, ptr %45, align 8, !tbaa !17
  %47 = call i32 @ld_clust(ptr noundef %43, ptr noundef %46)
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.DIR, ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds %struct.FFOBJID, ptr %49, i32 0, i32 4
  store i32 %47, ptr %50, align 4, !tbaa !18
  br label %52

51:                                               ; preds = %34
  store i32 5, ptr %6, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %51, %42
  br label %53

53:                                               ; preds = %52, %26
  %54 = load i32, ptr %6, align 4, !tbaa !9
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %65

56:                                               ; preds = %53
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.FATFS, ptr %57, i32 0, i32 5
  %59 = load i16, ptr %58, align 2, !tbaa !19
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.DIR, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds %struct.FFOBJID, ptr %61, i32 0, i32 1
  store i16 %59, ptr %62, align 8, !tbaa !21
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = call i32 @dir_sdi(ptr noundef %63, i32 noundef 0)
  store i32 %64, ptr %6, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %56, %53
  br label %66

66:                                               ; preds = %65, %16
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = icmp eq i32 %67, 4
  br i1 %68, label %69, label %70

69:                                               ; preds = %66
  store i32 5, ptr %6, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %69, %66
  br label %71

71:                                               ; preds = %70, %12
  %72 = load i32, ptr %6, align 4, !tbaa !9
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %78

74:                                               ; preds = %71
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.DIR, ptr %75, i32 0, i32 0
  %77 = getelementptr inbounds %struct.FFOBJID, ptr %76, i32 0, i32 0
  store ptr null, ptr %77, align 8, !tbaa !11
  br label %78

78:                                               ; preds = %74, %71
  %79 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %79, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %80

80:                                               ; preds = %78, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %81 = load i32, ptr %3, align 4
  ret i32 %81
}

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

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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !13, i64 0, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !7, i64 48}
!13 = !{!"", !6, i64 0, !14, i64 8, !7, i64 10, !7, i64 11, !10, i64 12, !10, i64 16}
!14 = !{!"short", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !7, i64 10}
!17 = !{!12, !6, i64 40}
!18 = !{!12, !10, i64 12}
!19 = !{!20, !14, i64 6}
!20 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !14, i64 6, !14, i64 8, !14, i64 10, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !7, i64 48}
!21 = !{!12, !14, i64 8}


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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @find_volume(ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: mustprogress 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 i32 @follow_path(ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @f_opendir(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %33, label %5

5:                                                ; preds = %2
  %6 = call i32 @find_volume(ptr noundef nonnull %3, ptr noundef nonnull %4, i8 noundef zeroext 0)
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %.thread29

8:                                                ; preds = %5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %9, ptr %0, align 8, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call i32 @follow_path(ptr noundef nonnull %0, ptr noundef %10)
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %32

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 59
  %15 = load i8, ptr %14, align 1, !tbaa !14
  %.not21 = icmp sgt i8 %15, -1
  br i1 %.not21, label %16, label %26

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %0, i64 10
  %18 = load i8, ptr %17, align 2, !tbaa !15
  %19 = and i8 %18, 16
  %.not22 = icmp eq i8 %19, 0
  br i1 %.not22, label %.thread29, label %20

20:                                               ; preds = %16
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %0, i64 40
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = call i32 @ld_clust(ptr noundef %21, ptr noundef %23)
  %25 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %24, ptr %25, align 4, !tbaa !17
  br label %26

26:                                               ; preds = %13, %20
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 6
  %29 = load i16, ptr %28, align 2, !tbaa !18
  %30 = getelementptr inbounds i8, ptr %0, i64 8
  store i16 %29, ptr %30, align 8, !tbaa !20
  %31 = call i32 @dir_sdi(ptr noundef nonnull %0, i32 noundef 0)
  br label %32

32:                                               ; preds = %26, %8
  %.1 = phi i32 [ %31, %26 ], [ %11, %8 ]
  %.1.fr = freeze i32 %.1
  switch i32 %.1.fr, label %.thread29.fold.split [
    i32 4, label %.thread29
    i32 0, label %33
  ]

.thread29.fold.split:                             ; preds = %32
  br label %.thread29

.thread29:                                        ; preds = %32, %.thread29.fold.split, %16, %5
  %.232 = phi i32 [ %6, %5 ], [ 5, %16 ], [ 5, %32 ], [ %.1.fr, %.thread29.fold.split ]
  store ptr null, ptr %0, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %32, %.thread29, %2
  %.016 = phi i32 [ 9, %2 ], [ %.232, %.thread29 ], [ %.1.fr, %32 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  ret i32 %.016
}

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

attributes #0 = { mustprogress 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 = { 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, !6, i64 0}
!10 = !{!"", !11, i64 0, !13, i64 24, !13, i64 28, !13, i64 32, !6, i64 40, !7, i64 48}
!11 = !{!"", !6, i64 0, !12, i64 8, !7, i64 10, !7, i64 11, !13, i64 12, !13, i64 16}
!12 = !{!"short", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!10, !7, i64 10}
!16 = !{!10, !6, i64 40}
!17 = !{!10, !13, i64 12}
!18 = !{!19, !12, i64 6}
!19 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !12, i64 6, !12, i64 8, !12, i64 10, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !7, i64 48}
!20 = !{!10, !12, i64 8}


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