; LLVM IR from SvrAdityaReddy/RTOS :: Assignment_2/asynchronous_inputs (asynchronous_input)

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

@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [29 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [4 x i32], align 16
  %3 = alloca i32, align 4
  %4 = alloca [4 x i32], align 16
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  %5 = call i32 @sysfs_gpio_export(i32 noundef 14)
  %6 = call i32 @sysfs_gpio_export(i32 noundef 24)
  %7 = call i32 @sysfs_gpio_export(i32 noundef 18)
  %8 = call i32 @sysfs_gpio_export(i32 noundef 23)
  %9 = call i32 @usleep(i32 noundef 500000)
  %10 = call i32 @sysfs_gpio_set_direction(i32 noundef 14, i32 noundef 1)
  %11 = call i32 @sysfs_gpio_set_direction(i32 noundef 24, i32 noundef 1)
  %12 = call i32 @sysfs_gpio_set_direction(i32 noundef 18, i32 noundef 1)
  %13 = call i32 @sysfs_gpio_set_direction(i32 noundef 23, i32 noundef 1)
  %14 = call i32 @sysfs_gpio_get(i32 noundef 14)
  %15 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 0
  store i32 %14, ptr %15, align 16, !tbaa !5
  %16 = call i32 @sysfs_gpio_get(i32 noundef 24)
  %17 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 1
  store i32 %16, ptr %17, align 4, !tbaa !5
  %18 = call i32 @sysfs_gpio_get(i32 noundef 18)
  %19 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 2
  store i32 %18, ptr %19, align 8, !tbaa !5
  %20 = call i32 @sysfs_gpio_get(i32 noundef 23)
  %21 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 3
  store i32 %20, ptr %21, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %73, %0
  br label %23

23:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #3
  %24 = call i32 @sysfs_gpio_get(i32 noundef 14)
  %25 = getelementptr inbounds [4 x i32], ptr %4, i64 0, i64 0
  store i32 %24, ptr %25, align 16, !tbaa !5
  %26 = call i32 @sysfs_gpio_get(i32 noundef 24)
  %27 = getelementptr inbounds [4 x i32], ptr %4, i64 0, i64 1
  store i32 %26, ptr %27, align 4, !tbaa !5
  %28 = call i32 @sysfs_gpio_get(i32 noundef 18)
  %29 = getelementptr inbounds [4 x i32], ptr %4, i64 0, i64 2
  store i32 %28, ptr %29, align 8, !tbaa !5
  %30 = call i32 @sysfs_gpio_get(i32 noundef 23)
  %31 = getelementptr inbounds [4 x i32], ptr %4, i64 0, i64 3
  store i32 %30, ptr %31, align 4, !tbaa !5
  %32 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 0
  %33 = getelementptr inbounds [4 x i32], ptr %4, i64 0, i64 0
  %34 = call i32 @match_states(ptr noundef %32, ptr noundef %33)
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %73, label %36

36:                                               ; preds = %23
  %37 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 0
  %38 = load i32, ptr %37, align 16, !tbaa !5
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %38)
  %40 = getelementptr inbounds [4 x i32], ptr %4, i64 0, i64 0
  %41 = load i32, ptr %40, align 16, !tbaa !5
  %42 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 0
  store i32 %41, ptr %42, align 16, !tbaa !5
  %43 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 0
  %44 = load i32, ptr %43, align 16, !tbaa !5
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %44)
  %46 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 1
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %47)
  %49 = getelementptr inbounds [4 x i32], ptr %4, i64 0, i64 1
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 1
  store i32 %50, ptr %51, align 4, !tbaa !5
  %52 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 1
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %53)
  %55 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 2
  %56 = load i32, ptr %55, align 8, !tbaa !5
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %56)
  %58 = getelementptr inbounds [4 x i32], ptr %4, i64 0, i64 2
  %59 = load i32, ptr %58, align 8, !tbaa !5
  %60 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 2
  store i32 %59, ptr %60, align 8, !tbaa !5
  %61 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 2
  %62 = load i32, ptr %61, align 8, !tbaa !5
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %62)
  %64 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 3
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %65)
  %67 = getelementptr inbounds [4 x i32], ptr %4, i64 0, i64 3
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 3
  store i32 %68, ptr %69, align 4, !tbaa !5
  %70 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 3
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %71)
  br label %73

73:                                               ; preds = %36, %23
  %74 = call i32 @usleep(i32 noundef 500000)
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #3
  br label %22
}

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

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

declare i32 @usleep(i32 noundef) #2

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

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

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

; 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 = { 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"}


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

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

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca [4 x i32], align 16
  %2 = alloca [4 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #5
  %3 = tail call i32 @sysfs_gpio_export(i32 noundef 14)
  %4 = tail call i32 @sysfs_gpio_export(i32 noundef 24)
  %5 = tail call i32 @sysfs_gpio_export(i32 noundef 18)
  %6 = tail call i32 @sysfs_gpio_export(i32 noundef 23)
  %7 = tail call i32 @usleep(i32 noundef 500000) #5
  %8 = tail call i32 @sysfs_gpio_set_direction(i32 noundef 14, i32 noundef 1)
  %9 = tail call i32 @sysfs_gpio_set_direction(i32 noundef 24, i32 noundef 1)
  %10 = tail call i32 @sysfs_gpio_set_direction(i32 noundef 18, i32 noundef 1)
  %11 = tail call i32 @sysfs_gpio_set_direction(i32 noundef 23, i32 noundef 1)
  %12 = tail call i32 @sysfs_gpio_get(i32 noundef 14)
  store i32 %12, ptr %1, align 16, !tbaa !5
  %13 = tail call i32 @sysfs_gpio_get(i32 noundef 24)
  %14 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %13, ptr %14, align 4, !tbaa !5
  %15 = tail call i32 @sysfs_gpio_get(i32 noundef 18)
  %16 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %15, ptr %16, align 8, !tbaa !5
  %17 = tail call i32 @sysfs_gpio_get(i32 noundef 23)
  %18 = getelementptr inbounds i8, ptr %1, i64 12
  store i32 %17, ptr %18, align 4, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %2, i64 4
  %20 = getelementptr inbounds i8, ptr %2, i64 8
  %21 = getelementptr inbounds i8, ptr %2, i64 12
  br label %22

22:                                               ; preds = %45, %0
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #5
  %23 = call i32 @sysfs_gpio_get(i32 noundef 14)
  store i32 %23, ptr %2, align 16, !tbaa !5
  %24 = call i32 @sysfs_gpio_get(i32 noundef 24)
  store i32 %24, ptr %19, align 4, !tbaa !5
  %25 = call i32 @sysfs_gpio_get(i32 noundef 18)
  store i32 %25, ptr %20, align 8, !tbaa !5
  %26 = call i32 @sysfs_gpio_get(i32 noundef 23)
  store i32 %26, ptr %21, align 4, !tbaa !5
  %27 = call i32 @match_states(ptr noundef nonnull %1, ptr noundef nonnull %2)
  %.not = icmp eq i32 %27, 0
  br i1 %.not, label %28, label %45

28:                                               ; preds = %22
  %29 = load i32, ptr %1, align 16, !tbaa !5
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %29)
  %31 = load i32, ptr %2, align 16, !tbaa !5
  store i32 %31, ptr %1, align 16, !tbaa !5
  %32 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %31)
  %33 = load i32, ptr %14, align 4, !tbaa !5
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %33)
  %35 = load i32, ptr %19, align 4, !tbaa !5
  store i32 %35, ptr %14, align 4, !tbaa !5
  %36 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %35)
  %37 = load i32, ptr %16, align 8, !tbaa !5
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %37)
  %39 = load i32, ptr %20, align 8, !tbaa !5
  store i32 %39, ptr %16, align 8, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %39)
  %41 = load i32, ptr %18, align 4, !tbaa !5
  %42 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %41)
  %43 = load i32, ptr %21, align 4, !tbaa !5
  store i32 %43, ptr %18, align 4, !tbaa !5
  %44 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %43)
  br label %45

45:                                               ; preds = %28, %22
  %46 = call i32 @usleep(i32 noundef 500000) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #5
  br label %22
}

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

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

declare i32 @usleep(i32 noundef) local_unnamed_addr #3

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

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

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

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

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


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