#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_9__ TYPE_4__;
typedef struct TYPE_8__ TYPE_2__;
typedef struct TYPE_7__ TYPE_1__;

/* Type definitions */
struct TYPE_7__ {
  scalar_t__ visual_id;
};
typedef TYPE_1__ xcb_visualtype_t;
struct TYPE_8__ {
  int rem;
  TYPE_1__ *data;
};
typedef TYPE_2__ xcb_visualtype_iterator_t;
typedef scalar_t__ xcb_visualid_t;
typedef int /*<<< orphan*/ xcb_screen_t;
typedef int /*<<< orphan*/ xcb_depth_t;
typedef int /*<<< orphan*/ xcb_connection_t;
struct TYPE_9__ {
  int /*<<< orphan*/ *data;
};

/* Variables and functions */
int /*<<< orphan*/ *xcb_aux_get_screen(int /*<<< orphan*/ *, int);
TYPE_2__ xcb_depth_visuals_iterator(int /*<<< orphan*/ *);
TYPE_4__ xcb_screen_allowed_depths_iterator(int /*<<< orphan*/ *);
int /*<<< orphan*/ xcb_visualtype_next(TYPE_2__ *);
xcb_visualtype_t *xcb_aux_get_visualtype(xcb_connection_t *c, int scr,
                                         xcb_visualid_t vid) {
  xcb_screen_t *screen;
  xcb_depth_t *depth;
  xcb_visualtype_iterator_t iter;
  int cur;
  screen = xcb_aux_get_screen(c, scr);
  if (!screen)
    return NULL;
  depth = xcb_screen_allowed_depths_iterator(screen).data;
  if (!depth)
    return NULL;
  iter = xcb_depth_visuals_iterator(depth);
  for (cur = 0; cur < iter.rem; xcb_visualtype_next(&iter), ++cur)
    if (vid == iter.data->visual_id)
      return iter.data;
  return NULL;
}


x86 assembly (clang, -O0):
<xcb_aux_get_visualtype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <xcb_aux_get_screen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117b <xcb_aux_get_visualtype+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    121d <xcb_aux_get_visualtype+0xdd>
mov    -0x28(%rbp),%rdi
call   1050 <xcb_screen_allowed_depths_iterator@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a8 <xcb_aux_get_visualtype+0x68>
movq   $0x0,-0x8(%rbp)
jmp    121d <xcb_aux_get_visualtype+0xdd>
mov    -0x30(%rbp),%rdi
call   1060 <xcb_depth_visuals_iterator@plt>
mov    %eax,-0x60(%rbp)
mov    %rdx,-0x58(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x40(%rbp),%eax
jge    1215 <xcb_aux_get_visualtype+0xd5>
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
cmp    (%rcx),%rax
jne    11f9 <xcb_aux_get_visualtype+0xb9>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121d <xcb_aux_get_visualtype+0xdd>
jmp    11fe <xcb_aux_get_visualtype+0xbe>
lea    -0x40(%rbp),%rdi
call   1030 <xcb_visualtype_next@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11cf <xcb_aux_get_visualtype+0x8f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xcb_aux_get_visualtype>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
call   1040 <xcb_aux_get_screen@plt>
test   %rax,%rax
je     11ac <xcb_aux_get_visualtype+0x6c>
mov    %rax,%rdi
call   1050 <xcb_screen_allowed_depths_iterator@plt>
test   %rax,%rax
je     11ac <xcb_aux_get_visualtype+0x6c>
mov    %rax,%rdi
call   1060 <xcb_depth_visuals_iterator@plt>
mov    %eax,%ecx
mov    %eax,(%rsp)
mov    %rdx,0x8(%rsp)
test   %eax,%eax
jle    11ac <xcb_aux_get_visualtype+0x6c>
mov    %rdx,%rax
cmp    %rbx,(%rdx)
je     11ae <xcb_aux_get_visualtype+0x6e>
mov    %rsp,%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1030 <xcb_visualtype_next@plt>
add    $0x1,%ebp
cmp    (%rsp),%ebp
jge    11ac <xcb_aux_get_visualtype+0x6c>
mov    0x8(%rsp),%rax
cmp    %rbx,(%rax)
jne    1190 <xcb_aux_get_visualtype+0x50>
jmp    11ae <xcb_aux_get_visualtype+0x6e>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.TYPE_7__ = type { i64 }
%struct.TYPE_8__ = type { i32, %struct.TYPE_7__* }
define %struct.TYPE_7__* @xcb_aux_get_visualtype(i32* %0, i32 %1, i64 %2) {
%4 = alloca %struct.TYPE_8__
%5 = bitcast %struct.TYPE_8__* %4 to i8*
%6 = tail call i32* @xcb_aux_get_screen(i32* %0, i32 %1)
%7 = icmp eq i32* %6, null
br i1 %7, label %33, label %8
8: ; preds = %3
%9 = tail call i32* @xcb_screen_allowed_depths_iterator(i32* %6)
%10 = icmp eq i32* %9, null
br i1 %10, label %33, label %11
11: ; preds = %8
%12 = tail call { i32, %struct.TYPE_7__* } @xcb_depth_visuals_iterator(i32* %9)
%13 = extractvalue { i32, %struct.TYPE_7__* } %12, 0
%14 = extractvalue { i32, %struct.TYPE_7__* } %12, 1
%15 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %4, i64 0, i32 0
store i32 %13, i32* %15
%16 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %4, i64 0, i32 1
store %struct.TYPE_7__* %14, %struct.TYPE_7__** %16
%17 = icmp sgt i32 %13, 0
br i1 %17, label %18, label %33
18: ; preds = %11
%19 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %14, i64 0, i32 0
%20 = load i64, i64* %19
%21 = icmp eq i64 %20, %2
br i1 %21, label %33, label %22
22: ; preds = %18, %28
%23 = phi i32 [ %25, %28 ], [ 0, %18 ]
%24 = call i32 @xcb_visualtype_next(%struct.TYPE_8__* %4)
%25 = add nuw nsw i32 %23, 1
%26 = load i32, i32* %15
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %33
28: ; preds = %22
%29 = load %struct.TYPE_7__*, %struct.TYPE_7__** %16
%30 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %29, i64 0, i32 0
%31 = load i64, i64* %30
%32 = icmp eq i64 %31, %2
br i1 %32, label %33, label %22
33: ; preds = %22, %28, %18, %11, %8, %3
%34 = phi %struct.TYPE_7__* [ null, %3 ], [ null, %8 ], [ null, %11 ], [ %14, %18 ], [ %29, %28 ], [ null, %22 ]
ret %struct.TYPE_7__* %34
}