; LLVM IR from MiRoboticsLab/cyberdog_ros2 :: cyberdog_interaction/cyberdog_touch/src (TouchSensorHandler)

; 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.dirent = type { i64, i64, i16, i8, [256 x i8] }

@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN18TouchSensorHandler9openInputEv(ptr noundef nonnull align 8 dereferenceable(80) %0) #0 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [4096 x i8], align 16
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca [80 x i8], align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  %14 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 -1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store ptr @.str.1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4096, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call ptr @opendir(ptr noundef %15)
  store ptr %16, ptr %8, align 8, !tbaa !5
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %1
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %10, align 4
  br label %102

20:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 8, ptr %11, align 8, !tbaa !11
  %21 = getelementptr inbounds [4096 x i8], ptr %6, i64 0, i64 0
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load i64, ptr %11, align 8, !tbaa !11
  %24 = call ptr @strncpy(ptr noundef %21, ptr noundef %22, i64 noundef %23) #5
  %25 = getelementptr inbounds [4096 x i8], ptr %6, i64 0, i64 0
  %26 = getelementptr inbounds [4096 x i8], ptr %6, i64 0, i64 0
  %27 = call i64 @strlen(ptr noundef %26) #6
  %28 = getelementptr inbounds i8, ptr %25, i64 %27
  store ptr %28, ptr %7, align 8, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i32 1
  store ptr %30, ptr %7, align 8, !tbaa !5
  store i8 47, ptr %29, align 1, !tbaa !13
  br label %31

31:                                               ; preds = %97, %63, %20
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = call ptr @readdir(ptr noundef %32)
  store ptr %33, ptr %9, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %98

35:                                               ; preds = %31
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.dirent, ptr %36, i32 0, i32 4
  %38 = getelementptr inbounds [256 x i8], ptr %37, i64 0, i64 0
  %39 = load i8, ptr %38, align 1, !tbaa !13
  %40 = sext i8 %39 to i32
  %41 = icmp eq i32 %40, 46
  br i1 %41, label %42, label %64

42:                                               ; preds = %35
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.dirent, ptr %43, i32 0, i32 4
  %45 = getelementptr inbounds [256 x i8], ptr %44, i64 0, i64 1
  %46 = load i8, ptr %45, align 1, !tbaa !13
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %63, label %49

49:                                               ; preds = %42
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.dirent, ptr %50, i32 0, i32 4
  %52 = getelementptr inbounds [256 x i8], ptr %51, i64 0, i64 1
  %53 = load i8, ptr %52, align 1, !tbaa !13
  %54 = sext i8 %53 to i32
  %55 = icmp eq i32 %54, 46
  br i1 %55, label %56, label %64

56:                                               ; preds = %49
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.dirent, ptr %57, i32 0, i32 4
  %59 = getelementptr inbounds [256 x i8], ptr %58, i64 0, i64 2
  %60 = load i8, ptr %59, align 1, !tbaa !13
  %61 = sext i8 %60 to i32
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %56, %42
  br label %31, !llvm.loop !14

64:                                               ; preds = %56, %49, %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store i64 256, ptr %12, align 8, !tbaa !11
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.dirent, ptr %66, i32 0, i32 4
  %68 = getelementptr inbounds [256 x i8], ptr %67, i64 0, i64 0
  %69 = load i64, ptr %12, align 8, !tbaa !11
  %70 = call ptr @strncpy(ptr noundef %65, ptr noundef %68, i64 noundef %69) #5
  %71 = getelementptr inbounds [4096 x i8], ptr %6, i64 0, i64 0
  %72 = call i32 (ptr, i32, ...) @open(ptr noundef %71, i32 noundef 2)
  store i32 %72, ptr %4, align 4, !tbaa !9
  %73 = load i32, ptr %4, align 4, !tbaa !9
  %74 = icmp sge i32 %73, 0
  br i1 %74, label %75, label %93

75:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 80, ptr %13) #5
  %76 = load i32, ptr %4, align 4, !tbaa !9
  %77 = call i32 (i32, i64, ...) @ioctl(i32 noundef %76, i64 noundef 2152678662, ptr noundef %13) #5
  %78 = icmp slt i32 %77, 1
  br i1 %78, label %79, label %81

79:                                               ; preds = %75
  %80 = getelementptr inbounds [80 x i8], ptr %13, i64 0, i64 0
  store i8 0, ptr %80, align 16, !tbaa !13
  br label %81

81:                                               ; preds = %79, %75
  %82 = getelementptr inbounds [80 x i8], ptr %13, i64 0, i64 0
  %83 = call i32 @strcmp(ptr noundef %82, ptr noundef @.str.2) #6
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %86, label %85

85:                                               ; preds = %81
  store i32 3, ptr %10, align 4
  br label %90

86:                                               ; preds = %81
  %87 = load i32, ptr %4, align 4, !tbaa !9
  %88 = call i32 @close(i32 noundef %87)
  store i32 -1, ptr %4, align 4, !tbaa !9
  br label %89

89:                                               ; preds = %86
  store i32 0, ptr %10, align 4
  br label %90

90:                                               ; preds = %89, %85
  call void @llvm.lifetime.end.p0(i64 80, ptr %13) #5
  %91 = load i32, ptr %10, align 4
  switch i32 %91, label %95 [
    i32 0, label %92
  ]

92:                                               ; preds = %90
  br label %94

93:                                               ; preds = %64
  br label %94

94:                                               ; preds = %93, %92
  store i32 0, ptr %10, align 4
  br label %95

95:                                               ; preds = %94, %90
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %96 = load i32, ptr %10, align 4
  switch i32 %96, label %104 [
    i32 0, label %97
    i32 3, label %98
  ]

97:                                               ; preds = %95
  br label %31, !llvm.loop !14

98:                                               ; preds = %95, %31
  %99 = load ptr, ptr %8, align 8, !tbaa !5
  %100 = call i32 @closedir(ptr noundef %99)
  %101 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %101, ptr %2, align 4
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %102

102:                                              ; preds = %98, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4096, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %103 = load i32, ptr %2, align 4
  ret i32 %103

104:                                              ; preds = %95
  unreachable
}

declare i32 @close(i32 noundef) #1

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

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

declare ptr @opendir(ptr noundef) #1

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

declare ptr @readdir(ptr noundef) #1

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

; Function Attrs: nounwind
declare i32 @ioctl(i32 noundef, i64 noundef, ...) #3

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #4

declare i32 @closedir(ptr noundef) #1

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

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN18TouchSensorHandler9openInputEv(ptr nocapture noundef nonnull readnone align 8 dereferenceable(80) %0) local_unnamed_addr #0 align 2 {
  %2 = alloca [4096 x i8], align 16
  %3 = alloca [80 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %2) #8
  %4 = tail call ptr @opendir(ptr noundef nonnull @.str.1)
  %5 = icmp eq ptr %4, null
  br i1 %5, label %42, label %6

6:                                                ; preds = %1
  %7 = call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef 8) #8
  %8 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #9
  %9 = getelementptr inbounds i8, ptr %2, i64 %8
  %10 = getelementptr inbounds i8, ptr %9, i64 1
  store i8 47, ptr %9, align 1, !tbaa !5
  %11 = call ptr @readdir(ptr noundef nonnull %4)
  %.not4143 = icmp eq ptr %11, null
  br i1 %.not4143, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %6, %.outer
  %12 = phi ptr [ %40, %.outer ], [ %11, %6 ]
  %.021.ph44 = phi i32 [ %.3, %.outer ], [ -1, %6 ]
  br label %13

13:                                               ; preds = %.lr.ph, %25
  %14 = phi ptr [ %12, %.lr.ph ], [ %26, %25 ]
  %15 = getelementptr inbounds i8, ptr %14, i64 19
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = icmp eq i8 %16, 46
  br i1 %17, label %18, label %27

18:                                               ; preds = %13
  %19 = getelementptr inbounds i8, ptr %14, i64 20
  %20 = load i8, ptr %19, align 1, !tbaa !5
  switch i8 %20, label %27 [
    i8 0, label %25
    i8 46, label %21
  ]

21:                                               ; preds = %18
  %22 = getelementptr inbounds i8, ptr %14, i64 21
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = icmp eq i8 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %18, %21
  %26 = call ptr @readdir(ptr noundef nonnull %4)
  %.not = icmp eq ptr %26, null
  br i1 %.not, label %.loopexit, label %13, !llvm.loop !8

27:                                               ; preds = %18, %21, %13
  %28 = getelementptr inbounds i8, ptr %14, i64 19
  %29 = call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %10, ptr noundef nonnull dereferenceable(1) %28, i64 noundef 256) #8
  %30 = call i32 (ptr, i32, ...) @open(ptr noundef nonnull %2, i32 noundef 2)
  %31 = icmp sgt i32 %30, -1
  br i1 %31, label %32, label %.outer

32:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %3) #8
  %33 = call i32 (i32, i64, ...) @ioctl(i32 noundef %30, i64 noundef 2152678662, ptr noundef nonnull %3) #8
  %34 = icmp slt i32 %33, 1
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  store i8 0, ptr %3, align 16, !tbaa !5
  br label %36

36:                                               ; preds = %35, %32
  %37 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str.2) #9
  %.not29.not = icmp eq i32 %37, 0
  br i1 %.not29.not, label %.thread34, label %38

38:                                               ; preds = %36
  %39 = call i32 @close(i32 noundef %30)
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %3) #8
  br label %.outer

.thread34:                                        ; preds = %36
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %3) #8
  br label %.loopexit

.outer:                                           ; preds = %38, %27
  %.3 = phi i32 [ %30, %27 ], [ -1, %38 ]
  %40 = call ptr @readdir(ptr noundef nonnull %4)
  %.not41 = icmp eq ptr %40, null
  br i1 %.not41, label %.loopexit, label %.lr.ph

.loopexit:                                        ; preds = %.outer, %25, %6, %.thread34
  %.4 = phi i32 [ %30, %.thread34 ], [ -1, %6 ], [ %.021.ph44, %25 ], [ %.3, %.outer ]
  %41 = call i32 @closedir(ptr noundef nonnull %4)
  br label %42

42:                                               ; preds = %1, %.loopexit
  %.0 = phi i32 [ %.4, %.loopexit ], [ -1, %1 ]
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %2) #8
  ret i32 %.0
}

declare i32 @close(i32 noundef) local_unnamed_addr #1

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

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @opendir(ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #5

declare ptr @readdir(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind
declare i32 @ioctl(i32 noundef, i64 noundef, ...) local_unnamed_addr #7

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: nofree nounwind
declare noundef i32 @closedir(ptr nocapture noundef) local_unnamed_addr #3

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

!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++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass