#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 /*<<< orphan*/ *XOpenDisplay(char *);
int /*<<< orphan*/ printf(char *, char *);
Display *find_x_display() {
  int i;
  Display *dpy;
  char dname[] = ":0";
  for (i = 0; i < 10; ++i) {
    dname[1] = i + '0';
    dpy = XOpenDisplay(dname);
    if (dpy) {
      printf("dname: %s\n", dname);
      return dpy;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_x_display>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xed1(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xec9(%rip),%al
mov    %al,-0x19(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    119e <find_x_display+0x7e>
mov    -0xc(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x1a(%rbp)
lea    -0x1b(%rbp),%rdi
call   1040 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118b <find_x_display+0x6b>
lea    -0x1b(%rbp),%rsi
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <find_x_display+0x86>
jmp    1190 <find_x_display+0x70>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <find_x_display+0x23>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_x_display>:
push   %rbx
sub    $0x10,%rsp
movw   $0x303a,0xc(%rsp)
movb   $0x0,0xe(%rsp)
movb   $0x30,0xd(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <XOpenDisplay@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1227 <find_x_display+0x107>
movb   $0x31,0xd(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <XOpenDisplay@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1227 <find_x_display+0x107>
movb   $0x32,0xd(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <XOpenDisplay@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1227 <find_x_display+0x107>
movb   $0x33,0xd(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <XOpenDisplay@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1227 <find_x_display+0x107>
movb   $0x34,0xd(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <XOpenDisplay@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1227 <find_x_display+0x107>
movb   $0x35,0xd(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <XOpenDisplay@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1227 <find_x_display+0x107>
movb   $0x36,0xd(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <XOpenDisplay@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1227 <find_x_display+0x107>
movb   $0x37,0xd(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <XOpenDisplay@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1227 <find_x_display+0x107>
movb   $0x38,0xd(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <XOpenDisplay@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1227 <find_x_display+0x107>
movb   $0x39,0xd(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <XOpenDisplay@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1241 <find_x_display+0x121>
lea    0xdd5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1030 <printf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
xor    %ebx,%ebx
jmp    1238 <find_x_display+0x118>

LLVM IR (-O0):
@__const.find_x_display.dname = [3 x i8] c":0\00"
@.str = [11 x i8] c"dname: %s\0A\00"
define i32* @find_x_display() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [3 x i8]
%5 = bitcast [3 x i8]* %4 to i8*
store i32 0, i32* %2
br label %6
6: ; preds = %23, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 10
br i1 %8, label %9, label %26
9: ; preds = %6
%10 = load i32, i32* %2
%11 = add nsw i32 %10, 48
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
store i8 %12, i8* %13
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%15 = call i32* @XOpenDisplay(i8* %14)
store i32* %15, i32** %3
%16 = load i32*, i32** %3
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %9
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32*, i32** %3
store i32* %21, i32** %1
br label %27
22: ; preds = %9
br label %23
23: ; preds = %22
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
store i32 %25, i32* %2
br label %6
26: ; preds = %6
store i32* null, i32** %1
br label %27
27: ; preds = %26, %18
%28 = load i32*, i32** %1
ret i32* %28
}

LLVM IR (-O2):
@__const.find_x_display.dname = [3 x i8] c":0\00"
@.str = [11 x i8] c"dname: %s\0A\00"
define i32* @find_x_display() {
%1 = alloca [3 x i8]
%2 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 1
store i8 48, i8* %3
%4 = call i32* @XOpenDisplay(i8* %2)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %33
6: ; preds = %0
store i8 49, i8* %3
%7 = call i32* @XOpenDisplay(i8* %2)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %33
9: ; preds = %6
store i8 50, i8* %3
%10 = call i32* @XOpenDisplay(i8* %2)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %33
12: ; preds = %9
store i8 51, i8* %3
%13 = call i32* @XOpenDisplay(i8* %2)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %33
15: ; preds = %12
store i8 52, i8* %3
%16 = call i32* @XOpenDisplay(i8* %2)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %33
18: ; preds = %15
store i8 53, i8* %3
%19 = call i32* @XOpenDisplay(i8* %2)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %33
21: ; preds = %18
store i8 54, i8* %3
%22 = call i32* @XOpenDisplay(i8* %2)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %33
24: ; preds = %21
store i8 55, i8* %3
%25 = call i32* @XOpenDisplay(i8* %2)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %33
27: ; preds = %24
store i8 56, i8* %3
%28 = call i32* @XOpenDisplay(i8* %2)
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %27
store i8 57, i8* %3
%31 = call i32* @XOpenDisplay(i8* %2)
%32 = icmp eq i32* %31, null
br i1 %32, label %36, label %33
33: ; preds = %30, %27, %24, %21, %18, %15, %12, %9, %6, %0
%34 = phi i32* [ %4, %0 ], [ %7, %6 ], [ %10, %9 ], [ %13, %12 ], [ %16, %15 ], [ %19, %18 ], [ %22, %21 ], [ %25, %24 ], [ %28, %27 ], [ %31, %30 ]
%35 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %36
36: ; preds = %30, %33
%37 = phi i32* [ %34, %33 ], [ null, %30 ]
ret i32* %37
}