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

; 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.ScreenTuneStruct = type { %struct.ScreenStruct, ptr, ptr, ptr, ptr, ptr, i8, i8, i32, [2 x i16], %struct.HistoryStruct, 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 ptr @menu_longScreenTune(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 i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %9, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %12, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  call void @saveTempParam(ptr noundef %13)
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call zeroext i1 @fixPower(ptr noundef %14, i8 noundef zeroext 0)
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  store i8 1, ptr %6, align 1, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  store i8 0, ptr %7, align 1, !tbaa !17
  br label %16

16:                                               ; preds = %31, %1
  %17 = load i8, ptr %7, align 1, !tbaa !17
  %18 = zext i8 %17 to i32
  %19 = icmp slt i32 %18, 2
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  br label %34

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %22, i32 0, i32 9
  %24 = load i8, ptr %7, align 1, !tbaa !17
  %25 = zext i8 %24 to i64
  %26 = getelementptr inbounds [2 x i16], ptr %23, i64 0, i64 %25
  %27 = load i16, ptr %26, align 2, !tbaa !18
  %28 = icmp ne i16 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %21
  store i8 0, ptr %6, align 1, !tbaa !16
  br label %30

30:                                               ; preds = %29, %21
  br label %31

31:                                               ; preds = %30
  %32 = load i8, ptr %7, align 1, !tbaa !17
  %33 = add i8 %32, 1
  store i8 %33, ptr %7, align 1, !tbaa !17
  br label %16, !llvm.loop !19

34:                                               ; preds = %20
  %35 = load i8, ptr %6, align 1, !tbaa !16, !range !21, !noundef !22
  %36 = trunc i8 %35 to i1
  br i1 %36, label %37, label %49

37:                                               ; preds = %34
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %38, i32 0, i32 5
  %40 = load ptr, ptr %39, align 8, !tbaa !23
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %41, i32 0, i32 9
  %43 = getelementptr inbounds [2 x i16], ptr %42, i64 0, i64 0
  %44 = load i16, ptr %43, align 8, !tbaa !18
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %45, i32 0, i32 9
  %47 = getelementptr inbounds [2 x i16], ptr %46, i64 0, i64 1
  %48 = load i16, ptr %47, align 2, !tbaa !18
  call void @saveCalibrationData(ptr noundef %40, i16 noundef zeroext %44, i16 noundef zeroext %48)
  br label %49

49:                                               ; preds = %37, %34
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %50, i32 0, i32 0
  %52 = getelementptr inbounds %struct.ScreenStruct, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !24
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %60

55:                                               ; preds = %49
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ScreenTuneStruct, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds %struct.ScreenStruct, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !24
  store ptr %59, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %62

60:                                               ; preds = %49
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %61, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %62

62:                                               ; preds = %60, %55
  call void @llvm.lifetime.end.p0(i64 1, 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
  %63 = load ptr, ptr %2, align 8
  ret ptr %63
}

; Function Attrs: nounwind uwtable
declare dso_local void @saveTempParam(ptr 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

declare zeroext i1 @fixPower(ptr noundef, i8 noundef zeroext) #2

declare void @saveCalibrationData(ptr noundef, i16 noundef zeroext, i16 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, !6, i64 112}
!10 = !{!"ScreenTuneStruct", !11, i64 0, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !12, i64 152, !12, i64 153, !14, i64 156, !7, i64 160, !15, i64 164, !7, i64 200}
!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 = !{!12, !12, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!13, !13, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!10, !6, i64 144}
!24 = !{!10, !6, i64 8}


; 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 ptr @menu_longScreenTune(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 112
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @saveTempParam(ptr noundef %0)
  %4 = tail call zeroext i1 @fixPower(ptr noundef %3, i8 noundef zeroext 0) #2
  %5 = getelementptr inbounds i8, ptr %0, i64 160
  %6 = load i16, ptr %5, align 2, !tbaa !15
  %.not18 = icmp ne i16 %6, 0
  %7 = getelementptr inbounds i8, ptr %0, i64 162
  %8 = load i16, ptr %7, align 2, !tbaa !15
  %.not18.1 = icmp ne i16 %8, 0
  %spec.select.1 = select i1 %.not18.1, i1 %.not18, i1 false
  br i1 %spec.select.1, label %9, label %12

9:                                                ; preds = %1
  %10 = getelementptr inbounds i8, ptr %0, i64 144
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  tail call void @saveCalibrationData(ptr noundef %11, i16 noundef zeroext %6, i16 noundef zeroext %8) #2
  br label %12

12:                                               ; preds = %9, %1
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %.not = icmp eq ptr %14, null
  %. = select i1 %.not, ptr %0, ptr %14
  ret ptr %.
}

; Function Attrs: nounwind uwtable
declare dso_local void @saveTempParam(ptr noundef) local_unnamed_addr #0

declare zeroext i1 @fixPower(ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

declare void @saveCalibrationData(ptr noundef, i16 noundef zeroext, i16 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 112}
!6 = !{!"ScreenTuneStruct", !7, i64 0, !8, i64 112, !8, i64 120, !8, i64 128, !8, i64 136, !8, i64 144, !11, i64 152, !11, i64 153, !13, i64 156, !9, i64 160, !14, i64 164, !9, i64 200}
!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 = !{!12, !12, i64 0}
!16 = !{!6, !8, i64 144}
!17 = !{!6, !8, i64 8}


; Effective O3 passes: AggressiveInstCombinePass,BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass