; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/OptionRomPkg (I2cPinWrite)

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

; Function Attrs: nounwind uwtable
declare dso_local void @I2cOutb(ptr noundef, i64 noundef, i8 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @I2cInb(ptr noundef, i64 noundef) #0

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local void @I2cPinWrite(ptr noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  call void @I2cOutb(ptr noundef %8, i64 noundef 964, i8 noundef zeroext 8)
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call zeroext i8 @I2cInb(ptr noundef %9, i64 noundef 965)
  %11 = zext i8 %10 to i32
  %12 = load i8, ptr %5, align 1, !tbaa !9
  %13 = zext i8 %12 to i32
  %14 = shl i32 1, %13
  %15 = xor i32 %14, -1
  %16 = trunc i32 %15 to i8
  %17 = zext i8 %16 to i32
  %18 = and i32 %11, %17
  %19 = trunc i32 %18 to i8
  store i8 %19, ptr %7, align 1, !tbaa !9
  %20 = load i8, ptr %7, align 1, !tbaa !9
  %21 = zext i8 %20 to i32
  %22 = load i8, ptr %6, align 1, !tbaa !9
  %23 = zext i8 %22 to i32
  %24 = and i32 %23, 1
  %25 = load i8, ptr %5, align 1, !tbaa !9
  %26 = zext i8 %25 to i32
  %27 = shl i32 %24, %26
  %28 = or i32 %21, %27
  %29 = trunc i32 %28 to i8
  store i8 %29, ptr %7, align 1, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load i8, ptr %7, align 1, !tbaa !9
  %32 = zext i8 %31 to i32
  %33 = or i32 %32, 64
  %34 = trunc i32 %33 to i8
  call void @I2cOutb(ptr noundef %30, i64 noundef 965, i8 noundef zeroext %34)
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  ret void
}

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 = { 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 = !{!7, !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: nounwind uwtable
declare dso_local void @I2cOutb(ptr noundef, i64 noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @I2cInb(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @I2cPinWrite(ptr noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  tail call void @I2cOutb(ptr noundef %0, i64 noundef 964, i8 noundef zeroext 8)
  %4 = tail call zeroext i8 @I2cInb(ptr noundef %0, i64 noundef 965)
  %5 = zext i8 %1 to i32
  %6 = shl nuw i32 1, %5
  %7 = trunc i32 %6 to i8
  %8 = xor i8 %7, -1
  %9 = and i8 %4, %8
  %10 = and i8 %2, 1
  %11 = zext nneg i8 %10 to i32
  %12 = shl nuw i32 %11, %5
  %13 = trunc i32 %12 to i8
  %14 = or i8 %9, %13
  %15 = or i8 %14, 64
  tail call void @I2cOutb(ptr noundef %0, i64 noundef 965, i8 noundef zeroext %15)
  ret void
}

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

!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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass