; LLVM IR from aap/pdp6 :: fe6 (cmd)

; 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.dev = type { ptr, i32, i32, ptr }

@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@devtab = external dso_local global [3 x %struct.dev], align 16
@.str.8 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 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

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

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

declare void @err(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @finddev(ptr noundef) #2

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

11:                                               ; preds = %2
  store ptr @devtab, ptr %7, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %31, %11
  %13 = load ptr, ptr %7, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.dev, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %34

17:                                               ; preds = %12
  %18 = load ptr, ptr %7, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.dev, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = icmp sge i32 %20, 0
  br i1 %21, label %22, label %30

22:                                               ; preds = %17
  %23 = load ptr, ptr %7, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.dev, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = load ptr, ptr %7, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.dev, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, ptr noundef %25, ptr noundef %28)
  br label %30

30:                                               ; preds = %22, %17
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %7, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.dev, ptr %32, i32 1
  store ptr %33, ptr %7, align 8, !tbaa !9
  br label %12, !llvm.loop !15

34:                                               ; preds = %12
  store i32 1, ptr %8, align 4
  br label %86

35:                                               ; preds = %2
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = icmp slt i32 %36, 3
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  call void @err(ptr noundef @.str.9)
  br label %39

39:                                               ; preds = %38, %35
  %40 = load ptr, ptr %4, align 8, !tbaa !9
  %41 = getelementptr inbounds ptr, ptr %40, i64 1
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  store ptr %42, ptr %5, align 8, !tbaa !9
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  %44 = getelementptr inbounds ptr, ptr %43, i64 2
  %45 = load ptr, ptr %44, align 8, !tbaa !9
  store ptr %45, ptr %6, align 8, !tbaa !9
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  %47 = call ptr @finddev(ptr noundef %46)
  store ptr %47, ptr %7, align 8, !tbaa !9
  %48 = load ptr, ptr %7, align 8, !tbaa !9
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %51

50:                                               ; preds = %39
  call void @err(ptr noundef @.str.10)
  br label %51

51:                                               ; preds = %50, %39
  %52 = load ptr, ptr %7, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.dev, ptr %52, i32 0, i32 2
  %54 = load i32, ptr %53, align 4, !tbaa !13
  %55 = icmp sge i32 %54, 0
  br i1 %55, label %56, label %68

56:                                               ; preds = %51
  %57 = load ptr, ptr %7, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.dev, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !13
  %60 = call i32 @close(i32 noundef %59)
  %61 = load ptr, ptr %7, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.dev, ptr %61, i32 0, i32 2
  store i32 -1, ptr %62, align 4, !tbaa !13
  %63 = load ptr, ptr %7, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.dev, ptr %63, i32 0, i32 3
  %65 = load ptr, ptr %64, align 8, !tbaa !14
  call void @free(ptr noundef %65) #4
  %66 = load ptr, ptr %7, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.dev, ptr %66, i32 0, i32 3
  store ptr null, ptr %67, align 8, !tbaa !14
  br label %68

68:                                               ; preds = %56, %51
  %69 = load ptr, ptr %6, align 8, !tbaa !9
  %70 = load ptr, ptr %7, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.dev, ptr %70, i32 0, i32 1
  %72 = load i32, ptr %71, align 8, !tbaa !17
  %73 = call i32 (ptr, i32, ...) @open(ptr noundef %69, i32 noundef %72)
  %74 = load ptr, ptr %7, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.dev, ptr %74, i32 0, i32 2
  store i32 %73, ptr %75, align 4, !tbaa !13
  %76 = load ptr, ptr %7, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.dev, ptr %76, i32 0, i32 2
  %78 = load i32, ptr %77, align 4, !tbaa !13
  %79 = icmp slt i32 %78, 0
  br i1 %79, label %80, label %81

80:                                               ; preds = %68
  call void @err(ptr noundef @.str.4)
  br label %81

81:                                               ; preds = %80, %68
  %82 = load ptr, ptr %6, align 8, !tbaa !9
  %83 = call noalias ptr @strdup(ptr noundef %82) #4
  %84 = load ptr, ptr %7, align 8, !tbaa !9
  %85 = getelementptr inbounds %struct.dev, ptr %84, i32 0, i32 3
  store ptr %83, ptr %85, align 8, !tbaa !14
  store i32 0, ptr %8, align 4
  br label %86

86:                                               ; preds = %81, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %87 = load i32, ptr %8, align 4
  switch i32 %87, label %89 [
    i32 0, label %88
    i32 1, label %88
  ]

88:                                               ; preds = %86, %86
  ret void

89:                                               ; preds = %86
  unreachable
}

declare i32 @close(i32 noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

declare i32 @open(ptr noundef, i32 noundef, ...) #1

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { 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 }

!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 = !{!12, !10, i64 0}
!12 = !{!"dev", !10, i64 0, !6, i64 8, !6, i64 12, !10, i64 16}
!13 = !{!12, !6, i64 12}
!14 = !{!12, !10, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !6, 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"

%struct.dev = type { ptr, i32, i32, ptr }

@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@devtab = external dso_local local_unnamed_addr global [3 x %struct.dev], align 16
@.str.8 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1

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

declare void @err(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @finddev(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @c_mount(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  %3 = icmp eq i32 %0, 1
  br i1 %3, label %.preheader, label %16

.preheader:                                       ; preds = %2
  %4 = load ptr, ptr @devtab, align 16, !tbaa !5
  %.not24 = icmp eq ptr %4, null
  br i1 %.not24, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %13
  %5 = phi ptr [ %15, %13 ], [ %4, %.preheader ]
  %.025 = phi ptr [ %14, %13 ], [ @devtab, %.preheader ]
  %6 = getelementptr inbounds i8, ptr %.025, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = icmp sgt i32 %7, -1
  br i1 %8, label %9, label %13

9:                                                ; preds = %.lr.ph
  %10 = getelementptr inbounds i8, ptr %.025, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef nonnull %5, ptr noundef %11)
  br label %13

13:                                               ; preds = %.lr.ph, %9
  %14 = getelementptr inbounds i8, ptr %.025, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %.not = icmp eq ptr %15, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !13

16:                                               ; preds = %2
  %17 = icmp slt i32 %0, 3
  br i1 %17, label %18, label %19

18:                                               ; preds = %16
  tail call void @err(ptr noundef nonnull @.str.9) #6
  br label %19

19:                                               ; preds = %18, %16
  %20 = getelementptr inbounds i8, ptr %1, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %1, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = tail call ptr @finddev(ptr noundef %21)
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %19
  tail call void @err(ptr noundef nonnull @.str.10) #6
  br label %27

27:                                               ; preds = %26, %19
  %28 = getelementptr inbounds i8, ptr %24, i64 12
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = icmp sgt i32 %29, -1
  br i1 %30, label %31, label %35

31:                                               ; preds = %27
  %32 = tail call i32 @close(i32 noundef %29) #6
  store i32 -1, ptr %28, align 4, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %24, i64 16
  %34 = load ptr, ptr %33, align 8, !tbaa !12
  tail call void @free(ptr noundef %34) #6
  store ptr null, ptr %33, align 8, !tbaa !12
  br label %35

35:                                               ; preds = %31, %27
  %36 = getelementptr inbounds i8, ptr %24, i64 8
  %37 = load i32, ptr %36, align 8, !tbaa !16
  %38 = tail call i32 (ptr, i32, ...) @open(ptr noundef %23, i32 noundef %37) #6
  store i32 %38, ptr %28, align 4, !tbaa !11
  %39 = icmp slt i32 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %35
  tail call void @err(ptr noundef nonnull @.str.4) #6
  br label %41

41:                                               ; preds = %40, %35
  %42 = tail call noalias ptr @strdup(ptr noundef %23) #6
  %43 = getelementptr inbounds i8, ptr %24, i64 16
  store ptr %42, ptr %43, align 8, !tbaa !12
  br label %.loopexit

.loopexit:                                        ; preds = %13, %.preheader, %41
  ret void
}

declare i32 @close(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nofree
declare noundef i32 @open(ptr nocapture noundef readonly, i32 noundef, ...) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #5

attributes #0 = { 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 #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 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nofree "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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #6 = { 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 0}
!6 = !{!"dev", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !7, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!7, !7, i64 0}
!16 = !{!6, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass