(* *********************************************************************)
(*                                                                     *)
(*              The Compcert verified compiler                         *)
(*                                                                     *)
(*          Xavier Leroy, INRIA Paris-Rocquencourt                     *)
(*                                                                     *)
(*  Copyright Institut National de Recherche en Informatique et en     *)
(*  Automatique.  All rights reserved.  This file is distributed       *)
(*  under the terms of the INRIA Non-Commercial License Agreement.     *)
(*                                                                     *)
(* *********************************************************************)
(** Corollaries of the main semantic preservation theorem. *)
(** * Preservation of whole-program behaviors *)
(** From the simulation diagrams proved in file [Compiler]. it follows that whole-program observable behaviors are preserved in the following sense. First, every behavior of the generated assembly code is matched by a behavior of the source C code.  The behavior [beh] of the assembly code is either identical to the behavior [beh'] of the source C code or ``improves upon'' [beh']  by replacing a ``going wrong'' behavior with a more defined behavior. *)

Theorem transf_c_program_preservation:
forall p tp beh,
transf_c_program p = OK tp ->
program_behaves (Asm.semantics tp) beh ->
exists beh', program_behaves (Csem.semantics p) beh' /\ behavior_improves beh' beh.