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

/* Variables and functions */
int checkRemote(char *);
char *getenv(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
char *strtok(char *, char *);
int remoteDisplay(char *display) {
  char *host = NULL;
  char *dpy = NULL;
  dpy = (char *)malloc(sizeof(char) * 255);
  if (!display) {
    dpy = getenv("DISPLAY");
  } else {
    sprintf(dpy, "%s", display);
  }
  if (!dpy) {
    return (0);
  }
  if (dpy[0] == ':') {
    return (0);
  }
  host = (char *)malloc(sizeof(char) * 255);
  host = strtok(dpy, ":");
  return (checkRemote(host));
}


x86 assembly (clang, -O0):
<remoteDisplay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0xff,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119a <remoteDisplay+0x4a>
lea    0xe74(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
jmp    11ae <remoteDisplay+0x5e>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe5f(%rip),%rsi
call   1070 <sprintf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11c5 <remoteDisplay+0x75>
movl   $0x0,-0x4(%rbp)
jmp    120f <remoteDisplay+0xbf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    11e1 <remoteDisplay+0x91>
movl   $0x0,-0x4(%rbp)
jmp    120f <remoteDisplay+0xbf>
mov    $0xff,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <checkRemote@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remoteDisplay>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0xff,%edi
call   1060 <malloc@plt>
test   %r14,%r14
je     117b <remoteDisplay+0x2b>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
test   %rbx,%rbx
jne    118f <remoteDisplay+0x3f>
jmp    1194 <remoteDisplay+0x44>
lea    0xe7e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rbx,%rbx
je     1194 <remoteDisplay+0x44>
cmpb   $0x3a,(%rbx)
jne    119e <remoteDisplay+0x4e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0xff,%edi
call   1060 <malloc@plt>
lea    0xe59(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strtok@plt>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <checkRemote@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"DISPLAY\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c":\00"
define i32 @remoteDisplay(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %4
store i8* null, i8** %5
%6 = call i64 @malloc(i32 255)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %5
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %5
br label %16
12: ; preds = %1
%13 = load i8*, i8** %5
%14 = load i8*, i8** %3
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %12, %10
%17 = load i8*, i8** %5
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %16
store i32 0, i32* %2
br label %34
20: ; preds = %16
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 58
br i1 %25, label %26, label %27
26: ; preds = %20
store i32 0, i32* %2
br label %34
27: ; preds = %20
%28 = call i64 @malloc(i32 255)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %4
%30 = load i8*, i8** %5
%31 = call i8* @strtok(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %31, i8** %4
%32 = load i8*, i8** %4
%33 = call i32 @checkRemote(i8* %32)
store i32 %33, i32* %2
br label %34
34: ; preds = %27, %26, %19
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [8 x i8] c"DISPLAY\00"
@.str.2 = [2 x i8] c":\00"
define i32 @remoteDisplay(i8* %0) {
%2 = tail call i64 @malloc(i32 255)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %9
7: ; preds = %1
%8 = tail call i8* @strcpy(i8* dereferenceable(1) %3, i8* %0)
br label %9
9: ; preds = %7, %5
%10 = phi i8* [ %3, %7 ], [ %6, %5 ]
%11 = icmp eq i8* %10, null
br i1 %11, label %19, label %12
12: ; preds = %9
%13 = load i8, i8* %10
%14 = icmp eq i8 %13, 58
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = tail call i64 @malloc(i32 255)
%17 = tail call i8* @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @checkRemote(i8* %17)
br label %19
19: ; preds = %12, %9, %15
%20 = phi i32 [ %18, %15 ], [ 0, %9 ], [ 0, %12 ]
ret i32 %20
}