#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct tag_osm_task {
  int dummy;
};
struct tag_osm_state {
  int dummy;
};

/* Variables and functions */
struct tag_osm_state *ons_get_common_parent_state(struct tag_osm_state *,
                                                  struct tag_osm_state *);
int /*<<< orphan*/ osm_enter_state(struct tag_osm_task *,
                                   struct tag_osm_state *,
                                   struct tag_osm_state *);
int /*<<< orphan*/ osm_exit_state(struct tag_osm_task *, struct tag_osm_state *,
                                  struct tag_osm_state *);
void osm_change_state(struct tag_osm_task *osm, struct tag_osm_state *new_state,
                      struct tag_osm_state *old_state) {
  if (new_state != old_state) {
    struct tag_osm_state *parent_state;
    parent_state = ons_get_common_parent_state(new_state, old_state);
    osm_exit_state(osm, parent_state, old_state);
    osm_enter_state(osm, parent_state, new_state);
  }
}


x86 assembly (clang, -O0):
<osm_change_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1185 <osm_change_state+0x55>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <ons_get_common_parent_state@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <osm_exit_state@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <osm_enter_state@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<osm_change_state>:
cmp    %rdx,%rsi
je     117b <osm_change_state+0x4b>
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1040 <ons_get_common_parent_state@plt>
mov    %rax,%r12
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1030 <osm_exit_state@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <osm_enter_state@plt>
ret

LLVM IR (-O0):
%struct.tag_osm_task = type { i32 }
%struct.tag_osm_state = type { i32 }
define void @osm_change_state(%struct.tag_osm_task* %0, %struct.tag_osm_state* %1, %struct.tag_osm_state* %2) {
%4 = alloca %struct.tag_osm_task*
%5 = alloca %struct.tag_osm_state*
%6 = alloca %struct.tag_osm_state*
%7 = alloca %struct.tag_osm_state*
store %struct.tag_osm_task* %0, %struct.tag_osm_task** %4
store %struct.tag_osm_state* %1, %struct.tag_osm_state** %5
store %struct.tag_osm_state* %2, %struct.tag_osm_state** %6
%8 = load %struct.tag_osm_state*, %struct.tag_osm_state** %5
%9 = load %struct.tag_osm_state*, %struct.tag_osm_state** %6
%10 = icmp ne %struct.tag_osm_state* %8, %9
br i1 %10, label %11, label %23
11: ; preds = %3
%12 = load %struct.tag_osm_state*, %struct.tag_osm_state** %5
%13 = load %struct.tag_osm_state*, %struct.tag_osm_state** %6
%14 = call %struct.tag_osm_state* @ons_get_common_parent_state(%struct.tag_osm_state* %12, %struct.tag_osm_state* %13)
store %struct.tag_osm_state* %14, %struct.tag_osm_state** %7
%15 = load %struct.tag_osm_task*, %struct.tag_osm_task** %4
%16 = load %struct.tag_osm_state*, %struct.tag_osm_state** %7
%17 = load %struct.tag_osm_state*, %struct.tag_osm_state** %6
%18 = call i32 @osm_exit_state(%struct.tag_osm_task* %15, %struct.tag_osm_state* %16, %struct.tag_osm_state* %17)
%19 = load %struct.tag_osm_task*, %struct.tag_osm_task** %4
%20 = load %struct.tag_osm_state*, %struct.tag_osm_state** %7
%21 = load %struct.tag_osm_state*, %struct.tag_osm_state** %5
%22 = call i32 @osm_enter_state(%struct.tag_osm_task* %19, %struct.tag_osm_state* %20, %struct.tag_osm_state* %21)
br label %23
23: ; preds = %11, %3
ret void
}

LLVM IR (-O2):
%struct.tag_osm_task = type { i32 }
%struct.tag_osm_state = type { i32 }
define void @osm_change_state(%struct.tag_osm_task* %0, %struct.tag_osm_state* %1, %struct.tag_osm_state* %2) {
%4 = icmp eq %struct.tag_osm_state* %1, %2
br i1 %4, label %9, label %5
5: ; preds = %3
%6 = tail call %struct.tag_osm_state* @ons_get_common_parent_state(%struct.tag_osm_state* %1, %struct.tag_osm_state* %2)
%7 = tail call i32 @osm_exit_state(%struct.tag_osm_task* %0, %struct.tag_osm_state* %6, %struct.tag_osm_state* %2)
%8 = tail call i32 @osm_enter_state(%struct.tag_osm_task* %0, %struct.tag_osm_state* %6, %struct.tag_osm_state* %1)
br label %9
9: ; preds = %5, %3
ret void
}