#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 */
scalar_t__ EEXIST;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
char *getenv(char *);
int mkdir(char *, int);
scalar_t__ mkdtemp(char *);
int /*<<< orphan*/ perror(char *);
int setenv(char *, char *, int);
int snprintf(char *, int, char *, char const *);
void set_xdg_runtime_dir(void) {
  char xdg_runtime_dir[256];
  const char *xrd_env;
  xrd_env = getenv("XDG_RUNTIME_DIR");
  assert((snprintf(xdg_runtime_dir, 256, "%s/wayland-tests-XXXXXX",
                   xrd_env ? xrd_env : "/tmp") < 256) &&
         "test error: XDG_RUNTIME_DIR too long");
  assert(mkdtemp(xdg_runtime_dir) && "test error: mkdtemp failed");
  if (mkdir(xdg_runtime_dir, 0700) == -1)
    if (errno != EEXIST) {
      perror("Creating XDG_RUNTIME_DIR");
      abort();
    }
  if (setenv("XDG_RUNTIME_DIR", xdg_runtime_dir, 1) == -1) {
    perror("Setting XDG_RUNTIME_DIR");
    abort();
  }
}


x86 assembly (clang, -O0):
<set_xdg_runtime_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    0xed4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x108(%rbp)
lea    -0x100(%rbp),%rax
mov    %rax,-0x110(%rbp)
cmpq   $0x0,-0x108(%rbp)
je     11cd <set_xdg_runtime_dir+0x4d>
mov    -0x108(%rbp),%rax
mov    %rax,-0x118(%rbp)
jmp    11e0 <set_xdg_runtime_dir+0x60>
lea    0xe44(%rip),%rax
mov    %rax,-0x118(%rbp)
jmp    11e0 <set_xdg_runtime_dir+0x60>
mov    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rcx
mov    $0x100,%esi
lea    0xe06(%rip),%rdx
call   1070 <snprintf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x100,%ecx
mov    %al,-0x119(%rbp)
jge    1222 <set_xdg_runtime_dir+0xa2>
mov    $0x1,%al
mov    %al,-0x119(%rbp)
jmp    1222 <set_xdg_runtime_dir+0xa2>
mov    -0x119(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x100(%rbp),%rdi
call   1090 <mkdtemp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11a(%rbp)
je     1260 <set_xdg_runtime_dir+0xe0>
mov    $0x1,%al
mov    %al,-0x11a(%rbp)
jmp    1260 <set_xdg_runtime_dir+0xe0>
mov    -0x11a(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x100(%rbp),%rdi
mov    $0x1c0,%esi
call   1050 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    12bc <set_xdg_runtime_dir+0x13c>
mov    0x2d47(%rip),%rax
mov    (%rax),%rax
mov    0x2d45(%rip),%rcx
cmp    (%rcx),%rax
je     12b7 <set_xdg_runtime_dir+0x137>
lea    0xdb2(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    12bc <set_xdg_runtime_dir+0x13c>
lea    -0x100(%rbp),%rsi
lea    0xd9c(%rip),%rdi
mov    $0x1,%edx
call   1060 <setenv@plt>
cmp    $0xffffffff,%eax
jne    12f0 <set_xdg_runtime_dir+0x170>
lea    0xd92(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x0,%al
call   1040 <abort@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_xdg_runtime_dir>:
push   %rbx
sub    $0x100,%rsp
lea    0xe97(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe7a(%rip),%rcx
cmovne %rax,%rcx
lea    0xe57(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1070 <snprintf@plt>
xor    %edi,%edi
cmp    $0x100,%eax
setl   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
call   1090 <mkdtemp@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
mov    $0x1c0,%esi
call   1050 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    1207 <set_xdg_runtime_dir+0x87>
mov    0x2de0(%rip),%rax
mov    (%rax),%rax
mov    0x2dde(%rip),%rcx
cmp    (%rcx),%rax
jne    1232 <set_xdg_runtime_dir+0xb2>
lea    0xe18(%rip),%rdi
mov    %rsp,%rsi
mov    $0x1,%edx
call   1060 <setenv@plt>
cmp    $0xffffffff,%eax
je     1229 <set_xdg_runtime_dir+0xa9>
add    $0x100,%rsp
pop    %rbx
ret
lea    0xe06(%rip),%rdi
jmp    1239 <set_xdg_runtime_dir+0xb9>
lea    0xde4(%rip),%rdi
call   10a0 <perror@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"XDG_RUNTIME_DIR\00"
@.str.1 = [24 x i8] c"%s/wayland-tests-XXXXXX\00"
@.str.2 = [5 x i8] c"/tmp\00"
@.str.3 = [37 x i8] c"test error: XDG_RUNTIME_DIR too long\00"
@.str.4 = [27 x i8] c"test error: mkdtemp failed\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.5 = [25 x i8] c"Creating XDG_RUNTIME_DIR\00"
@.str.6 = [24 x i8] c"Setting XDG_RUNTIME_DIR\00"
define void @set_xdg_runtime_dir() {
%1 = alloca [256 x i8]
%2 = alloca i8*
%3 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %2
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = load i8*, i8** %2
br label %10
9: ; preds = %0
br label %10
10: ; preds = %9, %7
%11 = phi i8* [ %8, %7 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %9 ]
%12 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = icmp slt i32 %12, 256
br i1 %13, label %14, label %15
14: ; preds = %10
br label %15
15: ; preds = %14, %10
%16 = phi i1 [ false, %10 ], [ true, %14 ]
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%20 = call i64 @mkdtemp(i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %15
br label %23
23: ; preds = %22, %15
%24 = phi i1 [ false, %15 ], [ true, %22 ]
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%28 = call i32 @mkdir(i8* %27, i32 448)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %38
30: ; preds = %23
%31 = load i64, i64* @errno
%32 = load i64, i64* @EEXIST
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32 (...) @abort()
unreachable
37: ; preds = %30
br label %38
38: ; preds = %37, %23
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%40 = call i32 @setenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %39, i32 1)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%44 = call i32 (...) @abort()
unreachable
45: ; preds = %38
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"XDG_RUNTIME_DIR\00"
@.str.1 = [24 x i8] c"%s/wayland-tests-XXXXXX\00"
@.str.2 = [5 x i8] c"/tmp\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.5 = [25 x i8] c"Creating XDG_RUNTIME_DIR\00"
@.str.6 = [24 x i8] c"Setting XDG_RUNTIME_DIR\00"
define void @set_xdg_runtime_dir() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
%5 = select i1 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3
%6 = call i32 @snprintf(i8* %2, i32 256, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%7 = icmp slt i32 %6, 256
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = call i64 @mkdtemp(i8* %2)
%11 = icmp ne i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i32 @mkdir(i8* %2, i32 448)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %0
%17 = load i64, i64* @errno
%18 = load i64, i64* @EEXIST
%19 = icmp eq i64 %17, %18
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %16, %0
%24 = call i32 @setenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %2, i32 1)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%28 = call i32 (...) @abort()
unreachable
29: ; preds = %23
ret void
}