#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *getenv(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
Display *open_display(int *argc, char **argv) {
  char *ptr;
  char dispname[256];
  Display *display;
  if ((ptr = getenv("DISPLAY")))
    strcpy(dispname, ptr);
  else
    strcpy(dispname, ":0.0");
  if (!(display = XOpenDisplay(dispname))) {
    fprintf(stderr, "Unable to open display %s\n", dispname);
    exit(1);
  }
  return display;
}


x86 assembly (clang, -O0):
<open_display>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe96(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1192 <open_display+0x42>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    11a5 <open_display+0x55>
lea    -0x120(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x120(%rbp),%rdi
call   1050 <XOpenDisplay@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
jne    11e8 <open_display+0x98>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rdx
lea    0xe34(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x128(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_display>:
sub    $0x108,%rsp
lea    0xea2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1170 <open_display+0x20>
mov    %rsp,%rdi
mov    %rax,%rsi
jmp    117a <open_display+0x2a>
lea    0xe91(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcpy@plt>
mov    %rsp,%rdi
call   1050 <XOpenDisplay@plt>
test   %rax,%rax
je     1194 <open_display+0x44>
add    $0x108,%rsp
ret
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
mov    %rsp,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"DISPLAY\00"
@.str.1 = [5 x i8] c":0.0\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Unable to open display %s\0A\00"
define i32* @open_display(i32* %0, i8** %1) {
%3 = alloca i32*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca [256 x i8]
%7 = alloca i32*
store i32* %0, i32** %3
store i8** %1, i8*** %4
%8 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = call i32 @strcpy(i8* %11, i8* %12)
br label %17
14: ; preds = %2
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %14, %10
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%19 = call i32* @XOpenDisplay(i8* %18)
store i32* %19, i32** %7
%20 = icmp ne i32* %19, null
br i1 %20, label %26, label %21
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %17
%27 = load i32*, i32** %7
ret i32* %27
}

LLVM IR (-O2):
@.str = [8 x i8] c"DISPLAY\00"
@.str.1 = [5 x i8] c":0.0\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Unable to open display %s\0A\00"
define i32* @open_display(i32* nocapture readnone %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = call i32 @strcpy(i8* %4, i8* %5)
br label %11
9: ; preds = %2
%10 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %7
%12 = call i32* @XOpenDisplay(i8* %4)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
ret i32* %12
}