#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 *x11_get_screen(xcb_connection_t *xc, int screen) {
  xcb_screen_iterator_t iter;
  iter = xcb_setup_roots_iterator(xcb_get_setup(xc));
  for (; iter.rem; screen--, xcb_screen_next(&iter)) {
    if (screen == 0) {
      return iter.data;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<x11_get_screen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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,-0x38(%rbp)
mov    %rdx,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a5 <x11_get_screen+0x75>
cmpl   $0x0,-0x14(%rbp)
jne    1189 <x11_get_screen+0x59>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ad <x11_get_screen+0x7d>
jmp    118e <x11_get_screen+0x5e>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
call   1030 <xcb_screen_next@plt>
jmp    1167 <x11_get_screen+0x37>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<x11_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 <x11_get_screen+0x47>
add    $0x1,%ebx
mov    %rsp,%r15
xor    %r14d,%r14d
xchg   %ax,%ax
add    $0xffffffff,%ebx
je     117c <x11_get_screen+0x4c>
mov    %r15,%rdi
call   1030 <xcb_screen_next@plt>
cmpq   $0x0,0x8(%rsp)
jne    1160 <x11_get_screen+0x30>
jmp    1180 <x11_get_screen+0x50>
xor    %r14d,%r14d
jmp    1180 <x11_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* @x11_get_screen(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca %struct.TYPE_4__
%7 = alloca %struct.TYPE_4__
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = load i32*, i32** %4
%9 = call i32 @xcb_get_setup(i32* %8)
%10 = call { i32*, i64 } @xcb_setup_roots_iterator(i32 %9)
%11 = bitcast %struct.TYPE_4__* %7 to { i32*, i64 }*
%12 = getelementptr inbounds { i32*, i64 }, { i32*, i64 }* %11, i32 0, i32 0
%13 = extractvalue { i32*, i64 } %10, 0
store i32* %13, i32** %12
%14 = getelementptr inbounds { i32*, i64 }, { i32*, i64 }* %11, i32 0, i32 1
%15 = extractvalue { i32*, i64 } %10, 1
store i64 %15, i64* %14
%16 = bitcast %struct.TYPE_4__* %6 to i8*
%17 = bitcast %struct.TYPE_4__* %7 to i8*
br label %18
18: ; preds = %29, %2
%19 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 1
%20 = load i64, i64* %19
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %18
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 0
%27 = load i32*, i32** %26
store i32* %27, i32** %3
br label %34
28: ; preds = %22
br label %29
29: ; preds = %28
%30 = load i32, i32* %5
%31 = add nsw i32 %30, -1
store i32 %31, i32* %5
%32 = call i32 @xcb_screen_next(%struct.TYPE_4__* %6)
br label %18
33: ; preds = %18
store i32* null, i32** %3
br label %34
34: ; preds = %33, %25
%35 = load i32*, i32** %3
ret i32* %35
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32*, i64 }
define i32* @x11_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 = extractvalue { i32*, i64 } %6, 0
%8 = extractvalue { i32*, i64 } %6, 1
%9 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
store i32* %7, i32** %9
%10 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 1
store i64 %8, i64* %10
%11 = icmp eq i64 %8, 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** %9
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* %10
%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
}