; LLVM IR from googlecreativelab/open-nsynth-super :: app/open-nsynth/src/AnalogInput.ll (ZN11AnalogInput6updateEhbb)

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

%class.AnalogInput = type { i8, i8 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN11AnalogInput6updateEhbb(ptr noundef nonnull align 1 dereferenceable(2) %0, i8 noundef zeroext %1, i1 noundef zeroext %2, i1 noundef zeroext %3) #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  %11 = zext i1 %2 to i8
  store i8 %11, ptr %7, align 1, !tbaa !10
  %12 = zext i1 %3 to i8
  store i8 %12, ptr %8, align 1, !tbaa !10
  %13 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %14 = load i8, ptr %7, align 1, !tbaa !10, !range !12, !noundef !13
  %15 = trunc i8 %14 to i1
  br i1 %15, label %16, label %24

16:                                               ; preds = %4
  %17 = load i8, ptr %6, align 1, !tbaa !9
  %18 = zext i8 %17 to i32
  %19 = getelementptr inbounds %class.AnalogInput, ptr %13, i32 0, i32 1
  %20 = load i8, ptr %19, align 1, !tbaa !14
  %21 = zext i8 %20 to i32
  %22 = icmp ne i32 %18, %21
  %23 = zext i1 %22 to i8
  store i8 %23, ptr %9, align 1, !tbaa !10
  br label %45

24:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %25 = load i8, ptr %6, align 1, !tbaa !9
  %26 = zext i8 %25 to i32
  %27 = getelementptr inbounds %class.AnalogInput, ptr %13, i32 0, i32 0
  %28 = load i8, ptr %27, align 1, !tbaa !16
  %29 = zext i8 %28 to i32
  %30 = sub nsw i32 %26, %29
  %31 = call i32 @llvm.abs.i32(i32 %30, i1 true)
  store i32 %31, ptr %10, align 4, !tbaa !17
  %32 = load i8, ptr %8, align 1, !tbaa !10, !range !12, !noundef !13
  %33 = trunc i8 %32 to i1
  br i1 %33, label %34, label %38

34:                                               ; preds = %24
  %35 = load i32, ptr %10, align 4, !tbaa !17
  %36 = icmp sgt i32 %35, 2
  %37 = zext i1 %36 to i8
  store i8 %37, ptr %9, align 1, !tbaa !10
  br label %42

38:                                               ; preds = %24
  %39 = load i32, ptr %10, align 4, !tbaa !17
  %40 = icmp sgt i32 %39, 5
  %41 = zext i1 %40 to i8
  store i8 %41, ptr %9, align 1, !tbaa !10
  br label %42

42:                                               ; preds = %38, %34
  %43 = load i8, ptr %6, align 1, !tbaa !9
  %44 = getelementptr inbounds %class.AnalogInput, ptr %13, i32 0, i32 0
  store i8 %43, ptr %44, align 1, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %45

45:                                               ; preds = %42, %16
  %46 = load i8, ptr %9, align 1, !tbaa !10, !range !12, !noundef !13
  %47 = trunc i8 %46 to i1
  br i1 %47, label %48, label %51

48:                                               ; preds = %45
  %49 = load i8, ptr %6, align 1, !tbaa !9
  %50 = getelementptr inbounds %class.AnalogInput, ptr %13, i32 0, i32 1
  store i8 %49, ptr %50, align 1, !tbaa !14
  br label %51

51:                                               ; preds = %48, %45
  %52 = load i8, ptr %9, align 1, !tbaa !10, !range !12, !noundef !13
  %53 = trunc i8 %52 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  ret i1 %53
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

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

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"bool", !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!15, !7, i64 1}
!15 = !{!"_ZTS11AnalogInput", !7, i64 0, !7, i64 1}
!16 = !{!15, !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"int", !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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef zeroext i1 @_ZN11AnalogInput6updateEhbb(ptr nocapture noundef nonnull align 1 dereferenceable(2) %0, i8 noundef zeroext %1, i1 noundef zeroext %2, i1 noundef zeroext %3) local_unnamed_addr #0 align 2 {
  br i1 %2, label %5, label %8

5:                                                ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 1
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %.not = icmp eq i8 %7, %1
  br i1 %.not, label %16, label %14

8:                                                ; preds = %4
  %9 = zext i8 %1 to i32
  %10 = load i8, ptr %0, align 1, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = sub nsw i32 %9, %11
  %13 = tail call i32 @llvm.abs.i32(i32 %12, i1 true)
  %.0.in.v = select i1 %3, i32 2, i32 5
  %.0.in = icmp ugt i32 %13, %.0.in.v
  store i8 %1, ptr %0, align 1, !tbaa !9
  br i1 %.0.in, label %14, label %16

14:                                               ; preds = %5, %8
  %15 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 %1, ptr %15, align 1, !tbaa !5
  br label %16

16:                                               ; preds = %5, %14, %8
  %.1.in10 = phi i1 [ false, %5 ], [ true, %14 ], [ false, %8 ]
  ret i1 %.1.in10
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #1

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

!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 1}
!6 = !{!"_ZTS11AnalogInput", !7, i64 0, !7, i64 1}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!6, !7, i64 0}


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