#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 */

/* Type definitions */
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int DefaultScreen(int /*<<< orphan*/ *);
int ScreenCount(int /*<<< orphan*/ *);
scalar_t__ XNVCTRLIsNvScreen(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ stderr;
int GetNvXScreen(Display *dpy) {
  int defaultScreen, screen;
  defaultScreen = DefaultScreen(dpy);
  if (XNVCTRLIsNvScreen(dpy, defaultScreen)) {
    return defaultScreen;
  }
  for (screen = 0; screen < ScreenCount(dpy); screen++) {
    if (XNVCTRLIsNvScreen(dpy, screen)) {
      printf("Default X screen %d is not an NVIDIA X screen.  "
             "Using X screen %d instead.\n",
             defaultScreen, screen);
      return screen;
    }
  }
  fprintf(stderr, "Unable to find any NVIDIA X screens; aborting.\n");
  exit(1);
}


x86 assembly (clang, -O0):
<GetNvXScreen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <DefaultScreen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <XNVCTRLIsNvScreen@plt>
cmp    $0x0,%rax
je     1199 <GetNvXScreen+0x39>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1221 <GetNvXScreen+0xc1>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ScreenCount@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    1202 <GetNvXScreen+0xa2>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1060 <XNVCTRLIsNvScreen@plt>
cmp    $0x0,%rax
je     11ef <GetNvXScreen+0x8f>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe21(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1221 <GetNvXScreen+0xc1>
jmp    11f4 <GetNvXScreen+0x94>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a0 <GetNvXScreen+0x40>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetNvXScreen>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1080 <DefaultScreen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <XNVCTRLIsNvScreen@plt>
test   %rax,%rax
je     1183 <GetNvXScreen+0x23>
mov    %r14d,%ebp
jmp    11ee <GetNvXScreen+0x8e>
mov    %rbx,%rdi
call   1040 <ScreenCount@plt>
test   %eax,%eax
jle    11be <GetNvXScreen+0x5e>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <XNVCTRLIsNvScreen@plt>
test   %rax,%rax
jne    11dd <GetNvXScreen+0x7d>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1040 <ScreenCount@plt>
cmp    %eax,%ebp
jl     11a0 <GetNvXScreen+0x40>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe1c(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [76 x i8] c"Default X screen %d is not an NVIDIA X screen. Using X screen %d instead.\0A\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"Unable to find any NVIDIA X screens; aborting.\0A\00"
define i32 @GetNvXScreen(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call i32 @DefaultScreen(i32* %6)
store i32 %7, i32* %4
%8 = load i32*, i32** %3
%9 = load i32, i32* %4
%10 = call i64 @XNVCTRLIsNvScreen(i32* %8, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = load i32, i32* %4
store i32 %13, i32* %2
br label %38
14: ; preds = %1
store i32 0, i32* %5
br label %15
15: ; preds = %31, %14
%16 = load i32, i32* %5
%17 = load i32*, i32** %3
%18 = call i32 @ScreenCount(i32* %17)
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %34
20: ; preds = %15
%21 = load i32*, i32** %3
%22 = load i32, i32* %5
%23 = call i64 @XNVCTRLIsNvScreen(i32* %21, i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %27)
%29 = load i32, i32* %5
store i32 %29, i32* %2
br label %38
30: ; preds = %20
br label %31
31: ; preds = %30
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %15
34: ; preds = %15
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %25, %12
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@.str = [76 x i8] c"Default X screen %d is not an NVIDIA X screen. Using X screen %d instead.\0A\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"Unable to find any NVIDIA X screens; aborting.\0A\00"
define i32 @GetNvXScreen(i32* %0) {
%2 = tail call i32 @DefaultScreen(i32* %0)
%3 = tail call i64 @XNVCTRLIsNvScreen(i32* %0, i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %22
5: ; preds = %1
%6 = tail call i32 @ScreenCount(i32* %0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %5, %14
%9 = phi i32 [ %15, %14 ], [ 0, %5 ]
%10 = tail call i64 @XNVCTRLIsNvScreen(i32* %0, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %9)
br label %22
14: ; preds = %8
%15 = add nuw nsw i32 %9, 1
%16 = tail call i32 @ScreenCount(i32* %0)
%17 = icmp slt i32 %15, %16
br i1 %17, label %8, label %18
18: ; preds = %14, %5
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %1, %12
%23 = phi i32 [ %9, %12 ], [ %2, %1 ]
ret i32 %23
}