; LLVM IR from control-flow-attestation/c-flat :: samples/soldering (ScreenConfig)

; 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.ScreenConfigStruct = type { %struct.ScreenStruct, ptr, ptr, ptr, ptr, i32, i8, i8, i8, i8, i8, [4 x i8], [4 x i8] }
%struct.ScreenStruct = type { ptr, ptr, ptr, i8, i16, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @rotaryValueScreenConfig(ptr noundef %0, i16 noundef signext %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %7, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %8, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  store ptr %10, ptr %6, align 8, !tbaa !5
  %11 = call i64 @millis()
  %12 = add i64 %11, 10000
  %13 = trunc i64 %12 to i32
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %14, i32 0, i32 5
  store i32 %13, ptr %15, align 8, !tbaa !16
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %16, i32 0, i32 7
  %18 = load i8, ptr %17, align 1, !tbaa !17, !range !18, !noundef !19
  %19 = trunc i8 %18 to i1
  br i1 %19, label %20, label %45

20:                                               ; preds = %2
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %21, i32 0, i32 8
  store i8 1, ptr %22, align 2, !tbaa !20
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %23, i32 0, i32 6
  %25 = load i8, ptr %24, align 4, !tbaa !21
  %26 = zext i8 %25 to i32
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %37

28:                                               ; preds = %20
  %29 = load i16, ptr %4, align 2, !tbaa !9
  %30 = trunc i16 %29 to i8
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %31, i32 0, i32 9
  store i8 %30, ptr %32, align 1, !tbaa !22
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %34, i32 0, i32 9
  %36 = load i8, ptr %35, align 1, !tbaa !22
  call void @brightness(ptr noundef %33, i8 noundef zeroext %36)
  br label %44

37:                                               ; preds = %20
  %38 = load i16, ptr %4, align 2, !tbaa !9
  %39 = icmp ne i16 %38, 0
  %40 = xor i1 %39, true
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %41, i32 0, i32 10
  %43 = zext i1 %40 to i8
  store i8 %43, ptr %42, align 8, !tbaa !23
  br label %44

44:                                               ; preds = %37, %28
  br label %50

45:                                               ; preds = %2
  %46 = load i16, ptr %4, align 2, !tbaa !9
  %47 = trunc i16 %46 to i8
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %48, i32 0, i32 6
  store i8 %47, ptr %49, align 4, !tbaa !21
  br label %50

50:                                               ; preds = %45, %44
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ScreenConfigStruct, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds %struct.ScreenStruct, ptr %52, i32 0, i32 3
  store i8 1, ptr %53, align 8, !tbaa !24
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

; 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

declare i64 @millis() #2

declare void @brightness(ptr noundef, i8 noundef zeroext) #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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !6, i64 120}
!12 = !{!"ScreenConfigStruct", !13, i64 0, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !15, i64 144, !7, i64 148, !14, i64 149, !14, i64 150, !7, i64 151, !14, i64 152, !7, i64 153, !7, i64 157}
!13 = !{!"ScreenStruct", !6, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !10, i64 26, !15, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!12, !15, i64 144}
!17 = !{!12, !14, i64 149}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!12, !14, i64 150}
!21 = !{!12, !7, i64 148}
!22 = !{!12, !7, i64 151}
!23 = !{!12, !14, i64 152}
!24 = !{!12, !14, i64 24}


; 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
define dso_local void @rotaryValueScreenConfig(ptr nocapture noundef %0, i16 noundef signext %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 120
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call i64 @millis() #2
  %6 = trunc i64 %5 to i32
  %7 = add i32 %6, 10000
  %8 = getelementptr inbounds i8, ptr %0, i64 144
  store i32 %7, ptr %8, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 149
  %10 = load i8, ptr %9, align 1, !tbaa !15, !range !16, !noundef !17
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %12, label %23

12:                                               ; preds = %2
  %13 = getelementptr inbounds i8, ptr %0, i64 150
  store i8 1, ptr %13, align 2, !tbaa !18
  %14 = getelementptr inbounds i8, ptr %0, i64 148
  %15 = load i8, ptr %14, align 4, !tbaa !19
  %16 = icmp eq i8 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %12
  %18 = trunc i16 %1 to i8
  %19 = getelementptr inbounds i8, ptr %0, i64 151
  store i8 %18, ptr %19, align 1, !tbaa !20
  tail call void @brightness(ptr noundef %4, i8 noundef zeroext %18) #2
  br label %26

20:                                               ; preds = %12
  %.not = icmp eq i16 %1, 0
  %21 = getelementptr inbounds i8, ptr %0, i64 152
  %22 = zext i1 %.not to i8
  store i8 %22, ptr %21, align 8, !tbaa !21
  br label %26

23:                                               ; preds = %2
  %24 = trunc i16 %1 to i8
  %25 = getelementptr inbounds i8, ptr %0, i64 148
  store i8 %24, ptr %25, align 4, !tbaa !19
  br label %26

26:                                               ; preds = %17, %20, %23
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  store i8 1, ptr %27, align 8, !tbaa !22
  ret void
}

declare i64 @millis() local_unnamed_addr #1

declare void @brightness(ptr noundef, i8 noundef zeroext) local_unnamed_addr #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 = { "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 }

!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, !8, i64 120}
!6 = !{!"ScreenConfigStruct", !7, i64 0, !8, i64 112, !8, i64 120, !8, i64 128, !8, i64 136, !13, i64 144, !9, i64 148, !11, i64 149, !11, i64 150, !9, i64 151, !11, i64 152, !9, i64 153, !9, i64 157}
!7 = !{!"ScreenStruct", !8, i64 0, !8, i64 8, !8, i64 16, !11, i64 24, !12, i64 26, !13, i64 28, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !8, i64 88, !8, i64 96, !8, i64 104}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"_Bool", !9, i64 0}
!12 = !{!"short", !9, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!6, !13, i64 144}
!15 = !{!6, !11, i64 149}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!6, !11, i64 150}
!19 = !{!6, !9, i64 148}
!20 = !{!6, !9, i64 151}
!21 = !{!6, !11, i64 152}
!22 = !{!6, !11, i64 24}


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