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

/* Type definitions */
struct TYPE_10__ {
  int _class;
};
typedef TYPE_1__ xcb_visualtype_t;
struct TYPE_11__ {
  TYPE_1__ *data;
  scalar_t__ rem;
};
typedef TYPE_2__ xcb_visualtype_iterator_t;
typedef int /*<<< orphan*/ xcb_screen_t;
struct TYPE_12__ {
  TYPE_7__ *data;
  scalar_t__ rem;
};
typedef TYPE_3__ xcb_depth_iterator_t;
typedef int int8_t;
struct TYPE_13__ {
  int depth;
};

/* 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__ *);
xcb_visualtype_t *xcb_aux_find_visual_by_attrs(xcb_screen_t *screen,
                                               int8_t class, int8_t depth) {
  xcb_depth_iterator_t i;
  xcb_visualtype_iterator_t j;
  for (i = xcb_screen_allowed_depths_iterator(screen); i.rem;
       xcb_depth_next(&i)) {
    if (depth != -1 && i.data->depth != depth)
      continue;
    for (j = xcb_depth_visuals_iterator(i.data); j.rem; xcb_visualtype_next(&j))
      if (class == -1 || j.data->_class == class)
        return j.data;
  }
  return 0;
}


x86 assembly (clang, -O0):
<xcb_aux_find_visual_by_attrs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-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     1214 <xcb_aux_find_visual_by_attrs+0xd4>
cmpl   $0xffffffff,-0x18(%rbp)
je     119c <xcb_aux_find_visual_by_attrs+0x5c>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
cmp    -0x18(%rbp),%eax
je     119c <xcb_aux_find_visual_by_attrs+0x5c>
jmp    1206 <xcb_aux_find_visual_by_attrs+0xc6>
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     1201 <xcb_aux_find_visual_by_attrs+0xc1>
cmpl   $0xffffffff,-0x14(%rbp)
je     11e1 <xcb_aux_find_visual_by_attrs+0xa1>
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
cmp    -0x14(%rbp),%eax
jne    11ee <xcb_aux_find_visual_by_attrs+0xae>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121c <xcb_aux_find_visual_by_attrs+0xdc>
jmp    11f3 <xcb_aux_find_visual_by_attrs+0xb3>
lea    -0x38(%rbp),%rdi
call   1040 <xcb_visualtype_next@plt>
jmp    11bd <xcb_aux_find_visual_by_attrs+0x7d>
jmp    1206 <xcb_aux_find_visual_by_attrs+0xc6>
lea    -0x28(%rbp),%rdi
call   1030 <xcb_depth_next@plt>
jmp    1173 <xcb_aux_find_visual_by_attrs+0x33>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xcb_aux_find_visual_by_attrs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
call   1050 <xcb_screen_allowed_depths_iterator@plt>
mov    %rax,0x18(%rsp)
mov    %rdx,0x20(%rsp)
test   %rdx,%rdx
je     11cf <xcb_aux_find_visual_by_attrs+0x8f>
lea    0x8(%rsp),%rbx
lea    0x18(%rsp),%r15
jmp    1180 <xcb_aux_find_visual_by_attrs+0x40>
nop
mov    %r15,%rdi
call   1030 <xcb_depth_next@plt>
cmpq   $0x0,0x20(%rsp)
je     11cf <xcb_aux_find_visual_by_attrs+0x8f>
mov    0x18(%rsp),%rdi
cmp    $0xffffffff,%r14d
je     1190 <xcb_aux_find_visual_by_attrs+0x50>
cmp    %r14d,(%rdi)
jne    1170 <xcb_aux_find_visual_by_attrs+0x30>
call   1060 <xcb_depth_visuals_iterator@plt>
mov    %rax,0x8(%rsp)
mov    %rdx,0x10(%rsp)
test   %rdx,%rdx
je     1170 <xcb_aux_find_visual_by_attrs+0x30>
cmp    $0xffffffff,%ebp
je     11d1 <xcb_aux_find_visual_by_attrs+0x91>
nopl   0x0(%rax)
cmp    %ebp,(%rax)
je     11d1 <xcb_aux_find_visual_by_attrs+0x91>
mov    %rbx,%rdi
call   1040 <xcb_visualtype_next@plt>
cmpq   $0x0,0x10(%rsp)
je     1170 <xcb_aux_find_visual_by_attrs+0x30>
mov    0x8(%rsp),%rax
cmp    %ebp,(%rax)
jne    11b4 <xcb_aux_find_visual_by_attrs+0x74>
jmp    11d1 <xcb_aux_find_visual_by_attrs+0x91>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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