#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_12__ TYPE_7__;
typedef struct TYPE_11__ TYPE_3__;
typedef struct TYPE_10__ TYPE_2__;
typedef struct TYPE_9__ TYPE_1__;

/* Type definitions */
struct TYPE_10__ {
  TYPE_1__ *data;
  scalar_t__ rem;
};
typedef TYPE_2__ xcb_visualtype_iterator_t;
typedef scalar_t__ xcb_visualid_t;
typedef int /*<<< orphan*/ xcb_screen_t;
struct TYPE_11__ {
  TYPE_7__ *data;
  scalar_t__ rem;
};
typedef TYPE_3__ xcb_depth_iterator_t;
typedef int /*<<< orphan*/ uint8_t;
struct TYPE_12__ {
  int /*<<< orphan*/ depth;
};
struct TYPE_9__ {
  scalar_t__ visual_id;
};

/* Variables and functions */
int /*<<< orphan*/ xcb_depth_next(TYPE_3__ *);
TYPE_2__ xcb_depth_visuals_iterator(TYPE_7__ *);
TYPE_3__ xcb_screen_allowed_depths_iterator(int /*<<< orphan*/ *);
int /*<<< orphan*/ xcb_visualtype_next(TYPE_2__ *);
uint8_t xcb_aux_get_depth_of_visual(xcb_screen_t *screen, xcb_visualid_t id) {
  xcb_depth_iterator_t i;
  xcb_visualtype_iterator_t j;
  for (i = xcb_screen_allowed_depths_iterator(screen); i.rem;
       xcb_depth_next(&i))
    for (j = xcb_depth_visuals_iterator(i.data); j.rem; xcb_visualtype_next(&j))
      if (j.data->visual_id == id)
        return i.data->depth;
  return 0;
}


x86 assembly (clang, -O0):
<xcb_aux_get_depth_of_visual>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <xcb_screen_allowed_depths_iterator@plt>
mov    %rax,-0x48(%rbp)
mov    %rdx,-0x40(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ed <xcb_aux_get_depth_of_visual+0xad>
mov    -0x28(%rbp),%rdi
call   1060 <xcb_depth_visuals_iterator@plt>
mov    %rax,-0x58(%rbp)
mov    %rdx,-0x50(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11da <xcb_aux_get_depth_of_visual+0x9a>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
jne    11c7 <xcb_aux_get_depth_of_visual+0x87>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11f4 <xcb_aux_get_depth_of_visual+0xb4>
jmp    11cc <xcb_aux_get_depth_of_visual+0x8c>
lea    -0x38(%rbp),%rdi
call   1040 <xcb_visualtype_next@plt>
jmp    119d <xcb_aux_get_depth_of_visual+0x5d>
jmp    11df <xcb_aux_get_depth_of_visual+0x9f>
lea    -0x28(%rbp),%rdi
call   1030 <xcb_depth_next@plt>
jmp    1171 <xcb_aux_get_depth_of_visual+0x31>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xcb_aux_get_depth_of_visual>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
call   1050 <xcb_screen_allowed_depths_iterator@plt>
mov    %rax,0x8(%rsp)
mov    %rdx,0x10(%rsp)
xor    %r15d,%r15d
test   %rdx,%rdx
je     11df <xcb_aux_get_depth_of_visual+0x9f>
mov    %rax,%rdi
lea    0x8(%rsp),%r14
lea    0x18(%rsp),%rbp
call   1060 <xcb_depth_visuals_iterator@plt>
mov    %rax,0x18(%rsp)
mov    %rdx,0x20(%rsp)
test   %rdx,%rdx
je     11c0 <xcb_aux_get_depth_of_visual+0x80>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %rbx,(%rax)
je     11d7 <xcb_aux_get_depth_of_visual+0x97>
mov    %rbp,%rdi
call   1040 <xcb_visualtype_next@plt>
cmpq   $0x0,0x20(%rsp)
je     11c0 <xcb_aux_get_depth_of_visual+0x80>
mov    0x18(%rsp),%rax
cmp    %rbx,(%rax)
jne    1195 <xcb_aux_get_depth_of_visual+0x55>
jmp    11d7 <xcb_aux_get_depth_of_visual+0x97>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <xcb_depth_next@plt>
cmpq   $0x0,0x10(%rsp)
je     11df <xcb_aux_get_depth_of_visual+0x9f>
mov    0x8(%rsp),%rdi
jmp    1171 <xcb_aux_get_depth_of_visual+0x31>
mov    0x8(%rsp),%rax
mov    (%rax),%r15d
mov    %r15d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_11__ = type { %struct.TYPE_12__*, i64 }
%struct.TYPE_12__ = type { i32 }
%struct.TYPE_10__ = type { %struct.TYPE_9__*, i64 }
%struct.TYPE_9__ = type { i64 }
define i32 @xcb_aux_get_depth_of_visual(i32* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca %struct.TYPE_11__
%7 = alloca %struct.TYPE_10__
%8 = alloca %struct.TYPE_11__
%9 = alloca %struct.TYPE_10__
store i32* %0, i32** %4
store i64 %1, i64* %5
%10 = load i32*, i32** %4
%11 = call { %struct.TYPE_12__*, i64 } @xcb_screen_allowed_depths_iterator(i32* %10)
%12 = bitcast %struct.TYPE_11__* %8 to { %struct.TYPE_12__*, i64 }*
%13 = getelementptr inbounds { %struct.TYPE_12__*, i64 }, { %struct.TYPE_12__*, i64 }* %12, i32 0, i32 0
%14 = extractvalue { %struct.TYPE_12__*, i64 } %11, 0
store %struct.TYPE_12__* %14, %struct.TYPE_12__** %13
%15 = getelementptr inbounds { %struct.TYPE_12__*, i64 }, { %struct.TYPE_12__*, i64 }* %12, i32 0, i32 1
%16 = extractvalue { %struct.TYPE_12__*, i64 } %11, 1
store i64 %16, i64* %15
%17 = bitcast %struct.TYPE_11__* %6 to i8*
%18 = bitcast %struct.TYPE_11__* %8 to i8*
br label %19
19: ; preds = %54, %2
%20 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %6, i32 0, i32 1
%21 = load i64, i64* %20
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %56
23: ; preds = %19
%24 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %6, i32 0, i32 0
%25 = load %struct.TYPE_12__*, %struct.TYPE_12__** %24
%26 = call { %struct.TYPE_9__*, i64 } @xcb_depth_visuals_iterator(%struct.TYPE_12__* %25)
%27 = bitcast %struct.TYPE_10__* %9 to { %struct.TYPE_9__*, i64 }*
%28 = getelementptr inbounds { %struct.TYPE_9__*, i64 }, { %struct.TYPE_9__*, i64 }* %27, i32 0, i32 0
%29 = extractvalue { %struct.TYPE_9__*, i64 } %26, 0
store %struct.TYPE_9__* %29, %struct.TYPE_9__** %28
%30 = getelementptr inbounds { %struct.TYPE_9__*, i64 }, { %struct.TYPE_9__*, i64 }* %27, i32 0, i32 1
%31 = extractvalue { %struct.TYPE_9__*, i64 } %26, 1
store i64 %31, i64* %30
%32 = bitcast %struct.TYPE_10__* %7 to i8*
%33 = bitcast %struct.TYPE_10__* %9 to i8*
br label %34
34: ; preds = %51, %23
%35 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %7, i32 0, i32 1
%36 = load i64, i64* %35
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %53
38: ; preds = %34
%39 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %7, i32 0, i32 0
%40 = load %struct.TYPE_9__*, %struct.TYPE_9__** %39
%41 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %40, i32 0, i32 0
%42 = load i64, i64* %41
%43 = load i64, i64* %5
%44 = icmp eq i64 %42, %43
br i1 %44, label %45, label %50
45: ; preds = %38
%46 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %6, i32 0, i32 0
%47 = load %struct.TYPE_12__*, %struct.TYPE_12__** %46
%48 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %47, i32 0, i32 0
%49 = load i32, i32* %48
store i32 %49, i32* %3
br label %57
50: ; preds = %38
br label %51
51: ; preds = %50
%52 = call i32 @xcb_visualtype_next(%struct.TYPE_10__* %7)
br label %34
53: ; preds = %34
br label %54
54: ; preds = %53
%55 = call i32 @xcb_depth_next(%struct.TYPE_11__* %6)
br label %19
56: ; preds = %19
store i32 0, i32* %3
br label %57
57: ; preds = %56, %45
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
%struct.TYPE_11__ = type { %struct.TYPE_12__*, i64 }
%struct.TYPE_12__ = type { i32 }
%struct.TYPE_10__ = type { %struct.TYPE_9__*, i64 }
%struct.TYPE_9__ = type { i64 }
define i32 @xcb_aux_get_depth_of_visual(i32* %0, i64 %1) {
%3 = alloca %struct.TYPE_11__
%4 = alloca %struct.TYPE_10__
%5 = bitcast %struct.TYPE_11__* %3 to i8*
%6 = bitcast %struct.TYPE_10__* %4 to i8*
%7 = tail call { %struct.TYPE_12__*, i64 } @xcb_screen_allowed_depths_iterator(i32* %0)
%8 = extractvalue { %struct.TYPE_12__*, i64 } %7, 0
%9 = extractvalue { %struct.TYPE_12__*, i64 } %7, 1
%10 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %3, i64 0, i32 0
store %struct.TYPE_12__* %8, %struct.TYPE_12__** %10
%11 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %3, i64 0, i32 1
store i64 %9, i64* %11
%12 = icmp eq i64 %9, 0
br i1 %12, label %45, label %13
13: ; preds = %2
%14 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %4, i64 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %4, i64 0, i32 1
br label %16
16: ; preds = %43, %13
%17 = phi %struct.TYPE_12__* [ %44, %43 ], [ %8, %13 ]
%18 = call { %struct.TYPE_9__*, i64 } @xcb_depth_visuals_iterator(%struct.TYPE_12__* %17)
%19 = extractvalue { %struct.TYPE_9__*, i64 } %18, 0
%20 = extractvalue { %struct.TYPE_9__*, i64 } %18, 1
store %struct.TYPE_9__* %19, %struct.TYPE_9__** %14
store i64 %20, i64* %15
%21 = icmp eq i64 %20, 0
br i1 %21, label %39, label %22
22: ; preds = %16
%23 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %19, i64 0, i32 0
%24 = load i64, i64* %23
%25 = icmp eq i64 %24, %1
br i1 %25, label %26, label %30
26: ; preds = %22, %34
%27 = load %struct.TYPE_12__*, %struct.TYPE_12__** %10
%28 = getelementptr inbounds %struct.TYPE_12__, %struct.TYPE_12__* %27, i64 0, i32 0
%29 = load i32, i32* %28
br label %45
30: ; preds = %22, %34
%31 = call i32 @xcb_visualtype_next(%struct.TYPE_10__* %4)
%32 = load i64, i64* %15
%33 = icmp eq i64 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %30
%35 = load %struct.TYPE_9__*, %struct.TYPE_9__** %14
%36 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %35, i64 0, i32 0
%37 = load i64, i64* %36
%38 = icmp eq i64 %37, %1
br i1 %38, label %26, label %30
39: ; preds = %30, %16
%40 = call i32 @xcb_depth_next(%struct.TYPE_11__* %3)
%41 = load i64, i64* %11
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %39
%44 = load %struct.TYPE_12__*, %struct.TYPE_12__** %10
br label %16
45: ; preds = %39, %2, %26
%46 = phi i32 [ %29, %26 ], [ 0, %2 ], [ 0, %39 ]
ret i32 %46
}