#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  scalar_t__ error_code;
};
typedef TYPE_1__ XErrorEvent;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
scalar_t__ BadAccess;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int original_error_handler(int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ stderr;
int handle_error(Display *display, XErrorEvent *error) {
  if (error->error_code == BadAccess) {
    fprintf(stderr, "Failed to grab key! Another application has already "
                    "claimed a key I need.\n");
    return 0;
  }
  return original_error_handler(display, error);
}


x86 assembly (clang, -O0):
<handle_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e9a(%rip),%rcx
cmp    (%rcx),%rax
jne    1168 <handle_error+0x48>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1178 <handle_error+0x58>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <original_error_handler@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_error>:
push   %rax
mov    (%rsi),%rax
mov    0x2ead(%rip),%rcx
cmp    (%rcx),%rax
jne    1149 <handle_error+0x29>
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
lea    0xec0(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret
pop    %rax
jmp    1040 <original_error_handler@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i64 }
@BadAccess = global i64 0
@stderr = global i32 0
@.str = [75 x i8] c"Failed to grab key! Another application has already claimed a key I need.\0A\00"
define i32 @handle_error(i32* %0, %struct.TYPE_4__* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.TYPE_4__*
store i32* %0, i32** %4
store %struct.TYPE_4__* %1, %struct.TYPE_4__** %5
%6 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%7 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 0
%8 = load i64, i64* %7
%9 = load i64, i64* @BadAccess
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %18
14: ; preds = %2
%15 = load i32*, i32** %4
%16 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%17 = call i32 @original_error_handler(i32* %15, %struct.TYPE_4__* %16)
store i32 %17, i32* %3
br label %18
18: ; preds = %14, %11
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i64 }
@BadAccess = global i64 0
@stderr = global i32 0
@.str = [75 x i8] c"Failed to grab key! Another application has already claimed a key I need.\0A\00"
define i32 @handle_error(i32* %0, %struct.TYPE_4__* %1) {
%3 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %1, i64 0, i32 0
%4 = load i64, i64* %3
%5 = load i64, i64* @BadAccess
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
br label %12
10: ; preds = %2
%11 = tail call i32 @original_error_handler(i32* %0, %struct.TYPE_4__* %1)
br label %12
12: ; preds = %10, %7
%13 = phi i32 [ 0, %7 ], [ %11, %10 ]
ret i32 %13
}