#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 */
typedef int /*<<< orphan*/ xcb_window_t;
struct TYPE_4__ {
  int map_state;
};
typedef TYPE_1__ xcb_get_window_attributes_reply_t;
typedef int /*<<< orphan*/ xcb_get_window_attributes_cookie_t;
typedef int /*<<< orphan*/ xcb_connection_t;

/* Variables and functions */
int XCB_MAP_STATE_VIEWABLE;
int /*<<< orphan*/ free(TYPE_1__ *);
int /*<<< orphan*/ xcb_get_window_attributes(int /*<<< orphan*/ *,
                                             int /*<<< orphan*/);
TYPE_1__ *xcb_get_window_attributes_reply(int /*<<< orphan*/ *,
                                          int /*<<< orphan*/,
                                          int /*<<< orphan*/ *);
int mapped(xcb_connection_t *con, xcb_window_t w) {
  int ms;
  xcb_get_window_attributes_cookie_t c;
  xcb_get_window_attributes_reply_t *r;
  c = xcb_get_window_attributes(con, w);
  r = xcb_get_window_attributes_reply(con, c, NULL);
  if (r == NULL)
    return 0;
  ms = r->map_state;
  free(r);
  return ms == XCB_MAP_STATE_VIEWABLE;
}


x86 assembly (clang, -O0):
<mapped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <xcb_get_window_attributes@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <xcb_get_window_attributes_reply@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1179 <mapped+0x49>
movl   $0x0,-0x4(%rbp)
jmp    11a2 <mapped+0x72>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%eax
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapped>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1050 <xcb_get_window_attributes@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <xcb_get_window_attributes_reply@plt>
test   %rax,%rax
je     1167 <mapped+0x37>
mov    (%rax),%ebp
mov    %rax,%rdi
call   1030 <free@plt>
mov    0x2e78(%rip),%rax
xor    %ebx,%ebx
cmp    (%rax),%ebp
sete   %bl
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32 }
@XCB_MAP_STATE_VIEWABLE = global i32 0
define i32 @mapped(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.TYPE_4__*
store i32* %0, i32** %4
store i32 %1, i32* %5
%9 = load i32*, i32** %4
%10 = load i32, i32* %5
%11 = call i32 @xcb_get_window_attributes(i32* %9, i32 %10)
store i32 %11, i32* %7
%12 = load i32*, i32** %4
%13 = load i32, i32* %7
%14 = call %struct.TYPE_4__* @xcb_get_window_attributes_reply(i32* %12, i32 %13, i32* null)
store %struct.TYPE_4__* %14, %struct.TYPE_4__** %8
%15 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%16 = icmp eq %struct.TYPE_4__* %15, null
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 0, i32* %3
br label %28
18: ; preds = %2
%19 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %19, i32 0, i32 0
%21 = load i32, i32* %20
store i32 %21, i32* %6
%22 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%23 = call i32 @free(%struct.TYPE_4__* %22)
%24 = load i32, i32* %6
%25 = load i32, i32* @XCB_MAP_STATE_VIEWABLE
%26 = icmp eq i32 %24, %25
%27 = zext i1 %26 to i32
store i32 %27, i32* %3
br label %28
28: ; preds = %18, %17
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32 }
@XCB_MAP_STATE_VIEWABLE = global i32 0
define i32 @mapped(i32* %0, i32 %1) {
%3 = tail call i32 @xcb_get_window_attributes(i32* %0, i32 %1)
%4 = tail call %struct.TYPE_4__* @xcb_get_window_attributes_reply(i32* %0, i32 %3, i32* null)
%5 = icmp eq %struct.TYPE_4__* %4, null
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %4, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i32 @free(%struct.TYPE_4__* %4)
%10 = load i32, i32* @XCB_MAP_STATE_VIEWABLE
%11 = icmp eq i32 %8, %10
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %2, %6
%14 = phi i32 [ %12, %6 ], [ 0, %2 ]
ret i32 %14
}