#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;
typedef double uint32_t;
typedef long uint16_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ _SC_PAGESIZE;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *mmap(int /*<<< orphan*/ *, int /*<<< orphan*/, int, int /*<<< orphan*/,
           int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, float);
int /*<<< orphan*/ sleep(long);
int /*<<< orphan*/ stderr;
int strtol(char *, char **, int);
int /*<<< orphan*/ sysconf(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd, i;
  char *end;
  volatile void *cfg, *sts;
  volatile uint32_t *fifo;
  volatile uint8_t *rst;
  volatile uint16_t *cntr;
  long number;
  uint32_t buffer;
  float corr;
  errno = 0;
  number = (argc == 2) ? strtol(argv[1], &end, 10) : -1;
  if (errno != 0 || end == argv[1] || number < 1 || number > 30) {
    fprintf(stderr, "Usage: measure-corr [1-30]\n");
    return EXIT_FAILURE;
  }
  if ((fd = open("/dev/mem", O_RDWR)) < 0) {
    fprintf(stderr, "Cannot open /dev/mem.\n");
    return EXIT_FAILURE;
  }
  sts = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE, MAP_SHARED,
             fd, 0x40000000);
  cfg = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE, MAP_SHARED,
             fd, 0x40001000);
  fifo = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE, MAP_SHARED,
              fd, 0x4000B000);
  rst = (uint8_t *)(cfg + 3);
  cntr = (uint16_t *)(sts + 28);
  *rst &= ~1;
  *rst |= 1;
  sleep(number + 1);
  if (*cntr < number) {
    fprintf(stderr, "Not enough PPS pulses.\n");
    return EXIT_FAILURE;
  }
  buffer = 0;
  for (i = 0; i < number; ++i) {
    buffer += *fifo + 1;
  }
  corr = (125.0e6 * number / buffer - 1.0) * 1.0e6;
  if (corr < -100.0 || corr > 100.0) {
    fprintf(stderr, "Correction value is out of range.\n");
    return EXIT_FAILURE;
  }
  printf("%.2f\n", corr);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e2b(%rip),%rax
movq   $0x0,(%rax)
cmpl   $0x2,-0x8(%rbp)
jne    11bc <main+0x4c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x60(%rbp)
jmp    11c9 <main+0x59>
mov    $0xffffffff,%eax
mov    %eax,-0x60(%rbp)
jmp    11c9 <main+0x59>
mov    -0x60(%rbp),%eax
cltq
mov    %rax,-0x50(%rbp)
mov    0x2ddf(%rip),%rax
cmpq   $0x0,(%rax)
jne    120b <main+0x9b>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    0x8(%rcx),%rax
je     120b <main+0x9b>
cmpq   $0x1,-0x50(%rbp)
jl     120b <main+0x9b>
cmpq   $0x1e,-0x50(%rbp)
jle    1231 <main+0xc1>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14aa <main+0x33a>
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
lea    0xe03(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1278 <main+0x108>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14aa <main+0x33a>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,%esi
mov    0x2d69(%rip),%rax
mov    (%rax),%edx
mov    0x2d10(%rip),%rax
or     (%rax),%edx
mov    0x2d47(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x40000000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,%esi
mov    0x2d27(%rip),%rax
mov    (%rax),%edx
mov    0x2cce(%rip),%rax
or     (%rax),%edx
mov    0x2d05(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x40001000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    %eax,%esi
mov    0x2ce5(%rip),%rax
mov    (%rax),%edx
mov    0x2c8c(%rip),%rax
or     (%rax),%edx
mov    0x2cc3(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x4000b000,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1c,%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%ecx
and    $0xfffffffe,%ecx
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rax
mov    (%rax),%ecx
or     $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x50(%rbp),%rdi
add    $0x1,%rdi
call   1090 <sleep@plt>
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
cmp    -0x50(%rbp),%rax
jge    13b0 <main+0x240>
mov    0x2c2f(%rip),%rax
mov    (%rax),%edi
lea    0xcca(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2c0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14aa <main+0x33a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    -0x50(%rbp),%rax
jge    13f9 <main+0x289>
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xc33(%rip),%xmm1
addsd  %xmm1,%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13bf <main+0x24f>
cvtsi2sdq -0x50(%rbp),%xmm1
movsd  0xc11(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x58(%rbp),%xmm0
movsd  0xbf8(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xbe4(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x5c(%rbp)
movss  -0x5c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xbbe(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     1467 <main+0x2f7>
movss  -0x5c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xbc3(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    148d <main+0x31d>
mov    0x2b52(%rip),%rax
mov    (%rax),%edi
lea    0xc05(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2b2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14aa <main+0x33a>
movss  -0x5c(%rbp),%xmm0
lea    0xc06(%rip),%rdi
call   1040 <printf@plt>
mov    0x2afb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e33(%rip),%rbp
movq   $0x0,0x0(%rbp)
cmp    $0x2,%edi
jne    11af <main+0x3f>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0x10(%rsp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
cmpq   $0x0,0x0(%rbp)
je     11dc <main+0x6c>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r12d
mov    0x10(%rsp),%rax
cmp    0x8(%rbx),%rax
je     11af <main+0x3f>
test   %r12d,%r12d
jle    11af <main+0x3f>
cmp    $0x1f,%r12d
jge    11af <main+0x3f>
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
lea    0xe3f(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     12f1 <main+0x181>
mov    %eax,%ebx
movslq %r12d,%rbp
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    0x2dcc(%rip),%r13
mov    0x2d75(%rip),%r14
mov    (%r14),%edx
or     0x0(%r13),%edx
mov    0x2da7(%rip),%r15
mov    (%r15),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %ebx,%r8d
mov    $0x40000000,%r9d
call   1030 <mmap@plt>
mov    %rax,0x8(%rsp)
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    (%r14),%edx
or     0x0(%r13),%edx
mov    (%r15),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %ebx,%r8d
mov    $0x40001000,%r9d
call   1030 <mmap@plt>
mov    %rax,%r15
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   1080 <sysconf@plt>
mov    (%r14),%edx
or     0x0(%r13),%edx
mov    0x2d44(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %ebx,%r8d
mov    $0x4000b000,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
andl   $0xfffffffe,0x3(%r15)
orl    $0x1,0x3(%r15)
lea    0x1(%rbp),%rdi
call   1090 <sleep@plt>
mov    0x8(%rsp),%rax
mov    0x1c(%rax),%rax
cmp    %rbp,%rax
jge    1306 <main+0x196>
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
lea    0xd78(%rip),%rsi
jmp    11bf <main+0x4f>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
lea    0xd4c(%rip),%rsi
jmp    11bf <main+0x4f>
lea    -0x1(%rbp),%rcx
mov    %ebp,%eax
and    $0x3,%eax
cmp    $0x3,%rcx
jae    131b <main+0x1ab>
xorpd  %xmm0,%xmm0
jmp    1366 <main+0x1f6>
and    $0xfffffffffffffffc,%rbp
xorpd  %xmm0,%xmm0
movsd  0xcd5(%rip),%xmm1
nopl   0x0(%rax,%rax,1)
movsd  (%rbx),%xmm2
addsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
movsd  (%rbx),%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
movsd  (%rbx),%xmm2
addsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
movsd  (%rbx),%xmm0
addsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
add    $0xfffffffffffffffc,%rbp
jne    1330 <main+0x1c0>
test   %rax,%rax
je     1392 <main+0x222>
movsd  0xc8d(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%rbx),%xmm2
addsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
add    $0xffffffffffffffff,%rax
jne    1380 <main+0x210>
xorps  %xmm1,%xmm1
cvtsi2sd %r12d,%xmm1
mulsd  0xc66(%rip),%xmm1
divsd  %xmm0,%xmm1
addsd  0xc62(%rip),%xmm1
mulsd  0xc62(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  0xc5b(%rip),%xmm1
ucomiss %xmm0,%xmm1
ja     13eb <main+0x27b>
ucomiss 0xc53(%rip),%xmm0
ja     13eb <main+0x27b>
lea    0xcc5(%rip),%rdi
call   1040 <printf@plt>
mov    0x2bba(%rip),%rax
jmp    11cb <main+0x5b>
mov    0x2bce(%rip),%rax
mov    (%rax),%edi
lea    0xc81(%rip),%rsi
jmp    11bf <main+0x4f>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [28 x i8] c"Usage: measure-corr [1-30]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@.str.2 = [23 x i8] c"Cannot open /dev/mem.\0A\00"
@_SC_PAGESIZE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.3 = [24 x i8] c"Not enough PPS pulses.\0A\00"
@.str.4 = [35 x i8] c"Correction value is out of range.\0A\00"
@.str.5 = [6 x i8] c"%.2f\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca double*
%12 = alloca i32*
%13 = alloca i64*
%14 = alloca i64
%15 = alloca double
%16 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* @errno
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strtol(i8* %22, i8** %8, i32 10)
br label %25
24: ; preds = %2
br label %25
25: ; preds = %24, %19
%26 = phi i32 [ %23, %19 ], [ -1, %24 ]
%27 = sext i32 %26 to i64
store i64 %27, i64* %14
%28 = load i64, i64* @errno
%29 = icmp ne i64 %28, 0
br i1 %29, label %42, label %30
30: ; preds = %25
%31 = load i8*, i8** %8
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = icmp eq i8* %31, %34
br i1 %35, label %42, label %36
36: ; preds = %30
%37 = load i64, i64* %14
%38 = icmp slt i64 %37, 1
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = load i64, i64* %14
%41 = icmp sgt i64 %40, 30
br i1 %41, label %42, label %46
42: ; preds = %39, %36, %30, %25
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
store i32 %45, i32* %3
br label %142
46: ; preds = %39
%47 = load i32, i32* @O_RDWR
%48 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %47)
store i32 %48, i32* %6
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = load i32, i32* @stderr
%52 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
store i32 %53, i32* %3
br label %142
54: ; preds = %46
%55 = load i32, i32* @_SC_PAGESIZE
%56 = call i32 @sysconf(i32 %55)
%57 = load i32, i32* @PROT_READ
%58 = load i32, i32* @PROT_WRITE
%59 = or i32 %57, %58
%60 = load i32, i32* @MAP_SHARED
%61 = load i32, i32* %6
%62 = call i8* @mmap(i32* null, i32 %56, i32 %59, i32 %60, i32 %61, i32 1073741824)
store i8* %62, i8** %10
%63 = load i32, i32* @_SC_PAGESIZE
%64 = call i32 @sysconf(i32 %63)
%65 = load i32, i32* @PROT_READ
%66 = load i32, i32* @PROT_WRITE
%67 = or i32 %65, %66
%68 = load i32, i32* @MAP_SHARED
%69 = load i32, i32* %6
%70 = call i8* @mmap(i32* null, i32 %64, i32 %67, i32 %68, i32 %69, i32 1073745920)
store i8* %70, i8** %9
%71 = load i32, i32* @_SC_PAGESIZE
%72 = call i32 @sysconf(i32 %71)
%73 = load i32, i32* @PROT_READ
%74 = load i32, i32* @PROT_WRITE
%75 = or i32 %73, %74
%76 = load i32, i32* @MAP_SHARED
%77 = load i32, i32* %6
%78 = call i8* @mmap(i32* null, i32 %72, i32 %75, i32 %76, i32 %77, i32 1073786880)
%79 = bitcast i8* %78 to double*
store double* %79, double** %11
%80 = load i8*, i8** %9
%81 = getelementptr i8, i8* %80, i64 3
%82 = bitcast i8* %81 to i32*
store i32* %82, i32** %12
%83 = load i8*, i8** %10
%84 = getelementptr i8, i8* %83, i64 28
%85 = bitcast i8* %84 to i64*
store i64* %85, i64** %13
%86 = load i32*, i32** %12
%87 = load volatile i32, i32* %86
%88 = and i32 %87, -2
store volatile i32 %88, i32* %86
%89 = load i32*, i32** %12
%90 = load volatile i32, i32* %89
%91 = or i32 %90, 1
store volatile i32 %91, i32* %89
%92 = load i64, i64* %14
%93 = add nsw i64 %92, 1
%94 = call i32 @sleep(i64 %93)
%95 = load i64*, i64** %13
%96 = load volatile i64, i64* %95
%97 = load i64, i64* %14
%98 = icmp slt i64 %96, %97
br i1 %98, label %99, label %103
99: ; preds = %54
%100 = load i32, i32* @stderr
%101 = call i32 @fprintf(i32 %100, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%102 = load i32, i32* @EXIT_FAILURE
store i32 %102, i32* %3
br label %142
103: ; preds = %54
store double 0.000000e+00, double* %15
store i32 0, i32* %7
br label %104
104: ; preds = %115, %103
%105 = load i32, i32* %7
%106 = sext i32 %105 to i64
%107 = load i64, i64* %14
%108 = icmp slt i64 %106, %107
br i1 %108, label %109, label %118
109: ; preds = %104
%110 = load double*, double** %11
%111 = load volatile double, double* %110
%112 = fadd double %111, 1.000000e+00
%113 = load double, double* %15
%114 = fadd double %113, %112
store double %114, double* %15
br label %115
115: ; preds = %109
%116 = load i32, i32* %7
%117 = add nsw i32 %116, 1
store i32 %117, i32* %7
br label %104
118: ; preds = %104
%119 = load i64, i64* %14
%120 = sitofp i64 %119 to double
%121 = fmul double 1.250000e+08, %120
%122 = load double, double* %15
%123 = fdiv double %121, %122
%124 = fsub double %123, 1.000000e+00
%125 = fmul double %124, 1.000000e+06
%126 = fptrunc double %125 to float
store float %126, float* %16
%127 = load float, float* %16
%128 = fpext float %127 to double
%129 = fcmp olt double %128, -1.000000e+02
br i1 %129, label %134, label %130
130: ; preds = %118
%131 = load float, float* %16
%132 = fpext float %131 to double
%133 = fcmp ogt double %132, 1.000000e+02
br i1 %133, label %134, label %138
134: ; preds = %130, %118
%135 = load i32, i32* @stderr
%136 = call i32 @fprintf(i32 %135, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%137 = load i32, i32* @EXIT_FAILURE
store i32 %137, i32* %3
br label %142
138: ; preds = %130
%139 = load float, float* %16
%140 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), float %139)
%141 = load i32, i32* @EXIT_SUCCESS
store i32 %141, i32* %3
br label %142
142: ; preds = %138, %134, %99, %50, %42
%143 = load i32, i32* %3
ret i32 %143
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [28 x i8] c"Usage: measure-corr [1-30]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@.str.2 = [23 x i8] c"Cannot open /dev/mem.\0A\00"
@_SC_PAGESIZE = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.3 = [24 x i8] c"Not enough PPS pulses.\0A\00"
@.str.4 = [35 x i8] c"Correction value is out of range.\0A\00"
@.str.5 = [6 x i8] c"%.2f\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %22
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i32 @strtol(i8* %8, i8** %3, i32 10)
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %6
%13 = sext i32 %9 to i64
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = icmp eq i8* %14, %16
%18 = icmp slt i32 %9, 1
%19 = select i1 %17, i1 true, i1 %18
%20 = icmp sgt i32 %9, 30
%21 = select i1 %19, i1 true, i1 %20
br i1 %21, label %22, label %25
22: ; preds = %2, %12, %6
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %121
25: ; preds = %12
%26 = load i32, i32* @O_RDWR
%27 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %121
32: ; preds = %25
%33 = load i32, i32* @_SC_PAGESIZE
%34 = tail call i32 @sysconf(i32 %33)
%35 = load i32, i32* @PROT_READ
%36 = load i32, i32* @PROT_WRITE
%37 = or i32 %36, %35
%38 = load i32, i32* @MAP_SHARED
%39 = tail call i8* @mmap(i32* null, i32 %34, i32 %37, i32 %38, i32 %27, i32 1073741824)
%40 = load i32, i32* @_SC_PAGESIZE
%41 = tail call i32 @sysconf(i32 %40)
%42 = load i32, i32* @PROT_READ
%43 = load i32, i32* @PROT_WRITE
%44 = or i32 %43, %42
%45 = load i32, i32* @MAP_SHARED
%46 = tail call i8* @mmap(i32* null, i32 %41, i32 %44, i32 %45, i32 %27, i32 1073745920)
%47 = load i32, i32* @_SC_PAGESIZE
%48 = tail call i32 @sysconf(i32 %47)
%49 = load i32, i32* @PROT_READ
%50 = load i32, i32* @PROT_WRITE
%51 = or i32 %50, %49
%52 = load i32, i32* @MAP_SHARED
%53 = tail call i8* @mmap(i32* null, i32 %48, i32 %51, i32 %52, i32 %27, i32 1073786880)
%54 = bitcast i8* %53 to double*
%55 = getelementptr i8, i8* %46, i64 3
%56 = bitcast i8* %55 to i32*
%57 = getelementptr i8, i8* %39, i64 28
%58 = bitcast i8* %57 to i64*
%59 = load volatile i32, i32* %56
%60 = and i32 %59, -2
store volatile i32 %60, i32* %56
%61 = load volatile i32, i32* %56
%62 = or i32 %61, 1
store volatile i32 %62, i32* %56
%63 = add nuw nsw i64 %13, 1
%64 = tail call i32 @sleep(i64 %63)
%65 = load volatile i64, i64* %58
%66 = icmp slt i64 %65, %13
br i1 %66, label %73, label %67
67: ; preds = %32
%68 = add nsw i64 %13, -1
%69 = and i64 %13, 3
%70 = icmp ult i64 %68, 3
br i1 %70, label %93, label %71
71: ; preds = %67
%72 = and i64 %13, -4
br label %76
73: ; preds = %32
%74 = load i32, i32* @stderr
%75 = tail call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %121
76: ; preds = %76, %71
%77 = phi double [ 0.000000e+00, %71 ], [ %90, %76 ]
%78 = phi i64 [ 0, %71 ], [ %91, %76 ]
%79 = load volatile double, double* %54
%80 = fadd double %79, 1.000000e+00
%81 = fadd double %77, %80
%82 = load volatile double, double* %54
%83 = fadd double %82, 1.000000e+00
%84 = fadd double %81, %83
%85 = load volatile double, double* %54
%86 = fadd double %85, 1.000000e+00
%87 = fadd double %84, %86
%88 = load volatile double, double* %54
%89 = fadd double %88, 1.000000e+00
%90 = fadd double %87, %89
%91 = add i64 %78, 4
%92 = icmp eq i64 %91, %72
br i1 %92, label %93, label %76
93: ; preds = %76, %67
%94 = phi double [ undef, %67 ], [ %90, %76 ]
%95 = phi double [ 0.000000e+00, %67 ], [ %90, %76 ]
%96 = icmp eq i64 %69, 0
br i1 %96, label %105, label %97
97: ; preds = %93, %97
%98 = phi double [ %102, %97 ], [ %95, %93 ]
%99 = phi i64 [ %103, %97 ], [ 0, %93 ]
%100 = load volatile double, double* %54
%101 = fadd double %100, 1.000000e+00
%102 = fadd double %98, %101
%103 = add i64 %99, 1
%104 = icmp eq i64 %103, %69
br i1 %104, label %105, label %97
105: ; preds = %97, %93
%106 = phi double [ %94, %93 ], [ %102, %97 ]
%107 = sitofp i32 %9 to double
%108 = fmul double %107, 1.250000e+08
%109 = fdiv double %108, %106
%110 = fadd double %109, -1.000000e+00
%111 = fmul double %110, 1.000000e+06
%112 = fptrunc double %111 to float
%113 = fcmp olt float %112, -1.000000e+02
%114 = fcmp ogt float %112, 1.000000e+02
%115 = or i1 %113, %114
br i1 %115, label %116, label %119
116: ; preds = %105
%117 = load i32, i32* @stderr
%118 = tail call i32 @fprintf(i32 %117, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %121
119: ; preds = %105
%120 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), float %112)
br label %121
121: ; preds = %119, %116, %73, %29, %22
%122 = phi i32* [ @EXIT_FAILURE, %22 ], [ @EXIT_FAILURE, %29 ], [ @EXIT_FAILURE, %73 ], [ @EXIT_FAILURE, %116 ], [ @EXIT_SUCCESS, %119 ]
%123 = load i32, i32* %122
ret i32 %123
}