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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strdup(char *);
int read_display_ref(char *refid, char **display) {
  int rc;
  FILE *file;
  char rdisplay[256];
  char ref_file[256];
  if (snprintf(ref_file, 256, "/tmp/slurm-spank-x11.%s", refid) >= 256) {
    fprintf(stderr, "error: unable to build file reference\n");
    return 20;
  }
  file = fopen(ref_file, "r");
  if (file == NULL) {
    fprintf(stderr, "error: unable to open file %s\n", ref_file);
    return 30;
  }
  if (fscanf(file, "%256s\n", rdisplay) != 1) {
    fprintf(stderr,
            "warning: unable to read DISPLAY value "
            "from file %s\n",
            ref_file);
    rc = 31;
  } else {
    *display = strdup(rdisplay);
    fflush(stdout);
    rc = 0;
  }
  fclose(file);
  return rc;
}


x86 assembly (clang, -O0):
<read_display_ref>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xe66(%rip),%rdx
call   1040 <snprintf@plt>
cmp    $0x100,%eax
jl     11cd <read_display_ref+0x5d>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x14,-0x4(%rbp)
jmp    129d <read_display_ref+0x12d>
lea    -0x230(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1219 <read_display_ref+0xa9>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    -0x230(%rbp),%rdx
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1e,-0x4(%rbp)
jmp    129d <read_display_ref+0x12d>
mov    -0x28(%rbp),%rdi
lea    -0x130(%rbp),%rdx
lea    0xe35(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0x1,%eax
je     1263 <read_display_ref+0xf3>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    -0x230(%rbp),%rdx
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1f,-0x1c(%rbp)
jmp    128e <read_display_ref+0x11e>
lea    -0x130(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_display_ref>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%r14
mov    %rdi,%rcx
lea    0xe78(%rip),%rdx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1040 <snprintf@plt>
cmp    $0x100,%eax
jl     11bd <read_display_ref+0x4d>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x14,%ebp
jmp    125a <read_display_ref+0xea>
lea    0xe7b(%rip),%rsi
mov    %rsp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1212 <read_display_ref+0xa2>
mov    %rax,%rbx
lea    0xe85(%rip),%rsi
lea    0x100(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    1233 <read_display_ref+0xc3>
lea    0x100(%rsp),%rdi
call   1090 <strdup@plt>
mov    %rax,(%r14)
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
xor    %ebp,%ebp
jmp    1252 <read_display_ref+0xe2>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1e,%ebp
jmp    125a <read_display_ref+0xea>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1f,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"/tmp/slurm-spank-x11.%s\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"error: unable to build file reference\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [31 x i8] c"error: unable to open file %s\0A\00"
@.str.4 = [7 x i8] c"%256s\0A\00"
@.str.5 = [52 x i8] c"warning: unable to read DISPLAY value from file %s\0A\00"
@stdout = global i32 0
define i32 @read_display_ref(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [256 x i8]
%9 = alloca [256 x i8]
store i8* %0, i8** %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%11 = load i8*, i8** %4
%12 = call i32 @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = icmp sge i32 %12, 256
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
store i32 20, i32* %3
br label %45
17: ; preds = %2
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %19, i32** %7
%20 = load i32*, i32** %7
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %24)
store i32 30, i32* %3
br label %45
26: ; preds = %17
%27 = load i32*, i32** %7
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%29 = call i32 @fscanf(i32* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %28)
%30 = icmp ne i32 %29, 1
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i8* %33)
store i32 31, i32* %6
br label %41
35: ; preds = %26
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%37 = call i8* @strdup(i8* %36)
%38 = load i8**, i8*** %5
store i8* %37, i8** %38
%39 = load i32, i32* @stdout
%40 = call i32 @fflush(i32 %39)
store i32 0, i32* %6
br label %41
41: ; preds = %35, %31
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
%44 = load i32, i32* %6
store i32 %44, i32* %3
br label %45
45: ; preds = %41, %22, %14
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [24 x i8] c"/tmp/slurm-spank-x11.%s\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"error: unable to build file reference\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [31 x i8] c"error: unable to open file %s\0A\00"
@.str.4 = [7 x i8] c"%256s\0A\00"
@.str.5 = [52 x i8] c"warning: unable to read DISPLAY value from file %s\0A\00"
@stdout = global i32 0
define i32 @read_display_ref(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = call i32 @snprintf(i8* %6, i32 256, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = icmp sgt i32 %7, 255
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %31
12: ; preds = %2
%13 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %6)
br label %31
18: ; preds = %12
%19 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%20 = icmp eq i32 %19, 1
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i8* %6)
br label %28
24: ; preds = %18
%25 = call i8* @strdup(i8* %5)
store i8* %25, i8** %1
%26 = load i32, i32* @stdout
%27 = call i32 @fflush(i32 %26)
br label %28
28: ; preds = %24, %21
%29 = phi i32 [ 31, %21 ], [ 0, %24 ]
%30 = call i32 @fclose(i32* %13)
br label %31
31: ; preds = %28, %15, %9
%32 = phi i32 [ 20, %9 ], [ 30, %15 ], [ %29, %28 ]
ret i32 %32
}