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

/* Variables and functions */
struct t_gui_key *gui_keyboard_new(struct t_gui_buffer *, char const *,
                                   char const *);
int /*<<< orphan*/ gui_keyboard_unbind(struct t_gui_buffer *, char const *,
                                       int /*<<< orphan*/);
int /*<<< orphan*/ log_printf(char *, ...);
struct t_gui_key *gui_keyboard_bind(struct t_gui_buffer *buffer,
                                    const char *key, const char *command) {
  struct t_gui_key *new_key;
  if (!key || !command) {
    log_printf(("Error: unable to bind key \"%s\""), key);
    return NULL;
  }
  gui_keyboard_unbind(buffer, key, 0);
  new_key = gui_keyboard_new(buffer, key, command);
  if (!new_key) {
    log_printf(("Error: not enough memory for key binding"));
    return NULL;
  }
  return new_key;
}


x86 assembly (clang, -O0):
<gui_keyboard_bind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     115a <gui_keyboard_bind+0x2a>
cmpq   $0x0,-0x20(%rbp)
jne    1179 <gui_keyboard_bind+0x49>
mov    -0x18(%rbp),%rsi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <log_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11cb <gui_keyboard_bind+0x9b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <gui_keyboard_unbind@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <gui_keyboard_new@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c3 <gui_keyboard_bind+0x93>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <log_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11cb <gui_keyboard_bind+0x9b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gui_keyboard_bind>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
test   %rsi,%rsi
je     117b <gui_keyboard_bind+0x4b>
mov    %rdx,%r14
test   %rdx,%rdx
je     117b <gui_keyboard_bind+0x4b>
mov    %rdi,%r15
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <gui_keyboard_unbind@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <gui_keyboard_new@plt>
mov    %rax,%r14
test   %rax,%rax
jne    118f <gui_keyboard_bind+0x5f>
lea    0xeb0(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <log_printf@plt>
jmp    118f <gui_keyboard_bind+0x5f>
lea    0xe7e(%rip),%rdi
xor    %r14d,%r14d
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <log_printf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.t_gui_key = type { i32 }
%struct.t_gui_buffer = type { i32 }
@.str = [31 x i8] c"Error: unable to bind key \22%s\22\00"
@.str.1 = [41 x i8] c"Error: not enough memory for key binding\00"
define %struct.t_gui_key* @gui_keyboard_bind(%struct.t_gui_buffer* %0, i8* %1, i8* %2) {
%4 = alloca %struct.t_gui_key*
%5 = alloca %struct.t_gui_buffer*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.t_gui_key*
store %struct.t_gui_buffer* %0, %struct.t_gui_buffer** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11, %3
%15 = load i8*, i8** %6
%16 = call i32 (i8*, ...) @log_printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %15)
store %struct.t_gui_key* null, %struct.t_gui_key** %4
br label %31
17: ; preds = %11
%18 = load %struct.t_gui_buffer*, %struct.t_gui_buffer** %5
%19 = load i8*, i8** %6
%20 = call i32 @gui_keyboard_unbind(%struct.t_gui_buffer* %18, i8* %19, i32 0)
%21 = load %struct.t_gui_buffer*, %struct.t_gui_buffer** %5
%22 = load i8*, i8** %6
%23 = load i8*, i8** %7
%24 = call %struct.t_gui_key* @gui_keyboard_new(%struct.t_gui_buffer* %21, i8* %22, i8* %23)
store %struct.t_gui_key* %24, %struct.t_gui_key** %8
%25 = load %struct.t_gui_key*, %struct.t_gui_key** %8
%26 = icmp ne %struct.t_gui_key* %25, null
br i1 %26, label %29, label %27
27: ; preds = %17
%28 = call i32 (i8*, ...) @log_printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
store %struct.t_gui_key* null, %struct.t_gui_key** %4
br label %31
29: ; preds = %17
%30 = load %struct.t_gui_key*, %struct.t_gui_key** %8
store %struct.t_gui_key* %30, %struct.t_gui_key** %4
br label %31
31: ; preds = %29, %27, %14
%32 = load %struct.t_gui_key*, %struct.t_gui_key** %4
ret %struct.t_gui_key* %32
}

LLVM IR (-O2):
%struct.t_gui_key = type { i32 }
%struct.t_gui_buffer = type { i32 }
@.str = [31 x i8] c"Error: unable to bind key \22%s\22\00"
@.str.1 = [41 x i8] c"Error: not enough memory for key binding\00"
define %struct.t_gui_key* @gui_keyboard_bind(%struct.t_gui_buffer* %0, i8* %1, i8* %2) {
%4 = icmp ne i8* %1, null
%5 = icmp ne i8* %2, null
%6 = and i1 %4, %5
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 (i8*, ...) @log_printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %15
9: ; preds = %3
%10 = tail call i32 @gui_keyboard_unbind(%struct.t_gui_buffer* %0, i8* %1, i32 0)
%11 = tail call %struct.t_gui_key* @gui_keyboard_new(%struct.t_gui_buffer* %0, i8* %1, i8* %2)
%12 = icmp eq %struct.t_gui_key* %11, null
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 (i8*, ...) @log_printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %9, %13, %7
%16 = phi %struct.t_gui_key* [ null, %13 ], [ null, %7 ], [ %11, %9 ]
ret %struct.t_gui_key* %16
}