#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 */
struct timespec {
  int tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ clock_nanosleep(int /*<<< orphan*/, int /*<<< orphan*/,
                                   struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
void waitForDCAF() {
  char printStr[128];
  struct timespec tp_1ms;
  tp_1ms.tv_sec = 0;
  tp_1ms.tv_nsec = 1000000;
  printStr[0] = '\0';
  strcat(printStr, "\nWaiting for DCAF to create shared memory.\n\n");
  printf("%s", printStr);
  char path[100] = "/dev/shm";
  strcat(path, "/dcaf_version");
  while (access(path, F_OK) != 0) {
    clock_nanosleep(CLOCK_MONOTONIC, 0, &tp_1ms, NULL);
  }
}


x86 assembly (clang, -O0):
<waitForDCAF>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movq   $0x0,-0x88(%rbp)
movl   $0xf4240,-0x90(%rbp)
movb   $0x0,-0x80(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x80(%rbp),%rsi
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
lea    -0x100(%rbp),%rdi
lea    0xe9e(%rip),%rsi
mov    $0x64,%edx
call   1040 <memcpy@plt>
lea    -0x100(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x100(%rbp),%rdi
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
je     11fe <waitForDCAF+0xae>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
lea    -0x90(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <clock_nanosleep@plt>
jmp    11bf <waitForDCAF+0x6f>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitForDCAF>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
movq   $0x0,0x8(%rsp)
movl   $0xf4240,(%rsp)
movb   $0x0,0x80(%rsp)
lea    0xe93(%rip),%rsi
lea    0x80(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strcat@plt>
lea    0xea9(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
movaps 0xefd(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xee1(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xec5(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xea9(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe8d(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe71(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x70(%rsp)
lea    0xe4d(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    0x2dd9(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <access@plt>
test   %rax,%rax
je     1240 <waitForDCAF+0x100>
mov    0x2dda(%rip),%r12
mov    %rsp,%r14
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    (%r12),%edi
xor    %esi,%esi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1060 <clock_nanosleep@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <access@plt>
test   %rax,%rax
jne    1220 <waitForDCAF+0xe0>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@.str = [45 x i8] c"\0AWaiting for DCAF to create shared memory.\0A\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@__const.waitForDCAF.path = [100 x i8] c"/dev/shm\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.2 = [14 x i8] c"/dcaf_version\00"
@F_OK = global i32 0
@CLOCK_MONOTONIC = global i32 0
define void @waitForDCAF() {
%1 = alloca [128 x i8]
%2 = alloca %struct.timespec
%3 = alloca [100 x i8]
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i64 0, i64* %4
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i32 1000000, i32* %5
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
store i8 0, i8* %6
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%8 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%10 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = bitcast [100 x i8]* %3 to i8*
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%13 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %19, %0
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%16 = load i32, i32* @F_OK
%17 = call i64 @access(i8* %15, i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* @CLOCK_MONOTONIC
%21 = call i32 @clock_nanosleep(i32 %20, i32 0, %struct.timespec* %2, i32* null)
br label %14
22: ; preds = %14
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@.str = [45 x i8] c"\0AWaiting for DCAF to create shared memory.\0A\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@__const.waitForDCAF.path = [100 x i8] c"/dev/shm\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.2 = [14 x i8] c"/dcaf_version\00"
@F_OK = global i32 0
@CLOCK_MONOTONIC = global i32 0
define void @waitForDCAF() {
%1 = alloca [128 x i8]
%2 = alloca %struct.timespec
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%5 = bitcast %struct.timespec* %2 to i8*
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 0, i64* %6
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 1000000, i32* %7
store i8 0, i8* %4
%8 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%11 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @F_OK
%13 = call i64 @access(i8* %10, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %0, %15
%16 = load i32, i32* @CLOCK_MONOTONIC
%17 = call i32 @clock_nanosleep(i32 %16, i32 0, %struct.timespec* %2, i32* null)
%18 = load i32, i32* @F_OK
%19 = call i64 @access(i8* %10, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %15
21: ; preds = %15, %0
ret void
}