#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_3__ TYPE_1__;

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

/* Variables and functions */
scalar_t__ BadWindow;
int /*<<< orphan*/ XGetErrorText(int /*<<< orphan*/ *, scalar_t__, char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int catch_badwin(Display *dpy, XErrorEvent *err) {
  char buf[256];
  if (err->error_code == BadWindow) {
  } else {
    XGetErrorText(dpy, err->error_code, buf, sizeof buf);
    fprintf(stderr, "Caught unexpected X error: %s\n", buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<catch_badwin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2ea7(%rip),%rcx
cmp    (%rcx),%rax
jne    114f <catch_badwin+0x2f>
jmp    1187 <catch_badwin+0x67>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    -0x110(%rbp),%rdx
mov    $0x100,%ecx
call   1040 <XGetErrorText@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rdx
lea    0xe7e(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<catch_badwin>:
push   %rbx
sub    $0x100,%rsp
mov    (%rsi),%rsi
mov    0x2eb6(%rip),%rax
cmp    (%rax),%rsi
je     115f <catch_badwin+0x3f>
mov    %rsp,%rbx
mov    %rbx,%rdx
mov    $0x100,%ecx
call   1040 <XGetErrorText@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64 }
@BadWindow = global i64 0
@stderr = global i32 0
@.str = [31 x i8] c"Caught unexpected X error: %s\0A\00"
define i32 @catch_badwin(i32* %0, %struct.TYPE_3__* %1) {
%3 = alloca i32*
%4 = alloca %struct.TYPE_3__*
%5 = alloca [256 x i8]
store i32* %0, i32** %3
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %4
%6 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%8 = load i64, i64* %7
%9 = load i64, i64* @BadWindow
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %12
11: ; preds = %2
br label %22
12: ; preds = %2
%13 = load i32*, i32** %3
%14 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%18 = call i32 @XGetErrorText(i32* %13, i64 %16, i8* %17, i32 256)
%19 = load i32, i32* @stderr
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %12, %11
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64 }
@BadWindow = global i64 0
@stderr = global i32 0
@.str = [31 x i8] c"Caught unexpected X error: %s\0A\00"
define i32 @catch_badwin(i32* %0, %struct.TYPE_3__* nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%6 = load i64, i64* %5
%7 = load i64, i64* @BadWindow
%8 = icmp eq i64 %6, %7
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = call i32 @XGetErrorText(i32* %0, i64 %6, i8* %4, i32 256)
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %13
13: ; preds = %2, %9
ret i32 0
}