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

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

; Function Attrs: nounwind uwtable
define dso_local void @initScreenWork(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca i8, align 1
  %8 = alloca i16, align 2
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %9, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %12, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %13, i32 0, i32 4
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  store ptr %15, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call zeroext i16 @getTemp(ptr noundef %16)
  store i16 %17, ptr %6, align 2, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call zeroext i1 @getTempUnits(ptr noundef %18)
  %20 = zext i1 %19 to i8
  store i8 %20, ptr %7, align 1, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #3
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load i16, ptr %6, align 2, !tbaa !17
  %23 = call zeroext i16 @temp2humanUnits(ptr noundef %21, i16 noundef zeroext %22)
  store i16 %23, ptr %8, align 2, !tbaa !17
  %24 = load i8, ptr %7, align 1, !tbaa !18, !range !19, !noundef !20
  %25 = trunc i8 %24 to i1
  br i1 %25, label %26, label %29

26:                                               ; preds = %1
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i16, ptr %8, align 2, !tbaa !17
  call void @initEncoder(ptr noundef %27, i16 noundef signext %28, i16 noundef signext 180, i16 noundef signext 400, i8 noundef zeroext 1, i8 noundef zeroext 5, i32 noundef 0)
  br label %32

29:                                               ; preds = %1
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i16, ptr %8, align 2, !tbaa !17
  call void @initEncoder(ptr noundef %30, i16 noundef signext %31, i16 noundef signext 356, i16 noundef signext 752, i8 noundef zeroext 1, i8 noundef zeroext 5, i32 noundef 0)
  br label %32

32:                                               ; preds = %29, %26
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  call void @switchPower(ptr noundef %33, i1 noundef zeroext true)
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %34, i32 0, i32 6
  store i8 0, ptr %35, align 4, !tbaa !21
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %36, i32 0, i32 8
  store i8 0, ptr %37, align 4, !tbaa !22
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %38, i32 0, i32 5
  call void @initHistory(ptr noundef %39)
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ScreenWorkStruct, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !23
  call void @clear(ptr noundef %42)
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  call void @forceRedraw(ptr noundef %43)
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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

declare zeroext i16 @getTemp(ptr noundef) #2

declare zeroext i1 @getTempUnits(ptr noundef) #2

declare zeroext i16 @temp2humanUnits(ptr noundef, i16 noundef zeroext) #2

declare void @initEncoder(ptr noundef, i16 noundef signext, i16 noundef signext, i16 noundef signext, i8 noundef zeroext, i8 noundef zeroext, i32 noundef) #2

declare void @switchPower(ptr noundef, i1 noundef zeroext) #2

declare void @initHistory(ptr noundef) #2

declare void @clear(ptr noundef) #2

declare void @forceRedraw(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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 112}
!10 = !{!"ScreenWorkStruct", !11, i64 0, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !15, i64 144, !12, i64 180, !14, i64 184, !12, i64 188}
!11 = !{!"ScreenStruct", !6, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !13, i64 26, !14, 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}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"HistoryStruct", !7, i64 0, !7, i64 4}
!16 = !{!10, !6, i64 136}
!17 = !{!13, !13, i64 0}
!18 = !{!12, !12, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!10, !12, i64 180}
!22 = !{!10, !12, i64 188}
!23 = !{!10, !6, i64 120}


; 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 @initScreenWork(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 112
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 136
  %5 = load ptr, ptr %4, align 8, !tbaa !15
  %6 = tail call zeroext i16 @getTemp(ptr noundef %3) #2
  %7 = tail call zeroext i1 @getTempUnits(ptr noundef %3) #2
  %8 = tail call zeroext i16 @temp2humanUnits(ptr noundef %3, i16 noundef zeroext %6) #2
  br i1 %7, label %9, label %10

9:                                                ; preds = %1
  tail call void @initEncoder(ptr noundef %5, i16 noundef signext %8, i16 noundef signext 180, i16 noundef signext 400, i8 noundef zeroext 1, i8 noundef zeroext 5, i32 noundef 0) #2
  br label %11

10:                                               ; preds = %1
  tail call void @initEncoder(ptr noundef %5, i16 noundef signext %8, i16 noundef signext 356, i16 noundef signext 752, i8 noundef zeroext 1, i8 noundef zeroext 5, i32 noundef 0) #2
  br label %11

11:                                               ; preds = %10, %9
  tail call void @switchPower(ptr noundef %3, i1 noundef zeroext true) #2
  %12 = getelementptr inbounds i8, ptr %0, i64 180
  store i8 0, ptr %12, align 4, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %0, i64 188
  store i8 0, ptr %13, align 4, !tbaa !17
  %14 = getelementptr inbounds i8, ptr %0, i64 144
  tail call void @initHistory(ptr noundef nonnull %14) #2
  %15 = getelementptr inbounds i8, ptr %0, i64 120
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  tail call void @clear(ptr noundef %16) #2
  tail call void @forceRedraw(ptr noundef nonnull %0) #2
  ret void
}

declare zeroext i16 @getTemp(ptr noundef) local_unnamed_addr #1

declare zeroext i1 @getTempUnits(ptr noundef) local_unnamed_addr #1

declare zeroext i16 @temp2humanUnits(ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

declare void @initEncoder(ptr noundef, i16 noundef signext, i16 noundef signext, i16 noundef signext, i8 noundef zeroext, i8 noundef zeroext, i32 noundef) local_unnamed_addr #1

declare void @switchPower(ptr noundef, i1 noundef zeroext) local_unnamed_addr #1

declare void @initHistory(ptr noundef) local_unnamed_addr #1

declare void @clear(ptr noundef) local_unnamed_addr #1

declare void @forceRedraw(ptr noundef) 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 112}
!6 = !{!"ScreenWorkStruct", !7, i64 0, !8, i64 112, !8, i64 120, !8, i64 128, !8, i64 136, !14, i64 144, !11, i64 180, !13, i64 184, !11, i64 188}
!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 = !{!"HistoryStruct", !9, i64 0, !9, i64 4}
!15 = !{!6, !8, i64 136}
!16 = !{!6, !11, i64 180}
!17 = !{!6, !11, i64 188}
!18 = !{!6, !8, i64 120}


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