#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_7__ TYPE_2__;
typedef struct TYPE_6__ TYPE_1__;

/* Type definitions */
struct TYPE_6__ {
  int /*<<< orphan*/ root;
};
typedef TYPE_1__ xcb_screen_t;
struct TYPE_7__ {
  int depth;
};
typedef TYPE_2__ xcb_get_geometry_reply_t;
typedef int /*<<< orphan*/ xcb_drawable_t;
typedef int /*<<< orphan*/ xcb_connection_t;
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ free(TYPE_2__ *);
int /*<<< orphan*/ xcb_get_geometry(int /*<<< orphan*/ *, int /*<<< orphan*/);
TYPE_2__ *xcb_get_geometry_reply(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                 int /*<<< orphan*/);
uint8_t xcb_aux_get_depth(xcb_connection_t *c, xcb_screen_t *screen) {
  xcb_drawable_t drawable;
  xcb_get_geometry_reply_t *geom;
  int depth = 0;
  drawable = screen->root;
  geom = xcb_get_geometry_reply(c, xcb_get_geometry(c, drawable), 0);
  if (geom) {
    depth = geom->depth;
    free(geom);
  }
  return depth;
}


x86 assembly (clang, -O0):
<xcb_aux_get_depth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <xcb_get_geometry@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <xcb_get_geometry_reply@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1192 <xcb_aux_get_depth+0x62>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xcb_aux_get_depth>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rsi),%esi
call   1050 <xcb_get_geometry@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <xcb_get_geometry_reply@plt>
test   %rax,%rax
je     115a <xcb_aux_get_depth+0x2a>
mov    (%rax),%ebp
mov    %rax,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { i32 }
%struct.TYPE_7__ = type { i32 }
define i32 @xcb_aux_get_depth(i32* %0, %struct.TYPE_6__* %1) {
%3 = alloca i32*
%4 = alloca %struct.TYPE_6__*
%5 = alloca i32
%6 = alloca %struct.TYPE_7__*
%7 = alloca i32
store i32* %0, i32** %3
store %struct.TYPE_6__* %1, %struct.TYPE_6__** %4
store i32 0, i32* %7
%8 = load %struct.TYPE_6__*, %struct.TYPE_6__** %4
%9 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %8, i32 0, i32 0
%10 = load i32, i32* %9
store i32 %10, i32* %5
%11 = load i32*, i32** %3
%12 = load i32*, i32** %3
%13 = load i32, i32* %5
%14 = call i32 @xcb_get_geometry(i32* %12, i32 %13)
%15 = call %struct.TYPE_7__* @xcb_get_geometry_reply(i32* %11, i32 %14, i32 0)
store %struct.TYPE_7__* %15, %struct.TYPE_7__** %6
%16 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%17 = icmp ne %struct.TYPE_7__* %16, null
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%20 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %19, i32 0, i32 0
%21 = load i32, i32* %20
store i32 %21, i32* %7
%22 = load %struct.TYPE_7__*, %struct.TYPE_7__** %6
%23 = call i32 @free(%struct.TYPE_7__* %22)
br label %24
24: ; preds = %18, %2
%25 = load i32, i32* %7
ret i32 %25
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32 }
%struct.TYPE_7__ = type { i32 }
define i32 @xcb_aux_get_depth(i32* %0, %struct.TYPE_6__* nocapture %1) {
%3 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %1, i64 0, i32 0
%4 = load i32, i32* %3
%5 = tail call i32 @xcb_get_geometry(i32* %0, i32 %4)
%6 = tail call %struct.TYPE_7__* @xcb_get_geometry_reply(i32* %0, i32 %5, i32 0)
%7 = icmp eq %struct.TYPE_7__* %6, null
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %6, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i32 @free(%struct.TYPE_7__* %6)
br label %12
12: ; preds = %8, %2
%13 = phi i32 [ %10, %8 ], [ 0, %2 ]
ret i32 %13
}