#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 timex {
  int freq;
  scalar_t__ offset;
  void *modes;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
void *ADJ_FREQUENCY;
int /*<<< orphan*/ WNOHANG;
int /*<<< orphan*/ adjtimex(struct timex *);
scalar_t__ fork();
int ksft_exit_fail();
int ksft_exit_pass();
int /*<<< orphan*/ printf(char *);
int system(char *);
int /*<<< orphan*/ usleep(int);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(int argv, char **argc) {
  struct timex tx;
  int ret, ppm;
  pid_t pid;
  printf("Running Asyncrhonous Frequency Changing Tests...\n");
  pid = fork();
  if (!pid)
    return system("./inconsistency-check -c 1 -t 600");
  ppm = 500;
  ret = 0;
  while (pid != waitpid(pid, &ret, WNOHANG)) {
    ppm = -ppm;
    tx.modes = ADJ_FREQUENCY;
    tx.freq = ppm << 16;
    adjtimex(&tx);
    usleep(500000);
  }
  tx.modes = ADJ_FREQUENCY;
  tx.offset = 0;
  adjtimex(&tx);
  if (ret) {
    printf("[FAILED]\n");
    return ksft_exit_fail();
  }
  printf("[OK]\n");
  return ksft_exit_pass();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11cc <main+0x4c>
lea    0xe73(%rip),%rdi
call   1050 <system@plt>
mov    %eax,-0x4(%rbp)
jmp    1299 <main+0x119>
movl   $0x1f4,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    0x2dfb(%rip),%rax
mov    (%rax),%edx
lea    -0x2c(%rbp),%rsi
call   1070 <waitpid@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
je     123f <main+0xbf>
xor    %eax,%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dc1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%eax
shl    $0x10,%eax
mov    %eax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
call   1080 <adjtimex@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
jmp    11da <main+0x5a>
mov    0x2d92(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
call   1080 <adjtimex@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1283 <main+0x103>
lea    0xde5(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1040 <ksft_exit_fail@plt>
mov    %eax,-0x4(%rbp)
jmp    1299 <main+0x119>
lea    0xdd4(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <ksft_exit_pass@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     1273 <main+0xf3>
mov    %rax,%rbx
movl   $0x0,0xc(%rsp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <waitpid@plt>
cmp    %rax,%rbx
je     1235 <main+0xb5>
mov    $0xfffffe0c,%ebp
mov    $0x1f4,%ecx
mov    0x2df7(%rip),%r13
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %ecx,%r12d
mov    0x0(%r13),%rax
mov    %rax,0x20(%rsp)
mov    %ebp,%eax
shl    $0x10,%eax
mov    %eax,0x10(%rsp)
mov    %r14,%rdi
call   1080 <adjtimex@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <waitpid@plt>
mov    %ebp,%ecx
mov    %r12d,%ebp
cmp    %rax,%rbx
jne    11f0 <main+0x70>
mov    0x2d9c(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x20(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x10(%rsp),%rdi
call   1080 <adjtimex@plt>
cmpl   $0x0,0xc(%rsp)
je     128d <main+0x10d>
lea    0xdf3(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <ksft_exit_fail@plt>
jmp    12a0 <main+0x120>
lea    0xd86(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <system@plt>
lea    0xdbf(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <ksft_exit_pass@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timex = type { i32, i64, i8* }
@.str = [50 x i8] c"Running Asyncrhonous Frequency Changing Tests...\0A\00"
@.str.1 = [34 x i8] c"./inconsistency-check -c 1 -t 600\00"
@WNOHANG = global i32 0
@ADJ_FREQUENCY = global i8* null
@.str.2 = [10 x i8] c"[FAILED]\0A\00"
@.str.3 = [6 x i8] c"[OK]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timex
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%11 = call i64 (...) @fork()
store i64 %11, i64* %9
%12 = load i64, i64* %9
%13 = icmp ne i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 @system(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 %15, i32* %3
br label %46
16: ; preds = %2
store i32 500, i32* %8
store i32 0, i32* %7
br label %17
17: ; preds = %23, %16
%18 = load i64, i64* %9
%19 = load i64, i64* %9
%20 = load i32, i32* @WNOHANG
%21 = call i64 @waitpid(i64 %19, i32* %7, i32 %20)
%22 = icmp ne i64 %18, %21
br i1 %22, label %23, label %33
23: ; preds = %17
%24 = load i32, i32* %8
%25 = sub nsw i32 0, %24
store i32 %25, i32* %8
%26 = load i8*, i8** @ADJ_FREQUENCY
%27 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 2
store i8* %26, i8** %27
%28 = load i32, i32* %8
%29 = shl i32 %28, 16
%30 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 0
store i32 %29, i32* %30
%31 = call i32 @adjtimex(%struct.timex* %6)
%32 = call i32 @usleep(i32 500000)
br label %17
33: ; preds = %17
%34 = load i8*, i8** @ADJ_FREQUENCY
%35 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 2
store i8* %34, i8** %35
%36 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
store i64 0, i64* %36
%37 = call i32 @adjtimex(%struct.timex* %6)
%38 = load i32, i32* %7
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %33
%41 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 (...) @ksft_exit_fail()
store i32 %42, i32* %3
br label %46
43: ; preds = %33
%44 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 (...) @ksft_exit_pass()
store i32 %45, i32* %3
br label %46
46: ; preds = %43, %40, %14
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
%struct.timex = type { i32, i64, i8* }
@.str.1 = [34 x i8] c"./inconsistency-check -c 1 -t 600\00"
@WNOHANG = global i32 0
@ADJ_FREQUENCY = global i8* null
@str = [49 x i8] c"Running Asyncrhonous Frequency Changing Tests...\00"
@str.4 = [5 x i8] c"[OK]\00"
@str.5 = [9 x i8] c"[FAILED]\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timex
%4 = alloca i32
%5 = bitcast %struct.timex* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%8 = tail call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @system(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %42
12: ; preds = %2
store i32 0, i32* %4
%13 = load i32, i32* @WNOHANG
%14 = call i64 @waitpid(i64 %8, i32* %4, i32 %13)
%15 = icmp eq i64 %8, %14
br i1 %15, label %29, label %16
16: ; preds = %12
%17 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 2
%18 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 0
br label %19
19: ; preds = %16, %19
%20 = phi i32 [ 500, %16 ], [ %21, %19 ]
%21 = phi i32 [ -500, %16 ], [ %20, %19 ]
%22 = load i8*, i8** @ADJ_FREQUENCY
store i8* %22, i8** %17
%23 = shl i32 %21, 16
store i32 %23, i32* %18
%24 = call i32 @adjtimex(%struct.timex* %3)
%25 = call i32 @usleep(i32 500000)
%26 = load i32, i32* @WNOHANG
%27 = call i64 @waitpid(i64 %8, i32* %4, i32 %26)
%28 = icmp eq i64 %8, %27
br i1 %28, label %29, label %19
29: ; preds = %19, %12
%30 = load i8*, i8** @ADJ_FREQUENCY
%31 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 2
store i8* %30, i8** %31
%32 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 1
store i64 0, i64* %32
%33 = call i32 @adjtimex(%struct.timex* %3)
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %29
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.5, i64 0, i64 0))
%38 = call i32 (...) @ksft_exit_fail()
br label %42
39: ; preds = %29
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.4, i64 0, i64 0))
%41 = call i32 (...) @ksft_exit_pass()
br label %42
42: ; preds = %39, %36, %10
%43 = phi i32 [ %38, %36 ], [ %41, %39 ], [ %11, %10 ]
ret i32 %43
}