#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*/ XCloseDisplay(int /*<<< orphan*/ *);
char *XDisplayString(int /*<<< orphan*/ *);
int /*<<< orphan*/ *XOpenDisplay(char const *);
int get_display_name_length(char *);
scalar_t__ strncmp(char *, char *, int);
int match_display_name(Display *x11_dpy, const char *display_name) {
  Display *test_dpy;
  char *test_dpy_name, *x11_dpy_name;
  int test_dpy_namelen, x11_dpy_namelen;
  int m;
  test_dpy = XOpenDisplay(display_name);
  if (!test_dpy)
    return 0;
  test_dpy_name = XDisplayString(test_dpy);
  test_dpy_namelen = get_display_name_length(test_dpy_name);
  x11_dpy_name = XDisplayString(x11_dpy);
  x11_dpy_namelen = get_display_name_length(x11_dpy_name);
  m = (test_dpy_namelen == x11_dpy_namelen &&
       (test_dpy_namelen == 0 ||
        (test_dpy_namelen > 0 &&
         strncmp(test_dpy_name, x11_dpy_name, test_dpy_namelen) == 0)));
  XCloseDisplay(test_dpy);
  return m;
}


x86 assembly (clang, -O0):
<match_display_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <XOpenDisplay@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1184 <match_display_name+0x34>
movl   $0x0,-0x4(%rbp)
jmp    1225 <match_display_name+0xd5>
mov    -0x20(%rbp),%rdi
call   1050 <XDisplayString@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <get_display_name_length@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <XDisplayString@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <get_display_name_length@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%ecx
xor    %eax,%eax
cmp    -0x38(%rbp),%ecx
mov    %al,-0x3d(%rbp)
jne    120b <match_display_name+0xbb>
mov    $0x1,%al
cmpl   $0x0,-0x34(%rbp)
mov    %al,-0x3e(%rbp)
je     1205 <match_display_name+0xb5>
xor    %eax,%eax
cmpl   $0x0,-0x34(%rbp)
mov    %al,-0x3f(%rbp)
jle    11ff <match_display_name+0xaf>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x3f(%rbp)
mov    -0x3f(%rbp),%al
mov    %al,-0x3e(%rbp)
mov    -0x3e(%rbp),%al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <XCloseDisplay@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_display_name>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1040 <XOpenDisplay@plt>
test   %rax,%rax
je     11bb <match_display_name+0x6b>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <XDisplayString@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <get_display_name_length@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1050 <XDisplayString@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <get_display_name_length@plt>
xor    %ebp,%ebp
cmp    %eax,%r15d
jne    11c4 <match_display_name+0x74>
test   %r15d,%r15d
je     11bf <match_display_name+0x6f>
jle    11c4 <match_display_name+0x74>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1030 <strncmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
jmp    11c4 <match_display_name+0x74>
xor    %ebp,%ebp
jmp    11cc <match_display_name+0x7c>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1070 <XCloseDisplay@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @match_display_name(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%12 = load i8*, i8** %5
%13 = call i32* @XOpenDisplay(i8* %12)
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %2
store i32 0, i32* %3
br label %51
17: ; preds = %2
%18 = load i32*, i32** %6
%19 = call i8* @XDisplayString(i32* %18)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = call i32 @get_display_name_length(i8* %20)
store i32 %21, i32* %9
%22 = load i32*, i32** %4
%23 = call i8* @XDisplayString(i32* %22)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = call i32 @get_display_name_length(i8* %24)
store i32 %25, i32* %10
%26 = load i32, i32* %9
%27 = load i32, i32* %10
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %45
29: ; preds = %17
%30 = load i32, i32* %9
%31 = icmp eq i32 %30, 0
br i1 %31, label %43, label %32
32: ; preds = %29
%33 = load i32, i32* %9
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = load i8*, i8** %7
%37 = load i8*, i8** %8
%38 = load i32, i32* %9
%39 = call i64 @strncmp(i8* %36, i8* %37, i32 %38)
%40 = icmp eq i64 %39, 0
br label %41
41: ; preds = %35, %32
%42 = phi i1 [ false, %32 ], [ %40, %35 ]
br label %43
43: ; preds = %41, %29
%44 = phi i1 [ true, %29 ], [ %42, %41 ]
br label %45
45: ; preds = %43, %17
%46 = phi i1 [ false, %17 ], [ %44, %43 ]
%47 = zext i1 %46 to i32
store i32 %47, i32* %11
%48 = load i32*, i32** %6
%49 = call i32 @XCloseDisplay(i32* %48)
%50 = load i32, i32* %11
store i32 %50, i32* %3
br label %51
51: ; preds = %45, %16
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
define i32 @match_display_name(i32* %0, i8* %1) {
%3 = tail call i32* @XOpenDisplay(i8* %1)
%4 = icmp eq i32* %3, null
br i1 %4, label %22, label %5
5: ; preds = %2
%6 = tail call i8* @XDisplayString(i32* %3)
%7 = tail call i32 @get_display_name_length(i8* %6)
%8 = tail call i8* @XDisplayString(i32* %0)
%9 = tail call i32 @get_display_name_length(i8* %8)
%10 = icmp eq i32 %7, %9
br i1 %10, label %11, label %19
11: ; preds = %5
%12 = icmp eq i32 %7, 0
br i1 %12, label %19, label %13
13: ; preds = %11
%14 = icmp sgt i32 %7, 0
br i1 %14, label %15, label %19
15: ; preds = %13
%16 = tail call i64 @strncmp(i8* %6, i8* %8, i32 %7)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %11, %15, %13, %5
%20 = phi i32 [ 0, %5 ], [ 1, %11 ], [ 0, %13 ], [ %18, %15 ]
%21 = tail call i32 @XCloseDisplay(i32* %3)
br label %22
22: ; preds = %2, %19
%23 = phi i32 [ %20, %19 ], [ 0, %2 ]
ret i32 %23
}