#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*/ *);
int /*<<< orphan*/ *XOpenDisplay(char const *);
int /*<<< orphan*/ print_display(char const *);
int /*<<< orphan*/ printf(char *);
int open_display(const char *display_name, int verbose) {
  int opened = 0;
  Display *disp = XOpenDisplay(display_name);
  if (disp) {
    opened = 1;
    if (verbose) {
      printf("Opened ");
      print_display(display_name);
      printf("\n");
    }
    XCloseDisplay(disp);
  }
  return opened;
}


x86 assembly (clang, -O0):
<open_display>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a9 <open_display+0x69>
movl   $0x1,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11a0 <open_display+0x60>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <print_display@plt>
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <XCloseDisplay@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_display>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
call   1060 <XOpenDisplay@plt>
test   %rax,%rax
je     1197 <open_display+0x47>
mov    %rax,%r14
test   %ebp,%ebp
je     1188 <open_display+0x38>
lea    0xe8f(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <print_display@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1070 <XCloseDisplay@plt>
mov    $0x1,%eax
jmp    1199 <open_display+0x49>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"Opened \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @open_display(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = call i32* @XOpenDisplay(i8* %7)
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %22
11: ; preds = %2
store i32 1, i32* %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %3
%17 = call i32 @print_display(i8* %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %14, %11
%20 = load i32*, i32** %6
%21 = call i32 @XCloseDisplay(i32* %20)
br label %22
22: ; preds = %19, %2
%23 = load i32, i32* %5
ret i32 %23
}

LLVM IR (-O2):
@.str = [8 x i8] c"Opened \00"
define i32 @open_display(i8* %0, i32 %1) {
%3 = tail call i32* @XOpenDisplay(i8* %0)
%4 = icmp eq i32* %3, null
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = icmp eq i32 %1, 0
br i1 %6, label %11, label %7
7: ; preds = %5
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @print_display(i8* %0)
%10 = tail call i32 @putchar(i32 10)
br label %11
11: ; preds = %7, %5
%12 = tail call i32 @XCloseDisplay(i32* %3)
br label %13
13: ; preds = %11, %2
%14 = phi i32 [ 1, %11 ], [ 0, %2 ]
ret i32 %14
}