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

/* Type definitions */
struct TYPE_9__ {
  scalar_t__ visual_id;
};
typedef TYPE_1__ xcb_visualtype_t;
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__ {
  int /*<<< orphan*/ data;
  scalar_t__ rem;
};
typedef TYPE_3__ xcb_depth_iterator_t;

/* Variables and functions */
int /*<<< orphan*/ xcb_depth_next(TYPE_3__ *);
TYPE_2__ xcb_depth_visuals_iterator(int /*<<< orphan*/);
TYPE_3__ xcb_screen_allowed_depths_iterator(int /*<<< orphan*/ *);
int /*<<< orphan*/ xcb_visualtype_next(TYPE_2__ *);
xcb_visualtype_t *xcb_aux_find_visual_by_id(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 j.data;
  return 0;
}


x86 assembly (clang, -O0):
<xcb_aux_find_visual_by_id>:
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    %eax,-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     11ea <xcb_aux_find_visual_by_id+0xaa>
mov    -0x28(%rbp),%edi
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     11d7 <xcb_aux_find_visual_by_id+0x97>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
jne    11c4 <xcb_aux_find_visual_by_id+0x84>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f2 <xcb_aux_find_visual_by_id+0xb2>
jmp    11c9 <xcb_aux_find_visual_by_id+0x89>
lea    -0x38(%rbp),%rdi
call   1040 <xcb_visualtype_next@plt>
jmp    119b <xcb_aux_find_visual_by_id+0x5b>
jmp    11dc <xcb_aux_find_visual_by_id+0x9c>
lea    -0x28(%rbp),%rdi
call   1030 <xcb_depth_next@plt>
jmp    1170 <xcb_aux_find_visual_by_id+0x30>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xcb_aux_find_visual_by_id>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
call   1050 <xcb_screen_allowed_depths_iterator@plt>
mov    %eax,0x10(%rsp)
mov    %rdx,0x18(%rsp)
test   %rdx,%rdx
je     11b6 <xcb_aux_find_visual_by_id+0x76>
mov    %eax,%edi
lea    0x10(%rsp),%r14
mov    %rsp,%r15
call   1060 <xcb_depth_visuals_iterator@plt>
mov    %rax,(%rsp)
mov    %rdx,0x8(%rsp)
test   %rdx,%rdx
je     11a0 <xcb_aux_find_visual_by_id+0x60>
nopl   0x0(%rax)
cmp    %rbx,(%rax)
je     11b8 <xcb_aux_find_visual_by_id+0x78>
mov    %r15,%rdi
call   1040 <xcb_visualtype_next@plt>
cmpq   $0x0,0x8(%rsp)
je     11a0 <xcb_aux_find_visual_by_id+0x60>
mov    (%rsp),%rax
cmp    %rbx,(%rax)
jne    1185 <xcb_aux_find_visual_by_id+0x45>
jmp    11b8 <xcb_aux_find_visual_by_id+0x78>
mov    %r14,%rdi
call   1030 <xcb_depth_next@plt>
cmpq   $0x0,0x18(%rsp)
je     11b6 <xcb_aux_find_visual_by_id+0x76>
mov    0x10(%rsp),%edi
jmp    1169 <xcb_aux_find_visual_by_id+0x29>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_9__ = type { i64 }
%struct.TYPE_11__ = type { i32, i64 }
%struct.TYPE_10__ = type { %struct.TYPE_9__*, i64 }
define %struct.TYPE_9__* @xcb_aux_find_visual_by_id(i32* %0, i64 %1) {
%3 = alloca %struct.TYPE_9__*
%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 { i32, i64 } @xcb_screen_allowed_depths_iterator(i32* %10)
%12 = bitcast %struct.TYPE_11__* %8 to { i32, i64 }*
%13 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %12, i32 0, i32 0
%14 = extractvalue { i32, i64 } %11, 0
store i32 %14, i32* %13
%15 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %12, i32 0, i32 1
%16 = extractvalue { i32, 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 = %52, %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 %54
23: ; preds = %19
%24 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %6, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call { %struct.TYPE_9__*, i64 } @xcb_depth_visuals_iterator(i32 %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 = %49, %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 %51
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 %48
45: ; preds = %38
%46 = getelementptr inbounds %struct.TYPE_10__, %struct.TYPE_10__* %7, i32 0, i32 0
%47 = load %struct.TYPE_9__*, %struct.TYPE_9__** %46
store %struct.TYPE_9__* %47, %struct.TYPE_9__** %3
br label %55
48: ; preds = %38
br label %49
49: ; preds = %48
%50 = call i32 @xcb_visualtype_next(%struct.TYPE_10__* %7)
br label %34
51: ; preds = %34
br label %52
52: ; preds = %51
%53 = call i32 @xcb_depth_next(%struct.TYPE_11__* %6)
br label %19
54: ; preds = %19
store %struct.TYPE_9__* null, %struct.TYPE_9__** %3
br label %55
55: ; preds = %54, %45
%56 = load %struct.TYPE_9__*, %struct.TYPE_9__** %3
ret %struct.TYPE_9__* %56
}

LLVM IR (-O2):
%struct.TYPE_9__ = type { i64 }
%struct.TYPE_11__ = type { i32, i64 }
%struct.TYPE_10__ = type { %struct.TYPE_9__*, i64 }
define %struct.TYPE_9__* @xcb_aux_find_visual_by_id(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 { i32, i64 } @xcb_screen_allowed_depths_iterator(i32* %0)
%8 = extractvalue { i32, i64 } %7, 0
%9 = extractvalue { i32, i64 } %7, 1
%10 = getelementptr inbounds %struct.TYPE_11__, %struct.TYPE_11__* %3, i64 0, i32 0
store i32 %8, i32* %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 %43, 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 = %39, %13
%17 = phi i32 [ %40, %39 ], [ %8, %13 ]
%18 = call { %struct.TYPE_9__*, i64 } @xcb_depth_visuals_iterator(i32 %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 %35, 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 %41, label %26
26: ; preds = %22, %30
%27 = call i32 @xcb_visualtype_next(%struct.TYPE_10__* %4)
%28 = load i64, i64* %15
%29 = icmp eq i64 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %26
%31 = load %struct.TYPE_9__*, %struct.TYPE_9__** %14
%32 = getelementptr inbounds %struct.TYPE_9__, %struct.TYPE_9__* %31, i64 0, i32 0
%33 = load i64, i64* %32
%34 = icmp eq i64 %33, %1
br i1 %34, label %43, label %26
35: ; preds = %26, %16
%36 = call i32 @xcb_depth_next(%struct.TYPE_11__* %3)
%37 = load i64, i64* %11
%38 = icmp eq i64 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = load i32, i32* %10
br label %16
41: ; preds = %22
%42 = extractvalue { %struct.TYPE_9__*, i64 } %18, 0
br label %43
43: ; preds = %41, %35, %30, %2
%44 = phi %struct.TYPE_9__* [ null, %2 ], [ %31, %30 ], [ %42, %41 ], [ null, %35 ]
ret %struct.TYPE_9__* %44
}