#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_4__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ xcb_screen_t;
struct TYPE_4__ {
  int /*<<< orphan*/ *data;
  scalar_t__ rem;
};
typedef TYPE_1__ xcb_screen_iterator_t;
typedef int /*<<< orphan*/ xcb_connection_t;

/* Variables and functions */
int /*<<< orphan*/ xcb_get_setup(int /*<<< orphan*/ *);
int /*<<< orphan*/ xcb_screen_next(TYPE_1__ *);
TYPE_1__ xcb_setup_roots_iterator(int /*<<< orphan*/);
xcb_screen_t *xcb_aux_get_screen(xcb_connection_t *c, int screen) {
  xcb_screen_iterator_t i = xcb_setup_roots_iterator(xcb_get_setup(c));
  for (; i.rem; --screen, xcb_screen_next(&i))
    if (screen == 0)
      return i.data;
  return 0;
}


x86 assembly (clang, -O0):
<xcb_aux_get_screen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <xcb_get_setup@plt>
mov    %eax,%edi
call   1040 <xcb_setup_roots_iterator@plt>
mov    %rax,-0x28(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1195 <xcb_aux_get_screen+0x65>
cmpl   $0x0,-0x14(%rbp)
jne    1179 <xcb_aux_get_screen+0x49>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119d <xcb_aux_get_screen+0x6d>
jmp    117e <xcb_aux_get_screen+0x4e>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
call   1030 <xcb_screen_next@plt>
jmp    1157 <xcb_aux_get_screen+0x27>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xcb_aux_get_screen>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
call   1050 <xcb_get_setup@plt>
mov    %eax,%edi
call   1040 <xcb_setup_roots_iterator@plt>
mov    %rax,(%rsp)
mov    %rdx,0x8(%rsp)
test   %rdx,%rdx
je     1177 <xcb_aux_get_screen+0x47>
add    $0x1,%ebx
mov    %rsp,%r15
xor    %r14d,%r14d
xchg   %ax,%ax
add    $0xffffffff,%ebx
je     117c <xcb_aux_get_screen+0x4c>
mov    %r15,%rdi
call   1030 <xcb_screen_next@plt>
cmpq   $0x0,0x8(%rsp)
jne    1160 <xcb_aux_get_screen+0x30>
jmp    1180 <xcb_aux_get_screen+0x50>
xor    %r14d,%r14d
jmp    1180 <xcb_aux_get_screen+0x50>
mov    (%rsp),%r14
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32*, i64 }
define i32* @xcb_aux_get_screen(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca %struct.TYPE_4__
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = load i32*, i32** %4
%8 = call i32 @xcb_get_setup(i32* %7)
%9 = call { i32*, i64 } @xcb_setup_roots_iterator(i32 %8)
%10 = bitcast %struct.TYPE_4__* %6 to { i32*, i64 }*
%11 = getelementptr inbounds { i32*, i64 }, { i32*, i64 }* %10, i32 0, i32 0
%12 = extractvalue { i32*, i64 } %9, 0
store i32* %12, i32** %11
%13 = getelementptr inbounds { i32*, i64 }, { i32*, i64 }* %10, i32 0, i32 1
%14 = extractvalue { i32*, i64 } %9, 1
store i64 %14, i64* %13
br label %15
15: ; preds = %26, %2
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 1
%17 = load i64, i64* %16
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 0
%24 = load i32*, i32** %23
store i32* %24, i32** %3
br label %31
25: ; preds = %19
br label %26
26: ; preds = %25
%27 = load i32, i32* %5
%28 = add nsw i32 %27, -1
store i32 %28, i32* %5
%29 = call i32 @xcb_screen_next(%struct.TYPE_4__* %6)
br label %15
30: ; preds = %15
store i32* null, i32** %3
br label %31
31: ; preds = %30, %22
%32 = load i32*, i32** %3
ret i32* %32
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32*, i64 }
define i32* @xcb_aux_get_screen(i32* %0, i32 %1) {
%3 = alloca %struct.TYPE_4__
%4 = bitcast %struct.TYPE_4__* %3 to i8*
%5 = tail call i32 @xcb_get_setup(i32* %0)
%6 = tail call { i32*, i64 } @xcb_setup_roots_iterator(i32 %5)
%7 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
%8 = extractvalue { i32*, i64 } %6, 0
store i32* %8, i32** %7
%9 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 1
%10 = extractvalue { i32*, i64 } %6, 1
store i64 %10, i64* %9
%11 = icmp eq i64 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %2, %17
%13 = phi i32 [ %18, %17 ], [ %1, %2 ]
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = load i32*, i32** %7
br label %22
17: ; preds = %12
%18 = add nsw i32 %13, -1
%19 = call i32 @xcb_screen_next(%struct.TYPE_4__* %3)
%20 = load i64, i64* %9
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %12
22: ; preds = %17, %2, %15
%23 = phi i32* [ %16, %15 ], [ null, %2 ], [ null, %17 ]
ret i32* %23
}