#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 t_gui_window {
  int dummy;
};
struct t_gui_buffer {
  int dummy;
};

/* Variables and functions */
struct t_gui_buffer *
gui_buffer_get_previous_active_buffer(struct t_gui_buffer *,
                                      int /*<<< orphan*/);
int /*<<< orphan*/ gui_buffer_set_active_buffer(struct t_gui_buffer *);
struct t_gui_window *gui_window_search_with_buffer(struct t_gui_buffer *);
int /*<<< orphan*/ gui_window_switch_to_buffer(struct t_gui_window *,
                                               struct t_gui_buffer *, int);
void gui_input_switch_active_buffer_previous(struct t_gui_buffer *buffer) {
  struct t_gui_buffer *ptr_buffer;
  struct t_gui_window *window;
  ptr_buffer = gui_buffer_get_previous_active_buffer(buffer, 0);
  if (ptr_buffer) {
    gui_buffer_set_active_buffer(ptr_buffer);
    window = gui_window_search_with_buffer(buffer);
    if (window)
      gui_window_switch_to_buffer(window, ptr_buffer, 1);
  }
}


x86 assembly (clang, -O0):
<gui_input_switch_active_buffer_previous>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <gui_buffer_get_previous_active_buffer@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119e <gui_input_switch_active_buffer_previous+0x5e>
mov    -0x10(%rbp),%rdi
call   1060 <gui_buffer_set_active_buffer@plt>
mov    -0x8(%rbp),%rdi
call   1040 <gui_window_search_with_buffer@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1199 <gui_input_switch_active_buffer_previous+0x59>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1050 <gui_window_switch_to_buffer@plt>
jmp    119e <gui_input_switch_active_buffer_previous+0x5e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gui_input_switch_active_buffer_previous>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %esi,%esi
call   1030 <gui_buffer_get_previous_active_buffer@plt>
test   %rax,%rax
je     1182 <gui_input_switch_active_buffer_previous+0x42>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <gui_buffer_set_active_buffer@plt>
mov    %r14,%rdi
call   1040 <gui_window_search_with_buffer@plt>
test   %rax,%rax
je     1182 <gui_input_switch_active_buffer_previous+0x42>
mov    %rax,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <gui_window_switch_to_buffer@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.t_gui_buffer = type { i32 }
%struct.t_gui_window = type { i32 }
define void @gui_input_switch_active_buffer_previous(%struct.t_gui_buffer* %0) {
%2 = alloca %struct.t_gui_buffer*
%3 = alloca %struct.t_gui_buffer*
%4 = alloca %struct.t_gui_window*
store %struct.t_gui_buffer* %0, %struct.t_gui_buffer** %2
%5 = load %struct.t_gui_buffer*, %struct.t_gui_buffer** %2
%6 = call %struct.t_gui_buffer* @gui_buffer_get_previous_active_buffer(%struct.t_gui_buffer* %5, i32 0)
store %struct.t_gui_buffer* %6, %struct.t_gui_buffer** %3
%7 = load %struct.t_gui_buffer*, %struct.t_gui_buffer** %3
%8 = icmp ne %struct.t_gui_buffer* %7, null
br i1 %8, label %9, label %21
9: ; preds = %1
%10 = load %struct.t_gui_buffer*, %struct.t_gui_buffer** %3
%11 = call i32 @gui_buffer_set_active_buffer(%struct.t_gui_buffer* %10)
%12 = load %struct.t_gui_buffer*, %struct.t_gui_buffer** %2
%13 = call %struct.t_gui_window* @gui_window_search_with_buffer(%struct.t_gui_buffer* %12)
store %struct.t_gui_window* %13, %struct.t_gui_window** %4
%14 = load %struct.t_gui_window*, %struct.t_gui_window** %4
%15 = icmp ne %struct.t_gui_window* %14, null
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = load %struct.t_gui_window*, %struct.t_gui_window** %4
%18 = load %struct.t_gui_buffer*, %struct.t_gui_buffer** %3
%19 = call i32 @gui_window_switch_to_buffer(%struct.t_gui_window* %17, %struct.t_gui_buffer* %18, i32 1)
br label %20
20: ; preds = %16, %9
br label %21
21: ; preds = %20, %1
ret void
}

LLVM IR (-O2):
%struct.t_gui_buffer = type { i32 }
%struct.t_gui_window = type { i32 }
define void @gui_input_switch_active_buffer_previous(%struct.t_gui_buffer* %0) {
%2 = tail call %struct.t_gui_buffer* @gui_buffer_get_previous_active_buffer(%struct.t_gui_buffer* %0, i32 0)
%3 = icmp eq %struct.t_gui_buffer* %2, null
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call i32 @gui_buffer_set_active_buffer(%struct.t_gui_buffer* %2)
%6 = tail call %struct.t_gui_window* @gui_window_search_with_buffer(%struct.t_gui_buffer* %0)
%7 = icmp eq %struct.t_gui_window* %6, null
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @gui_window_switch_to_buffer(%struct.t_gui_window* %6, %struct.t_gui_buffer* %2, i32 1)
br label %10
10: ; preds = %4, %8, %1
ret void
}