; LLVM IR from tsotchke/quantum_rng :: examples/crypto (key_exchange)

; 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.exchange_state_t = type { i32, %struct.key_material_t, [32 x i8], double, i32 }
%struct.key_material_t = type { [32 x i8], [32 x i8], [32 x i8], [32 x i8], [16 x i8] }

@.str.28 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [56 x i8], align 1
@stdin = external global ptr, align 8

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare dso_local void @run_key_exchange(ptr dead_on_unwind noalias writable sret(%struct.exchange_state_t) align 8, ptr noundef) #2

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: nounwind uwtable
declare dso_local void @print_results(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @run_interactive_mode(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca [256 x i8], align 16
  %4 = alloca %struct.exchange_state_t, align 8
  %5 = alloca %struct.exchange_state_t, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 256, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 200, ptr %4) #4
  %6 = call i32 (ptr, ...) @printf(ptr noundef @.str.28)
  %7 = call i32 (ptr, ...) @printf(ptr noundef @.str.29)
  br label %8

8:                                                ; preds = %24, %1
  br label %9

9:                                                ; preds = %8
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str.30)
  %11 = getelementptr inbounds [256 x i8], ptr %3, i64 0, i64 0
  %12 = load ptr, ptr @stdin, align 8, !tbaa !5
  %13 = call ptr @fgets(ptr noundef %11, i32 noundef 256, ptr noundef %12)
  %14 = getelementptr inbounds [256 x i8], ptr %3, i64 0, i64 0
  %15 = load i8, ptr %14, align 16, !tbaa !9
  %16 = sext i8 %15 to i32
  %17 = icmp eq i32 %16, 113
  br i1 %17, label %23, label %18

18:                                               ; preds = %9
  %19 = getelementptr inbounds [256 x i8], ptr %3, i64 0, i64 0
  %20 = load i8, ptr %19, align 16, !tbaa !9
  %21 = sext i8 %20 to i32
  %22 = icmp eq i32 %21, 81
  br i1 %22, label %23, label %24

23:                                               ; preds = %18, %9
  br label %27

24:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 200, ptr %5) #4
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  call void @run_key_exchange(ptr dead_on_unwind writable sret(%struct.exchange_state_t) align 8 %5, ptr noundef %25)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %5, i64 200, i1 false), !tbaa.struct !10
  call void @llvm.lifetime.end.p0(i64 200, ptr %5) #4
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  call void @print_results(ptr noundef %4, ptr noundef %26)
  br label %8

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 200, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 256, ptr %3) #4
  ret void
}

declare ptr @fgets(ptr noundef, i32 noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 #4 = { 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}
!10 = !{i64 0, i64 4, !11, i64 4, i64 32, !9, i64 36, i64 32, !9, i64 68, i64 32, !9, i64 100, i64 32, !9, i64 132, i64 16, !9, i64 148, i64 32, !9, i64 184, i64 8, !13, i64 192, i64 4, !11}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !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"

%struct.exchange_state_t = type { i32, %struct.key_material_t, [32 x i8], double, i32 }
%struct.key_material_t = type { [32 x i8], [32 x i8], [32 x i8], [32 x i8], [16 x i8] }

@.str.28 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [56 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare dso_local void @run_key_exchange(ptr dead_on_unwind noalias writable sret(%struct.exchange_state_t) align 8, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @print_results(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @run_interactive_mode(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca [256 x i8], align 16
  %3 = alloca %struct.exchange_state_t, align 8
  %4 = alloca %struct.exchange_state_t, align 8
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %3) #4
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.28)
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.29)
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.30)
  %8 = load ptr, ptr @stdin, align 8, !tbaa !5
  %9 = call ptr @fgets(ptr noundef nonnull %2, i32 noundef 256, ptr noundef %8)
  %10 = load i8, ptr %2, align 16
  %11 = and i8 %10, -33
  %or.cond5 = icmp eq i8 %11, 81
  br i1 %or.cond5, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %4) #4
  call void @run_key_exchange(ptr dead_on_unwind nonnull writable sret(%struct.exchange_state_t) align 8 %4, ptr noundef %0)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(200) %3, ptr noundef nonnull align 8 dereferenceable(200) %4, i64 200, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %4) #4
  call void @print_results(ptr noundef nonnull %3, ptr noundef %0)
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.30)
  %13 = load ptr, ptr @stdin, align 8, !tbaa !5
  %14 = call ptr @fgets(ptr noundef nonnull %2, i32 noundef 256, ptr noundef %13)
  %15 = load i8, ptr %2, align 16
  %16 = and i8 %15, -33
  %or.cond = icmp eq i8 %16, 81
  br i1 %or.cond, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %2) #4
  ret void
}

; Function Attrs: nofree nounwind
declare noundef ptr @fgets(ptr noundef, i32 noundef, ptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nofree nounwind "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 #4 = { 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 = !{i64 0, i64 4, !10, i64 4, i64 32, !12, i64 36, i64 32, !12, i64 68, i64 32, !12, i64 100, i64 32, !12, i64 132, i64 16, !12, i64 148, i64 32, !12, i64 184, i64 8, !13, i64 192, i64 4, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass