#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 uint8_t;
struct timespec {
  int tv_sec;
  int tv_nsec;
};
struct sched_param {
  int sched_priority;
};
typedef int /*<<< orphan*/ mode_t;
typedef int int32_t;
typedef int /*<<< orphan*/ cpu_set_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ CPU_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ CPU_ZERO(int /*<<< orphan*/ *);
int EINTR;
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ SCHED_FIFO;
int /*<<< orphan*/ TIMER_ABSTIME;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ addTimes(struct timespec *, struct timespec);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int clock_nanosleep(int /*<<< orphan*/, int /*<<< orphan*/, struct timespec *,
                    int /*<<< orphan*/ *);
int close(int);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ printWithStatus(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ pthread_self();
int pthread_setschedparam(int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sched_param *);
int sched_setaffinity(int /*<<< orphan*/, int, int /*<<< orphan*/ *);
int shm_open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int timeDiff(struct timespec *, struct timespec *);
int main(int argc, char *argv[]) {
  double remainder;
  int ret;
  struct timespec tp, prev, now, periodTp, timeout, timeoutDuration;
  periodTp.tv_sec = 0;
  periodTp.tv_nsec = 10000000;
  timeoutDuration.tv_sec = 10;
  printf("\033c");
  cpu_set_t cpu;
  CPU_ZERO(&cpu);
  CPU_SET(1, &cpu);
  printf("Setting CPU Affinity to CPU%d... ", 1);
  ret = sched_setaffinity(0, sizeof(cpu_set_t), &cpu);
  printWithStatus("", ret);
  struct sched_param params;
  params.sched_priority = 99;
  printf("Setting thread priority to %d... ", 99);
  ret = pthread_setschedparam(pthread_self(), SCHED_FIFO, &params);
  printWithStatus("", ret);
  printf("Waiting for LabVIEW to create shared memory...\n");
  clock_gettime(CLOCK_MONOTONIC, &timeout);
  addTimes(&timeout, timeoutDuration);
  do {
    clock_gettime(CLOCK_MONOTONIC, &tp);
    remainder = timeDiff(&tp, &timeout);
    printf("\rTimeout: %1.2f  \n", remainder);
    printf("\033[1A");
    if (remainder < 0)
      break;
    addTimes(&tp, periodTp);
    clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &tp, NULL);
  } while (access("/dev/shm/simple", F_OK) != 0);
  if (remainder < 0) {
    printf("\rLabVIEW did not create shared memory within timeout period. "
           "Exiting.\n\n");
    return 0;
  } else
    ;
  int fd = shm_open("/simple", O_RDWR, (mode_t)0777);
  printWithStatus("\rShared memory file detected.\nOpening file descriptor... ",
                  (fd < 0));
  void *mmapPointer =
      mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  printWithStatus("Mapping memory... ", (mmapPointer == (void *)-1));
  ret = close(fd);
  printWithStatus("Closing file descriptor... ", (ret != 0));
  void *pTemp = mmapPointer;
  uint8_t *lv_stop = (uint8_t *)pTemp;
  pTemp += sizeof(uint8_t);
  uint8_t *lv_bool = (uint8_t *)pTemp;
  pTemp += sizeof(uint8_t);
  double *lv_double = (double *)pTemp;
  pTemp += sizeof(double);
  int32_t *lv_int = (int32_t *)pTemp;
  pTemp += sizeof(int32_t);
  printf("\nRunning main loop until LabVIEW asserts STOP... \n");
  clock_gettime(CLOCK_MONOTONIC, &now);
  do {
    prev = now;
    clock_gettime(CLOCK_MONOTONIC, &now);
    printf("\rPeriod: %02.3f ms   ", (timeDiff(&prev, &now) * 1000));
    printf("\nBoolean:   %1d  ", *lv_bool);
    printf("\nDouble:    %+f             ", *lv_double);
    printf("\nI32:       %+d             ", *lv_int);
    printf("\n\033[4A");
    tp = now;
    addTimes(&tp, periodTp);
    do {
      ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &tp, NULL);
    } while (ret == EINTR && ret != 0);
  } while (!*lv_stop);
  printf("\n\n\n\nLabVIEW asserted STOP.\n");
  printf("Exiting.\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x989680,-0x3c(%rbp)
movl   $0xa,-0x50(%rbp)
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x54(%rbp),%rdi
call   10c0 <CPU_ZERO@plt>
mov    $0x1,%edi
lea    -0x54(%rbp),%rsi
call   1110 <CPU_SET@plt>
lea    0xdb9(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1080 <printf@plt>
xor    %edi,%edi
mov    $0x4,%esi
lea    -0x54(%rbp),%rdx
call   10a0 <sched_setaffinity@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe73(%rip),%rdi
call   1030 <printWithStatus@plt>
movl   $0x63,-0x58(%rbp)
lea    0xd9f(%rip),%rdi
mov    $0x63,%esi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x0,%al
call   10d0 <pthread_self@plt>
mov    %eax,%edi
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdx
call   1040 <pthread_setschedparam@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe2c(%rip),%rdi
call   1030 <printWithStatus@plt>
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%rsi
call   1050 <clock_gettime@plt>
mov    -0x50(%rbp),%rsi
lea    -0x48(%rbp),%rdi
call   1060 <addTimes@plt>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1050 <clock_gettime@plt>
lea    -0x28(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   10b0 <timeDiff@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xd57(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1348 <main+0x158>
jmp    1393 <main+0x1a3>
mov    -0x40(%rbp),%rsi
lea    -0x28(%rbp),%rdi
call   1060 <addTimes@plt>
mov    0x2c6c(%rip),%rax
mov    (%rax),%edi
mov    0x2c6b(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1100 <clock_nanosleep@plt>
mov    0x2c1d(%rip),%rax
mov    (%rax),%esi
lea    0xd0b(%rip),%rdi
call   10e0 <access@plt>
cmp    $0x0,%rax
jne    12ec <main+0xfc>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    13bb <main+0x1cb>
lea    0xcf7(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    161e <main+0x42e>
jmp    13c0 <main+0x1d0>
mov    0x2c11(%rip),%rax
mov    (%rax),%esi
lea    0xcc7(%rip),%rdi
mov    $0x1ff,%edx
call   10f0 <shm_open@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xcf7(%rip),%rdi
call   1030 <printWithStatus@plt>
mov    0x2bfc(%rip),%rax
mov    (%rax),%edx
mov    0x2ba3(%rip),%rax
or     (%rax),%edx
mov    0x2bda(%rip),%rax
mov    (%rax),%ecx
mov    -0x5c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
xor    %r9d,%r9d
call   1070 <mmap@plt>
mov    %rax,-0x68(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x68(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xcde(%rip),%rdi
call   1030 <printWithStatus@plt>
mov    -0x5c(%rbp),%edi
call   1090 <close@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%esi
lea    0xcce(%rip),%rdi
call   1030 <printWithStatus@plt>
mov    -0x68(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x70(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x70(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x70(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x70(%rbp)
lea    0xc80(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    0x2aea(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1050 <clock_gettime@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2ad0(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1050 <clock_gettime@plt>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10b0 <timeDiff@plt>
imul   $0x3e8,%eax,%esi
lea    0xc66(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x80(%rbp),%rax
mov    (%rax),%esi
lea    0xc68(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x88(%rbp),%rax
movsd  (%rax),%xmm0
lea    0xc61(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
mov    -0x90(%rbp),%rax
mov    (%rax),%esi
lea    0xc67(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xc76(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%rsi
lea    -0x28(%rbp),%rdi
call   1060 <addTimes@plt>
mov    0x2a36(%rip),%rax
mov    (%rax),%edi
mov    0x2a35(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1100 <clock_nanosleep@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
mov    0x29f7(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x91(%rbp)
jne    15d4 <main+0x3e4>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
mov    %al,-0x91(%rbp)
mov    -0x91(%rbp),%al
test   $0x1,%al
jne    158b <main+0x39b>
jmp    15e7 <main+0x3f7>
mov    -0x78(%rbp),%rax
cmpl   $0x0,(%rax)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    14e9 <main+0x2f9>
lea    0xbe9(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xacc(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xdeb(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x34(%rsp),%rbx
mov    %rbx,%rdi
call   10d0 <CPU_ZERO@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1120 <CPU_SET@plt>
lea    0xdc6(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %rbx,%rdx
call   10b0 <sched_setaffinity@plt>
lea    0xdfa(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printWithStatus@plt>
movl   $0x63,0x8(%rsp)
lea    0xdad(%rip),%rdi
mov    $0x63,%esi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %eax,%eax
call   10e0 <pthread_self@plt>
mov    0x2d2e(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1050 <pthread_setschedparam@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printWithStatus@plt>
lea    0xe8f(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d0b(%rip),%r12
mov    (%r12),%edi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <clock_gettime@plt>
mov    $0xa,%esi
mov    %rbx,%rdi
call   1070 <addTimes@plt>
lea    0x18(%rsp),%rbp
lea    0xd73(%rip),%r15
mov    0x2ce2(%rip),%r13
lea    0xd6a(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12),%edi
mov    %rbp,%rsi
call   1060 <clock_gettime@plt>
mov    %rbp,%rdi
lea    0x20(%rsp),%rsi
call   10c0 <timeDiff@plt>
mov    %eax,%r14d
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xd1d(%rip),%rdi
mov    $0x1,%al
call   1090 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
test   %r14d,%r14d
js     1504 <main+0x304>
mov    %rbp,%rdi
movabs $0x98968000000000,%rsi
call   1070 <addTimes@plt>
mov    (%r12),%edi
mov    0x0(%r13),%esi
mov    %rbp,%rdx
xor    %ecx,%ecx
call   1110 <clock_nanosleep@plt>
mov    0x2c29(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10f0 <access@plt>
test   %rax,%rax
jne    1300 <main+0x100>
mov    0x2c53(%rip),%rax
mov    (%rax),%esi
lea    0xcd9(%rip),%rdi
mov    $0x1ff,%edx
call   1100 <shm_open@plt>
mov    %eax,%ebp
mov    %eax,%esi
shr    $0x1f,%esi
lea    0xcc9(%rip),%rdi
call   1030 <printWithStatus@plt>
mov    0x2c46(%rip),%rax
mov    0x2bef(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c24(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1080 <mmap@plt>
mov    %rax,%rbx
xor    %esi,%esi
cmp    $0xffffffffffffffff,%rax
sete   %sil
lea    0xcbd(%rip),%rdi
call   1030 <printWithStatus@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
xor    %esi,%esi
test   %eax,%eax
setne  %sil
lea    0xcb5(%rip),%rdi
call   1030 <printWithStatus@plt>
lea    0xd5c(%rip),%rdi
call   1040 <puts@plt>
mov    (%r12),%edi
lea    0x10(%rsp),%r15
mov    %r15,%rsi
call   1060 <clock_gettime@plt>
lea    0x18(%rsp),%rbp
mov    0x2b7b(%rip),%r14
jmp    1449 <main+0x249>
nopw   0x0(%rax,%rax,1)
cmpl   $0x0,(%rbx)
jne    150d <main+0x30d>
mov    0x10(%rsp),%rax
mov    %rax,0x28(%rsp)
mov    (%r12),%edi
mov    %r15,%rsi
call   1060 <clock_gettime@plt>
lea    0x28(%rsp),%rdi
mov    %r15,%rsi
call   10c0 <timeDiff@plt>
imul   $0x3e8,%eax,%esi
lea    0xc5f(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x4(%rbx),%esi
lea    0xc64(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
movsd  0x8(%rbx),%xmm0
lea    0xc63(%rip),%rdi
mov    $0x1,%al
call   1090 <printf@plt>
mov    0x10(%rbx),%esi
lea    0xc6f(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xc7e(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x10(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    %rbp,%rdi
movabs $0x98968000000000,%rsi
call   1070 <addTimes@plt>
nop
mov    (%r12),%edi
mov    0x0(%r13),%esi
mov    %rbp,%rdx
xor    %ecx,%ecx
call   1110 <clock_nanosleep@plt>
test   %eax,%eax
je     1440 <main+0x240>
cmp    (%r14),%eax
je     14e0 <main+0x2e0>
jmp    1440 <main+0x240>
lea    0xcb1(%rip),%rdi
jmp    1520 <main+0x320>
lea    0xc8d(%rip),%rdi
call   1040 <puts@plt>
lea    0xcd9(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.sched_param = type { i32 }
@.str = [3 x i8] c"\1Bc\00"
@.str.1 = [34 x i8] c"Setting CPU Affinity to CPU%d... \00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [34 x i8] c"Setting thread priority to %d... \00"
@SCHED_FIFO = global i32 0
@.str.4 = [48 x i8] c"Waiting for LabVIEW to create shared memory...\0A\00"
@CLOCK_MONOTONIC = global i32 0
@.str.5 = [19 x i8] c"\0DTimeout: %1.2f \0A\00"
@.str.6 = [5 x i8] c"\1B[1A\00"
@TIMER_ABSTIME = global i32 0
@.str.7 = [16 x i8] c"/dev/shm/simple\00"
@F_OK = global i32 0
@.str.8 = [72 x i8] c"\0DLabVIEW did not create shared memory within timeout period. Exiting.\0A\0A\00"
@.str.9 = [8 x i8] c"/simple\00"
@O_RDWR = global i32 0
@.str.10 = [58 x i8] c"\0DShared memory file detected.\0AOpening file descriptor... \00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.11 = [19 x i8] c"Mapping memory... \00"
@.str.12 = [28 x i8] c"Closing file descriptor... \00"
@.str.13 = [51 x i8] c"\0ARunning main loop until LabVIEW asserts STOP... \0A\00"
@.str.14 = [22 x i8] c"\0DPeriod: %02.3f ms \00"
@.str.15 = [18 x i8] c"\0ABoolean: %1d \00"
@.str.16 = [29 x i8] c"\0ADouble: %+f \00"
@.str.17 = [29 x i8] c"\0AI32: %+d \00"
@.str.18 = [6 x i8] c"\0A\1B[4A\00"
@EINTR = global i32 0
@.str.19 = [28 x i8] c"\0A\0A\0A\0ALabVIEW asserted STOP.\0A\00"
@.str.20 = [11 x i8] c"Exiting.\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i32
%8 = alloca %struct.timespec
%9 = alloca %struct.timespec
%10 = alloca %struct.timespec
%11 = alloca %struct.timespec
%12 = alloca %struct.timespec
%13 = alloca %struct.timespec
%14 = alloca i32
%15 = alloca %struct.sched_param
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i32*
%20 = alloca i32*
%21 = alloca double*
%22 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 0
store i32 0, i32* %23
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 1
store i32 10000000, i32* %24
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 0
store i32 10, i32* %25
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @CPU_ZERO(i32* %14)
%28 = call i32 @CPU_SET(i32 1, i32* %14)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 1)
%30 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %14)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = call i32 @printWithStatus(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %15, i32 0, i32 0
store i32 99, i32* %33
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 99)
%35 = call i32 (...) @pthread_self()
%36 = load i32, i32* @SCHED_FIFO
%37 = call i32 @pthread_setschedparam(i32 %35, i32 %36, %struct.sched_param* %15)
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = call i32 @printWithStatus(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%41 = load i32, i32* @CLOCK_MONOTONIC
%42 = call i32 @clock_gettime(i32 %41, %struct.timespec* %12)
%43 = bitcast %struct.timespec* %13 to i64*
%44 = load i64, i64* %43
%45 = call i32 @addTimes(%struct.timespec* %12, i64 %44)
br label %46
46: ; preds = %64, %2
%47 = load i32, i32* @CLOCK_MONOTONIC
%48 = call i32 @clock_gettime(i32 %47, %struct.timespec* %8)
%49 = call i32 @timeDiff(%struct.timespec* %8, %struct.timespec* %12)
%50 = sitofp i32 %49 to double
store double %50, double* %6
%51 = load double, double* %6
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), double %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%54 = load double, double* %6
%55 = fcmp olt double %54, 0.000000e+00
br i1 %55, label %56, label %57
56: ; preds = %46
br label %68
57: ; preds = %46
%58 = bitcast %struct.timespec* %11 to i64*
%59 = load i64, i64* %58
%60 = call i32 @addTimes(%struct.timespec* %8, i64 %59)
%61 = load i32, i32* @CLOCK_MONOTONIC
%62 = load i32, i32* @TIMER_ABSTIME
%63 = call i32 @clock_nanosleep(i32 %61, i32 %62, %struct.timespec* %8, i32* null)
br label %64
64: ; preds = %57
%65 = load i32, i32* @F_OK
%66 = call i64 @access(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i32 %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %46, label %68
68: ; preds = %64, %56
%69 = load double, double* %6
%70 = fcmp olt double %69, 0.000000e+00
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %3
br label %162
73: ; preds = %68
br label %74
74: ; preds = %73
%75 = load i32, i32* @O_RDWR
%76 = call i32 @shm_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i32 %75, i32 511)
store i32 %76, i32* %16
%77 = load i32, i32* %16
%78 = icmp slt i32 %77, 0
%79 = zext i1 %78 to i32
%80 = call i32 @printWithStatus(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.10, i64 0, i64 0), i32 %79)
%81 = load i32, i32* @PROT_READ
%82 = load i32, i32* @PROT_WRITE
%83 = or i32 %81, %82
%84 = load i32, i32* @MAP_SHARED
%85 = load i32, i32* %16
%86 = call i8* @mmap(i32* null, i32 4096, i32 %83, i32 %84, i32 %85, i32 0)
store i8* %86, i8** %17
%87 = load i8*, i8** %17
%88 = icmp eq i8* %87, inttoptr (i64 -1 to i8*)
%89 = zext i1 %88 to i32
%90 = call i32 @printWithStatus(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i32 %89)
%91 = load i32, i32* %16
%92 = call i32 @close(i32 %91)
store i32 %92, i32* %7
%93 = load i32, i32* %7
%94 = icmp ne i32 %93, 0
%95 = zext i1 %94 to i32
%96 = call i32 @printWithStatus(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i32 %95)
%97 = load i8*, i8** %17
store i8* %97, i8** %18
%98 = load i8*, i8** %18
%99 = bitcast i8* %98 to i32*
store i32* %99, i32** %19
%100 = load i8*, i8** %18
%101 = getelementptr i8, i8* %100, i64 4
store i8* %101, i8** %18
%102 = load i8*, i8** %18
%103 = bitcast i8* %102 to i32*
store i32* %103, i32** %20
%104 = load i8*, i8** %18
%105 = getelementptr i8, i8* %104, i64 4
store i8* %105, i8** %18
%106 = load i8*, i8** %18
%107 = bitcast i8* %106 to double*
store double* %107, double** %21
%108 = load i8*, i8** %18
%109 = getelementptr i8, i8* %108, i64 8
store i8* %109, i8** %18
%110 = load i8*, i8** %18
%111 = bitcast i8* %110 to i32*
store i32* %111, i32** %22
%112 = load i8*, i8** %18
%113 = getelementptr i8, i8* %112, i64 4
store i8* %113, i8** %18
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.13, i64 0, i64 0))
%115 = load i32, i32* @CLOCK_MONOTONIC
%116 = call i32 @clock_gettime(i32 %115, %struct.timespec* %10)
br label %117
117: ; preds = %154, %74
%118 = bitcast %struct.timespec* %9 to i8*
%119 = bitcast %struct.timespec* %10 to i8*
%120 = load i32, i32* @CLOCK_MONOTONIC
%121 = call i32 @clock_gettime(i32 %120, %struct.timespec* %10)
%122 = call i32 @timeDiff(%struct.timespec* %9, %struct.timespec* %10)
%123 = mul nsw i32 %122, 1000
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0), i32 %123)
%125 = load i32*, i32** %20
%126 = load i32, i32* %125
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0), i32 %126)
%128 = load double*, double** %21
%129 = load double, double* %128
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.16, i64 0, i64 0), double %129)
%131 = load i32*, i32** %22
%132 = load i32, i32* %131
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.17, i64 0, i64 0), i32 %132)
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.18, i64 0, i64 0))
%135 = bitcast %struct.timespec* %8 to i8*
%136 = bitcast %struct.timespec* %10 to i8*
%137 = bitcast %struct.timespec* %11 to i64*
%138 = load i64, i64* %137
%139 = call i32 @addTimes(%struct.timespec* %8, i64 %138)
br label %140
140: ; preds = %151, %117
%141 = load i32, i32* @CLOCK_MONOTONIC
%142 = load i32, i32* @TIMER_ABSTIME
%143 = call i32 @clock_nanosleep(i32 %141, i32 %142, %struct.timespec* %8, i32* null)
store i32 %143, i32* %7
br label %144
144: ; preds = %140
%145 = load i32, i32* %7
%146 = load i32, i32* @EINTR
%147 = icmp eq i32 %145, %146
br i1 %147, label %148, label %151
148: ; preds = %144
%149 = load i32, i32* %7
%150 = icmp ne i32 %149, 0
br label %151
151: ; preds = %148, %144
%152 = phi i1 [ false, %144 ], [ %150, %148 ]
br i1 %152, label %140, label %153
153: ; preds = %151
br label %154
154: ; preds = %153
%155 = load i32*, i32** %19
%156 = load i32, i32* %155
%157 = icmp ne i32 %156, 0
%158 = xor i1 %157, true
br i1 %158, label %117, label %159
159: ; preds = %154
%160 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.19, i64 0, i64 0))
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.20, i64 0, i64 0))
store i32 0, i32* %3
br label %162
162: ; preds = %159, %71
%163 = load i32, i32* %3
ret i32 %163
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
%struct.sched_param = type { i32 }
@.str = [3 x i8] c"\1Bc\00"
@.str.1 = [34 x i8] c"Setting CPU Affinity to CPU%d... \00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [34 x i8] c"Setting thread priority to %d... \00"
@SCHED_FIFO = global i32 0
@CLOCK_MONOTONIC = global i32 0
@.str.5 = [19 x i8] c"\0DTimeout: %1.2f \0A\00"
@.str.6 = [5 x i8] c"\1B[1A\00"
@TIMER_ABSTIME = global i32 0
@.str.7 = [16 x i8] c"/dev/shm/simple\00"
@F_OK = global i32 0
@.str.9 = [8 x i8] c"/simple\00"
@O_RDWR = global i32 0
@.str.10 = [58 x i8] c"\0DShared memory file detected.\0AOpening file descriptor... \00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.11 = [19 x i8] c"Mapping memory... \00"
@.str.12 = [28 x i8] c"Closing file descriptor... \00"
@.str.14 = [22 x i8] c"\0DPeriod: %02.3f ms \00"
@.str.15 = [18 x i8] c"\0ABoolean: %1d \00"
@.str.16 = [29 x i8] c"\0ADouble: %+f \00"
@.str.17 = [29 x i8] c"\0AI32: %+d \00"
@.str.18 = [6 x i8] c"\0A\1B[4A\00"
@EINTR = global i32 0
@str = [47 x i8] c"Waiting for LabVIEW to create shared memory...\00"
@str.21 = [50 x i8] c"\0ARunning main loop until LabVIEW asserts STOP... \00"
@str.22 = [27 x i8] c"\0A\0A\0A\0ALabVIEW asserted STOP.\00"
@str.23 = [10 x i8] c"Exiting.\0A\00"
@str.24 = [71 x i8] c"\0DLabVIEW did not create shared memory within timeout period. Exiting.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to %struct.timespec*
%5 = alloca i64
%6 = bitcast i64* %5 to %struct.timespec*
%7 = alloca i64
%8 = bitcast i64* %7 to %struct.timespec*
%9 = alloca %struct.timespec
%10 = alloca i32
%11 = alloca %struct.sched_param
%12 = bitcast i64* %3 to i8*
%13 = bitcast i64* %5 to i8*
%14 = bitcast i64* %7 to i8*
%15 = bitcast %struct.timespec* %9 to i8*
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = bitcast i32* %10 to i8*
%18 = call i32 @CPU_ZERO(i32* %10)
%19 = call i32 @CPU_SET(i32 1, i32* %10)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 1)
%21 = call i32 @sched_setaffinity(i32 0, i32 4, i32* %10)
%22 = call i32 @printWithStatus(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = bitcast %struct.sched_param* %11 to i8*
%24 = getelementptr inbounds %struct.sched_param, %struct.sched_param* %11, i64 0, i32 0
store i32 99, i32* %24
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 99)
%26 = call i32 (...) @pthread_self()
%27 = load i32, i32* @SCHED_FIFO
%28 = call i32 @pthread_setschedparam(i32 %26, i32 %27, %struct.sched_param* %11)
%29 = call i32 @printWithStatus(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%31 = load i32, i32* @CLOCK_MONOTONIC
%32 = call i32 @clock_gettime(i32 %31, %struct.timespec* %9)
%33 = call i32 @addTimes(%struct.timespec* %9, i64 10)
br label %34
34: ; preds = %42, %2
%35 = load i32, i32* @CLOCK_MONOTONIC
%36 = call i32 @clock_gettime(i32 %35, %struct.timespec* %4)
%37 = call i32 @timeDiff(%struct.timespec* %4, %struct.timespec* %9)
%38 = sitofp i32 %37 to double
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), double %38)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%41 = icmp slt i32 %37, 0
br i1 %41, label %106, label %42
42: ; preds = %34
%43 = call i32 @addTimes(%struct.timespec* %4, i64 42949672960000000)
%44 = load i32, i32* @CLOCK_MONOTONIC
%45 = load i32, i32* @TIMER_ABSTIME
%46 = call i32 @clock_nanosleep(i32 %44, i32 %45, %struct.timespec* %4, i32* null)
%47 = load i32, i32* @F_OK
%48 = call i64 @access(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i32 %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %34
50: ; preds = %42
%51 = load i32, i32* @O_RDWR
%52 = call i32 @shm_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i32 %51, i32 511)
%53 = lshr i32 %52, 31
%54 = call i32 @printWithStatus(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.10, i64 0, i64 0), i32 %53)
%55 = load i32, i32* @PROT_READ
%56 = load i32, i32* @PROT_WRITE
%57 = or i32 %56, %55
%58 = load i32, i32* @MAP_SHARED
%59 = call i8* @mmap(i32* null, i32 4096, i32 %57, i32 %58, i32 %52, i32 0)
%60 = icmp eq i8* %59, inttoptr (i64 -1 to i8*)
%61 = zext i1 %60 to i32
%62 = call i32 @printWithStatus(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i32 %61)
%63 = call i32 @close(i32 %52)
%64 = icmp ne i32 %63, 0
%65 = zext i1 %64 to i32
%66 = call i32 @printWithStatus(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i32 %65)
%67 = bitcast i8* %59 to i32*
%68 = getelementptr i8, i8* %59, i64 4
%69 = bitcast i8* %68 to i32*
%70 = getelementptr i8, i8* %59, i64 8
%71 = bitcast i8* %70 to double*
%72 = getelementptr i8, i8* %59, i64 16
%73 = bitcast i8* %72 to i32*
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.21, i64 0, i64 0))
%75 = load i32, i32* @CLOCK_MONOTONIC
%76 = call i32 @clock_gettime(i32 %75, %struct.timespec* %8)
br label %77
77: ; preds = %101, %50
%78 = load i64, i64* %7
store i64 %78, i64* %5
%79 = load i32, i32* @CLOCK_MONOTONIC
%80 = call i32 @clock_gettime(i32 %79, %struct.timespec* %8)
%81 = call i32 @timeDiff(%struct.timespec* %6, %struct.timespec* %8)
%82 = mul nsw i32 %81, 1000
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0), i32 %82)
%84 = load i32, i32* %69
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0), i32 %84)
%86 = load double, double* %71
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.16, i64 0, i64 0), double %86)
%88 = load i32, i32* %73
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.17, i64 0, i64 0), i32 %88)
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.18, i64 0, i64 0))
%91 = load i64, i64* %7
store i64 %91, i64* %3
%92 = call i32 @addTimes(%struct.timespec* %4, i64 42949672960000000)
br label %93
93: ; preds = %93, %77
%94 = load i32, i32* @CLOCK_MONOTONIC
%95 = load i32, i32* @TIMER_ABSTIME
%96 = call i32 @clock_nanosleep(i32 %94, i32 %95, %struct.timespec* %4, i32* null)
%97 = load i32, i32* @EINTR
%98 = icmp eq i32 %96, %97
%99 = icmp ne i32 %96, 0
%100 = and i1 %99, %98
br i1 %100, label %93, label %101
101: ; preds = %93
%102 = load i32, i32* %67
%103 = icmp eq i32 %102, 0
br i1 %103, label %77, label %104
104: ; preds = %101
%105 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.22, i64 0, i64 0))
br label %106
106: ; preds = %34, %104
%107 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.23, i64 0, i64 0), %104 ], [ getelementptr inbounds ([71 x i8], [71 x i8]* @str.24, i64 0, i64 0), %34 ]
%108 = call i32 @puts(i8* dereferenceable(1) %107)
ret i32 0
}